Skip to content

Commit a976ee2

Browse files
committed
fix GCM test
Signed-off-by: Sameeh Jubran <[email protected]>
1 parent 74a94c0 commit a976ee2

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

tests/api/test_aes.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5283,6 +5283,7 @@ static int test_CryptoCb_Aes_Cb(int devId, wc_CryptoInfo* info, void* ctx)
52835283

52845284
/* Store handle in aes->devCtx - this is what wolfSSL will use */
52855285
aes->devCtx = cryptoCbAesMockHandle;
5286+
aes->devFlags |= WC_AES_FLAG_GCM_OFFLOAD; /* We handle GCM ops */
52865287

52875288
cryptoCbAesSetKeyCalled++;
52885289

@@ -5627,6 +5628,7 @@ static int test_CryptoCb_AesGcm_Offload_Cb(int devId, wc_CryptoInfo* info, void*
56275628

56285629
/* Store handle in aes->devCtx - this is what wolfSSL will use */
56295630
aes->devCtx = cryptoCbAesGcmMockHandle;
5631+
aes->devFlags |= WC_AES_FLAG_GCM_OFFLOAD; /* We handle GCM ops */
56305632

56315633
cryptoCbAesGcmSetKeyCalled++;
56325634

wolfcrypt/src/aes.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7511,7 +7511,8 @@ int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len)
75117511
#ifdef WOLF_CRYPTO_CB_AES_SETKEY
75127512
/* In CryptoCB key import mode, skip H table generation.
75137513
* The secure element handles GCM internally. */
7514-
if (aes->devId != INVALID_DEVID && aes->devCtx != NULL) {
7514+
if (aes->devId != INVALID_DEVID && aes->devCtx != NULL &&
7515+
(aes->devFlags & WC_AES_FLAG_GCM_OFFLOAD)) {
75157516
/* H table not needed - SE does GCM */
75167517
}
75177518
else
@@ -7529,7 +7530,8 @@ int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len)
75297530
#ifdef WOLF_CRYPTO_CB_AES_SETKEY
75307531
/* In CryptoCB key import mode, skip M0 table generation.
75317532
* The secure element handles GCM internally. */
7532-
if (aes->devId != INVALID_DEVID && aes->devCtx != NULL) {
7533+
if (aes->devId != INVALID_DEVID && aes->devCtx != NULL &&
7534+
(aes->devFlags & WC_AES_FLAG_GCM_OFFLOAD)) {
75337535
/* M0 table not needed - SE does GCM */
75347536
}
75357537
else
@@ -13473,14 +13475,17 @@ void wc_AesFree(Aes* aes)
1347313475
{
1347413476
int ret = wc_CryptoCb_Free(aes->devId, WC_ALGO_TYPE_CIPHER,
1347513477
WC_CIPHER_AES, aes);
13478+
if (ret == WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
13479+
/* Callback didn't handle it - fall through to software cleanup */
13480+
}
13481+
else {
13482+
/* Callback handled cleanup */
1347613483
#ifdef WOLF_CRYPTO_CB_AES_SETKEY
13477-
aes->devCtx = NULL; /* Clear device context handle */
13484+
aes->devCtx = NULL;
13485+
aes->devFlags = 0;
1347813486
#endif
13479-
/* If callback wants standard free, it can set devId to INVALID_DEVID.
13480-
* Otherwise assume the callback handled cleanup. */
13481-
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
1348213487
return;
13483-
/* fall-through when unavailable */
13488+
}
1348413489
}
1348513490
#endif /* WOLF_CRYPTO_CB && WOLF_CRYPTO_CB_FREE */
1348613491

wolfssl/wolfcrypt/aes.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ enum {
237237
WOLF_ENUM_DUMMY_LAST_ELEMENT(AES)
238238
};
239239

240+
/* CryptoCB device capability flags */
241+
#define WC_AES_FLAG_NONE 0x00
242+
#define WC_AES_FLAG_GCM_OFFLOAD 0x01 /* Device handles AES-GCM encrypt/decrypt */
243+
240244
#ifdef WC_AES_BITSLICED
241245
#ifdef WC_AES_BS_WORD_SIZE
242246
#define BS_WORD_SIZE WC_AES_BS_WORD_SIZE
@@ -335,6 +339,9 @@ struct Aes {
335339
#if defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_STM32U5_DHUK)
336340
int devId;
337341
void* devCtx;
342+
#ifdef WOLF_CRYPTO_CB
343+
byte devFlags; /* CryptoCB capability flags */
344+
#endif
338345
#endif
339346
#ifdef WOLF_PRIVATE_KEY_ID
340347
byte id[AES_MAX_ID_LEN];

0 commit comments

Comments
 (0)