1
0
mirror of https://github.com/wolfSSL/wolfssl.git synced 2026-10-24 04:09:07 +03:00

Offer the AES key to a SETKEY device in the PPC asm set-key

The PowerPC assembly build has its own wc_AesSetKey(), and it only
called the older WOLF_CRYPTO_CB_AES_SETKEY hook. With
WOLF_CRYPTO_CB_SETKEY a device never saw the key: the context always
got a software schedule, so a device that keeps its keys could not own
one, unlike in every other build.

The PPC set-key now calls wc_CryptoCb_SetKey() the same way the ARM32
one does, and handles a claim the same way: the old schedule and devKey
are wiped first, and the key counts as installed only if the callback
built a schedule.
This commit is contained in:
Tobias Frauenschläger
2026-10-06 08:59:20 +02:00
parent 6c8b85e0b5
commit df454f5ea9

View File

@@ -5493,6 +5493,9 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock,
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
const byte* iv, int dir)
{
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_SETKEY)
int cbRet;
#endif
if ((aes == NULL) || (userKey == NULL)) {
return BAD_FUNC_ARG;
}
@@ -5519,13 +5522,17 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock,
if (aes->devId != INVALID_DEVID) {
#ifdef WOLF_CRYPTO_CB_AES_SETKEY
int ret;
#endif
#if defined(WOLF_CRYPTO_CB_AES_SETKEY) || defined(WOLF_CRYPTO_CB_SETKEY)
aes->keyInstalled = 0;
aes->rounds = 0;
aes->keylen = 0;
WC_AES_GCM_UNKEY(aes);
ForceZero(aes->key, sizeof(aes->key));
ForceZero(aes->devKey, sizeof(aes->devKey));
#endif
#ifdef WOLF_CRYPTO_CB_AES_SETKEY
ret = wc_CryptoCb_AesSetKey(aes, userKey, keylen);
if (ret == 0) {
/* Callback succeeded - SE owns the key */
@@ -5543,6 +5550,25 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock,
}
/* CRYPTOCB_UNAVAILABLE: continue to software setup */
#endif
#ifdef WOLF_CRYPTO_CB_SETKEY
cbRet = wc_CryptoCb_SetKey(aes->devId,
WC_SETKEY_AES, aes, (void*)userKey, keylen,
(void*)iv,
(iv != NULL) ? WC_AES_BLOCK_SIZE : 0, dir);
if (cbRet != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
if (cbRet == 0) {
/* Callback succeeded - the device owns the key. */
aes->keylen = (int)keylen;
aes->keyInstalled = (aes->rounds != 0) ? 1 : 0;
if (iv != NULL)
XMEMCPY(aes->reg, iv, WC_AES_BLOCK_SIZE);
else
XMEMSET(aes->reg, 0, WC_AES_BLOCK_SIZE);
}
return cbRet;
}
/* CRYPTOCB_UNAVAILABLE: fall through to software setup */
#endif /* WOLF_CRYPTO_CB_SETKEY */
/* Standard CryptoCB path - copy key to devKey for encrypt/decrypt offload */
if (keylen > sizeof(aes->devKey)) {
return BAD_FUNC_ARG;