diff --git a/ctaocrypt/src/aes.c b/ctaocrypt/src/aes.c index bc38012a4..e0ec103d2 100644 --- a/ctaocrypt/src/aes.c +++ b/ctaocrypt/src/aes.c @@ -804,6 +804,11 @@ int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv, iv = (byte*)aes->reg; enc_key = (byte*)aes->key; + if ((word)out % CYASSL_MMCAU_ALIGNMENT) { + CYASSL_MSG("Bad cau_aes_encrypt alignment"); + return BAD_ALIGN_E; + } + while (len > 0) { XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE); @@ -836,6 +841,11 @@ int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv, iv = (byte*)aes->reg; dec_key = (byte*)aes->key; + if ((word)out % CYASSL_MMCAU_ALIGNMENT) { + CYASSL_MSG("Bad cau_aes_decrypt alignment"); + return BAD_ALIGN_E; + } + while (len > 0) { XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE); diff --git a/ctaocrypt/src/des3.c b/ctaocrypt/src/des3.c index a704b7910..39db39d44 100644 --- a/ctaocrypt/src/des3.c +++ b/ctaocrypt/src/des3.c @@ -566,6 +566,11 @@ int Des3_SetKey(Des3* des3, const byte* key, const byte* iv, int dir) iv = (byte*)des->reg; + if ((word)out % CYASSL_MMCAU_ALIGNMENT) { + CYASSL_MSG("Bad cau_des_encrypt alignment"); + return BAD_ALIGN_E; + } + while (len > 0) { XMEMCPY(temp_block, in + offset, DES_BLOCK_SIZE); @@ -596,6 +601,11 @@ int Des3_SetKey(Des3* des3, const byte* key, const byte* iv, int dir) iv = (byte*)des->reg; + if ((word)out % CYASSL_MMCAU_ALIGNMENT) { + CYASSL_MSG("Bad cau_des_decrypt alignment"); + return BAD_ALIGN_E; + } + while (len > 0) { XMEMCPY(temp_block, in + offset, DES_BLOCK_SIZE); @@ -627,6 +637,11 @@ int Des3_SetKey(Des3* des3, const byte* key, const byte* iv, int dir) iv = (byte*)des->reg; + if ((word)out % CYASSL_MMCAU_ALIGNMENT) { + CYASSL_MSG("Bad 3ede cau_des_encrypt alignment"); + return BAD_ALIGN_E; + } + while (len > 0) { XMEMCPY(temp_block, in + offset, DES_BLOCK_SIZE); @@ -660,6 +675,11 @@ int Des3_SetKey(Des3* des3, const byte* key, const byte* iv, int dir) iv = (byte*)des->reg; + if ((word)out % CYASSL_MMCAU_ALIGNMENT) { + CYASSL_MSG("Bad 3ede cau_des_decrypt alignment"); + return BAD_ALIGN_E; + } + while (len > 0) { XMEMCPY(temp_block, in + offset, DES_BLOCK_SIZE); diff --git a/cyassl/ctaocrypt/settings.h b/cyassl/ctaocrypt/settings.h index c8bd28f14..c49e3725c 100644 --- a/cyassl/ctaocrypt/settings.h +++ b/cyassl/ctaocrypt/settings.h @@ -647,6 +647,11 @@ #endif +/* FreeScale MMCAU hardware crypto has 4 byte alignment */ +#ifdef FREESCALE_MMCAU + #define CYASSL_MMCAU_ALIGNMENT 4 +#endif + /* if using hardware crypto and have alignment requirements, specify the requirement here. The record header of SSL/TLS will prvent easy alignment. This hint tries to help as much as possible. */ @@ -655,6 +660,8 @@ #define CYASSL_GENERAL_ALIGNMENT 16 #elif defined(XSTREAM_ALIGNMENT) #define CYASSL_GENERAL_ALIGNMENT 4 + #elif defined(FREESCALE_MMCAU) + #define CYASSL_GENERAL_ALIGNMENT CYASSL_MMCAU_ALIGNMENT #else #define CYASSL_GENERAL_ALIGNMENT 0 #endif