Skip to content

Commit 14906df

Browse files
authored
Merge pull request #6970 from anhu/AES_with_FREESCALE_MMCAU
Fix build errors when defining FREESCALE_MMCAU
2 parents cbb270b + 7566328 commit 14906df

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
475475

476476
/* We'll use SW for fallback:
477477
* unsupported key lengths. (e.g. ESP32-S3)
478-
* chipsets not ikmplemented.
478+
* chipsets not implemented.
479479
* hardware busy. */
480480
#define NEED_AES_TABLES
481481
#define NEED_AES_HW_FALLBACK
@@ -3586,12 +3586,18 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
35863586
return 0;
35873587
}
35883588
#elif defined(FREESCALE_LTC)
3589-
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
3590-
int dir)
3589+
int wc_AesSetKeyLocal(Aes* aes, const byte* userKey, word32 keylen,
3590+
const byte* iv, int dir, int checkKeyLen)
35913591
{
3592-
if (aes == NULL || !((keylen == 16) || (keylen == 24) || (keylen == 32)))
3592+
if (aes == NULL)
35933593
return BAD_FUNC_ARG;
35943594

3595+
if (checkKeyLen) {
3596+
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
3597+
return BAD_FUNC_ARG;
3598+
}
3599+
(void)dir;
3600+
35953601
aes->rounds = keylen/4 + 6;
35963602
XMEMCPY(aes->key, userKey, keylen);
35973603

@@ -3603,14 +3609,21 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
36033609
return wc_AesSetIV(aes, iv);
36043610
}
36053611

3612+
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
3613+
const byte* iv, int dir)
3614+
{
3615+
return wc_AesSetKeyLocal(aes, userKey, keylen, iv, dir, 1);
3616+
}
3617+
3618+
36063619
int wc_AesSetKeyDirect(Aes* aes, const byte* userKey, word32 keylen,
36073620
const byte* iv, int dir)
36083621
{
36093622
return wc_AesSetKey(aes, userKey, keylen, iv, dir);
36103623
}
36113624
#elif defined(FREESCALE_MMCAU)
3612-
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
3613-
const byte* iv, int dir)
3625+
int wc_AesSetKeyLocal(Aes* aes, const byte* userKey, word32 keylen,
3626+
const byte* iv, int dir, int checkKeyLen)
36143627
{
36153628
int ret;
36163629
byte* rk;
@@ -3620,11 +3633,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
36203633

36213634
(void)dir;
36223635

3623-
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
3624-
return BAD_FUNC_ARG;
36253636
if (aes == NULL)
36263637
return BAD_FUNC_ARG;
36273638

3639+
if (checkKeyLen) {
3640+
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
3641+
return BAD_FUNC_ARG;
3642+
}
3643+
36283644
rk = (byte*)aes->key;
36293645
if (rk == NULL)
36303646
return BAD_FUNC_ARG;
@@ -3675,6 +3691,12 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
36753691
return ret;
36763692
}
36773693

3694+
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
3695+
const byte* iv, int dir)
3696+
{
3697+
return wc_AesSetKeyLocal(aes, userKey, keylen, iv, dir, 1);
3698+
}
3699+
36783700
int wc_AesSetKeyDirect(Aes* aes, const byte* userKey, word32 keylen,
36793701
const byte* iv, int dir)
36803702
{
@@ -4991,6 +5013,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
49915013
#ifdef HAVE_AES_DECRYPT
49925014
int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
49935015
{
5016+
int ret;
49945017
int offset = 0;
49955018
byte* iv;
49965019
byte temp_block[AES_BLOCK_SIZE];
@@ -5009,7 +5032,9 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
50095032
while (blocks--) {
50105033
XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE);
50115034

5012-
wc_AesDecrypt(aes, in + offset, out + offset);
5035+
ret = wc_AesDecrypt(aes, in + offset, out + offset);
5036+
if (ret != 0)
5037+
return ret;
50135038

50145039
/* XOR block with IV for CBC */
50155040
xorbuf(out + offset, iv, AES_BLOCK_SIZE);

0 commit comments

Comments
 (0)