Merge pull request #2524 from cconlon/cau_iar

mmCAU Classic AES key alignment, IAR warnings fixes
This commit is contained in:
David Garske
2019-10-24 09:23:20 -07:00
committed by GitHub
3 changed files with 31 additions and 5 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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