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