Implement proper wc_AesSetKeyLocal
for NXP/Freescale MMCAU and LTC. This is required for AES CTR and AES Direct.
This commit is contained in:
parent
3fa612f49f
commit
7566328610
@ -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,15 +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)
|
||||
#define NEED_SOFTWARE_AES_SETKEY
|
||||
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;
|
||||
@ -3621,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;
|
||||
@ -3676,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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user