Address review: set keyInstalled in HW port key setup (F-6151)

The keyInstalled guard added to the shared aes.c mode functions is only
set by aes.c's own key schedule and the RISC-V port. Ports that ship
their own compile-time wc_AesSetKey/wc_AesGcmSetKey left keyInstalled at
0, so any AES mode that falls through to a guarded aes.c path returned
BAD_FUNC_ARG after a correct key setup.

Set keyInstalled at the key-install point of the affected ports so the
shared mode guards accept a validly-keyed context:
- silabs, af_alg, devcrypto, ti, caam: wc_AesSetKey
- af_alg, kcapi: wc_AesGcmSetKey
pull/10762/head
Juliusz Sosinowicz 2026-07-15 02:31:39 +00:00
parent 797cf23fd8
commit dab0b92992
6 changed files with 16 additions and 0 deletions

View File

@ -146,6 +146,8 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
#endif
aes->keylen = keylen;
aes->rounds = keylen/4 + 6;
/* Mark key installed so the shared aes.c mode guards accept this context. */
aes->keyInstalled = 1;
#ifdef WOLFSSL_AES_COUNTER
aes->left = 0;
@ -556,6 +558,8 @@ int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len)
aes->keylen = len;
aes->rounds = len/4 + 6;
aes->dir = AES_ENCRYPTION;
/* Mark key installed so the shared aes.c mode guards accept this context. */
aes->keyInstalled = 1;
if (aes->rdFd > WC_SOCK_NOTSET) {
(void)close(aes->rdFd);

View File

@ -88,6 +88,8 @@ int wc_AesSetKey(Aes* aes, const byte* key, word32 len,
default:
return BAD_FUNC_ARG;
}
/* Mark key installed so the shared aes.c mode guards accept this context. */
aes->keyInstalled = 1;
if ((ret = wc_AesSetIV(aes, iv)) != 0) {
return ret;

View File

@ -123,6 +123,8 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
#endif
aes->keylen = keylen;
aes->rounds = keylen/4 + 6;
/* Mark key installed so the shared aes.c mode guards accept this context. */
aes->keyInstalled = 1;
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)

View File

@ -208,6 +208,9 @@ int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len)
if (ret == 0) {
aes->keylen = len;
aes->rounds = len/4 + 6;
/* Mark key installed so the shared aes.c mode guards accept this
* context. */
aes->keyInstalled = 1;
/* save key until type is known i.e. CBC, ECB, ... */
XMEMCPY((byte*)(aes->devKey), key, len);

View File

@ -87,6 +87,9 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
aes->ctx.key.storage.location.buffer.pointer = (void*)aes->key;
aes->ctx.key.storage.location.buffer.size = keylen;
aes->ctx.key.size = keylen;
/* Mark key installed so the shared aes.c mode guards accept this
* context. */
aes->keyInstalled = 1;
}
return ret;

View File

@ -103,6 +103,8 @@ int wc_AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv, int dir)
}
aes->keylen = len;
aes->rounds = len / 4 + 6;
/* Mark key installed so the shared aes.c mode guards accept this context. */
aes->keyInstalled = 1;
XMEMCPY(aes->key, key, len);
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \