From c4afbb36858afa2bbd0ce818fd745ba77a8a0cef Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Fri, 18 Oct 2019 14:02:43 -0600 Subject: [PATCH 1/3] align AES key if needed when using MMCAU classic --- wolfcrypt/src/aes.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index 08b3fec73..5e64cb967 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -1917,7 +1917,9 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock) const byte* iv, int dir) { int ret; - byte *rk = (byte*)aes->key; + byte* rk = (byte*)aes->key; + byte* tmpKey = (byte*)userKey; + int tmpKeyDynamic = 0; (void)dir; @@ -1933,18 +1935,41 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock) aes->rounds = keylen/4 + 6; + #ifdef FREESCALE_MMCAU_CLASSIC + if ((wolfssl_word)userKey % WOLFSSL_MMCAU_ALIGNMENT) { + #ifndef NO_WOLFSSL_ALLOC_ALIGN + byte* tmp = (byte*)XMALLOC(keylen + WOLFSSL_MMCAU_ALIGNMENT, + aes->heap, DYNAMIC_TYPE_TMP_BUFFER); + if (tmp == NULL) { + return MEMORY_E; + } + tmpKey = tmp + (WOLFSSL_MMCAU_ALIGNMENT - + ((wolfssl_word)tmp % WOLFSSL_MMCAU_ALIGNMENT)); + XMEMCPY(tmpKey, userKey, keylen); + tmpKeyDynamic = 1; + #else + WOLFSSL_MSG("Bad cau_aes_set_key alignment"); + return BAD_ALIGN_E; + #endif + } + #endif + ret = wolfSSL_CryptHwMutexLock(); if(ret == 0) { #ifdef FREESCALE_MMCAU_CLASSIC - cau_aes_set_key(userKey, keylen*8, rk); + cau_aes_set_key(tmpKey, keylen*8, rk); #else - MMCAU_AES_SetKey(userKey, keylen, rk); + MMCAU_AES_SetKey(tmpKey, keylen, rk); #endif wolfSSL_CryptHwMutexUnLock(); ret = wc_AesSetIV(aes, iv); } + if (tmpKeyDynamic == 1) { + XFREE(tmpKey, aes->heap, DYNAMIC_TYPE_TMP_BUFFER); + } + return ret; } From c18ff3695935e4841db5ac35805d7159cd3a87c3 Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Fri, 18 Oct 2019 14:08:23 -0600 Subject: [PATCH 2/3] fix uninitialized variable warning in IAR-EWARM 7.50.2 --- wolfcrypt/src/tfm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index c5e4aac2b..3fab409e5 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -2768,7 +2768,7 @@ int fp_montgomery_reduce(fp_int *a, fp_int *m, fp_digit mp) fp_digit *c; #endif fp_digit *_c, *tmpm, mu = 0; - int oldused, x, y, pa, err; + int oldused, x, y, pa, err = 0; IF_HAVE_INTEL_MULX(err = fp_montgomery_reduce_mulx(a, m, mp), return err) ; (void)err; From 42ddd639520704a825a7b156113a28d0a3a69c1c Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Fri, 18 Oct 2019 16:33:01 -0600 Subject: [PATCH 3/3] exclude packed __attribute__ on IAR ICC < 9 --- wolfssl/wolfcrypt/types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 7c8cc1d7d..4cedf31b6 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -862,7 +862,8 @@ #endif - #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) + #if (defined(__IAR_SYSTEMS_ICC__) && (__IAR_SYSTEMS_ICC__ > 8)) || \ + defined(__GNUC__) #define WOLFSSL_PACK __attribute__ ((packed)) #else #define WOLFSSL_PACK