Merge pull request #6970 from anhu/AES_with_FREESCALE_MMCAU

Fix build errors when defining FREESCALE_MMCAU
This commit is contained in:
David Garske
2023-11-20 09:32:49 -08:00
committed by GitHub

View File

@ -475,7 +475,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
/* We'll use SW for fallback:
* unsupported key lengths. (e.g. ESP32-S3)
* chipsets not ikmplemented.
* chipsets not implemented.
* hardware busy. */
#define NEED_AES_TABLES
#define NEED_AES_HW_FALLBACK
@ -3586,12 +3586,18 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
return 0;
}
#elif defined(FREESCALE_LTC)
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
int dir)
int wc_AesSetKeyLocal(Aes* aes, const byte* userKey, word32 keylen,
const byte* iv, int dir, int checkKeyLen)
{
if (aes == NULL || !((keylen == 16) || (keylen == 24) || (keylen == 32)))
if (aes == NULL)
return BAD_FUNC_ARG;
if (checkKeyLen) {
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
return BAD_FUNC_ARG;
}
(void)dir;
aes->rounds = keylen/4 + 6;
XMEMCPY(aes->key, userKey, keylen);
@ -3603,14 +3609,21 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
return wc_AesSetIV(aes, iv);
}
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
const byte* iv, int dir)
{
return wc_AesSetKeyLocal(aes, userKey, keylen, iv, dir, 1);
}
int wc_AesSetKeyDirect(Aes* aes, const byte* userKey, word32 keylen,
const byte* iv, int dir)
{
return wc_AesSetKey(aes, userKey, keylen, iv, dir);
}
#elif defined(FREESCALE_MMCAU)
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
const byte* iv, int dir)
int wc_AesSetKeyLocal(Aes* aes, const byte* userKey, word32 keylen,
const byte* iv, int dir, int checkKeyLen)
{
int ret;
byte* rk;
@ -3620,11 +3633,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
(void)dir;
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
return BAD_FUNC_ARG;
if (aes == NULL)
return BAD_FUNC_ARG;
if (checkKeyLen) {
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
return BAD_FUNC_ARG;
}
rk = (byte*)aes->key;
if (rk == NULL)
return BAD_FUNC_ARG;
@ -3675,6 +3691,12 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
return ret;
}
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
const byte* iv, int dir)
{
return wc_AesSetKeyLocal(aes, userKey, keylen, iv, dir, 1);
}
int wc_AesSetKeyDirect(Aes* aes, const byte* userKey, word32 keylen,
const byte* iv, int dir)
{
@ -4991,6 +5013,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
#ifdef HAVE_AES_DECRYPT
int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
{
int ret;
int offset = 0;
byte* iv;
byte temp_block[AES_BLOCK_SIZE];
@ -5009,7 +5032,9 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
while (blocks--) {
XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE);
wc_AesDecrypt(aes, in + offset, out + offset);
ret = wc_AesDecrypt(aes, in + offset, out + offset);
if (ret != 0)
return ret;
/* XOR block with IV for CBC */
xorbuf(out + offset, iv, AES_BLOCK_SIZE);