Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittest for cryspr methods #864

Merged
merged 4 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/srt.pc DESTINATION ${CMAKE_INSTALL_LIB

# Applications

if ( HAVE_COMPILER_GNU_COMPAT )
if (HAVE_COMPILER_GNU_COMPAT AND ENABLE_CXX11)
message(STATUS "C++ VERSION: Setting C++11 compat flag for gnu compiler")
set (CFLAGS_CXX_STANDARD "-std=c++11")
else()
Expand Down Expand Up @@ -930,6 +930,7 @@ if (ENABLE_UNITTESTS AND ENABLE_CXX11)

srt_add_program(test_srt ${SOURCES_unittests})
srt_make_application(test_srt)
target_include_directories(test_srt PRIVATE ${SSL_INCLUDE_DIRS})

target_link_libraries(
test_srt
Expand Down
15 changes: 9 additions & 6 deletions haicrypt/cryspr-openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ int crysprOpenSSL_AES_SetKey(
int crysprOpenSSL_AES_EcbCipher(
bool bEncrypt, /* true:encrypt, false:decrypt */
CRYSPR_AESCTX *aes_key, /* CRYpto Service PRovider AES Key context */
const unsigned char *indata,/* src (clear text)*/
size_t inlen, /* length */
unsigned char *out_txt, /* dst (cipher text) */
size_t *outlen) /* dst len */
const unsigned char *indata,/* src (clear text if encrypt, cipher text otherwise)*/
size_t inlen, /* indata length */
unsigned char *out_txt, /* dst (cipher text if encrypt, clear text otherwise) */
size_t *outlen) /* in/out dst len */
{
int nblk = inlen/CRYSPR_AESBLKSZ;
int nmore = inlen%CRYSPR_AESBLKSZ;
size_t outsiz = (outlen ? *outlen : 0);
int i;

if (outsiz % CRYSPR_AESBLKSZ) return(-1); /* output buf size must be a multiple of AES block size (16) */
if (bEncrypt) {
if (outsiz > 16 && outsiz < (nblk+nmore)*CRYSPR_AESBLKSZ) return(-1); /* output buf size must have room for PKCS7 padding */
/* Encrypt packet payload, block by block, in output buffer */
for (i=0; i<nblk; i++){
AES_ecb_encrypt(&indata[(i*CRYSPR_AESBLKSZ)],
Expand All @@ -76,9 +79,9 @@ int crysprOpenSSL_AES_EcbCipher(
/* Encrypt last incomplete block */
if (0 < nmore) {
unsigned char intxt[CRYSPR_AESBLKSZ];

/* PKCS7 padding: padding value is number of bytes padded */
memcpy(intxt, &indata[(nblk*CRYSPR_AESBLKSZ)], nmore);
memset(intxt+nmore, 0, CRYSPR_AESBLKSZ-nmore);
memset(intxt+nmore, CRYSPR_AESBLKSZ-nmore, CRYSPR_AESBLKSZ-nmore);
AES_ecb_encrypt(intxt, &out_txt[(nblk*CRYSPR_AESBLKSZ)], aes_key, AES_ENCRYPT);
nblk++;
}
Expand Down
6 changes: 3 additions & 3 deletions haicrypt/cryspr.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int crysprFallback_AES_WrapKey(CRYSPR_cb *cryspr_cb,
}
}
memcpy(out, A, 8);
return inlen + 8;
return 0;
}

int crysprFallback_AES_UnwrapKey(CRYSPR_cb *cryspr_cb,
Expand Down Expand Up @@ -219,9 +219,9 @@ int crysprFallback_AES_UnwrapKey(CRYSPR_cb *cryspr_cb,
if (memcmp(A, iv, 8))
{
memset(out, 0, inlen);
return 0;
return -1;
}
return inlen;
return 0;
}

static unsigned char *_crysprFallback_GetOutbuf(CRYSPR_cb *cryspr_cb, size_t pfx_len, size_t out_len)
Expand Down
8 changes: 8 additions & 0 deletions haicrypt/cryspr.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ written by
#include "haisrt/hcrypt_msg.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#include "cryspr-config.h"

typedef struct tag_CRYSPR_cb {
Expand Down Expand Up @@ -192,4 +196,8 @@ typedef struct tag_CRYSPR_methods {

CRYSPR_methods *crysprInit(CRYSPR_methods *cryspr);

#ifdef __cplusplus
}
#endif

#endif /* CRYSPR_H */
1 change: 1 addition & 0 deletions test/filelist.maf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
SOURCES
test_buffer.cpp
test_connection_timeout.cpp
test_cryspr.cpp
test_epoll.cpp
test_seqno.cpp
test_strict_encription.cpp
Expand Down
Loading