Skip to content

Commit afbc65a

Browse files
committed
Aes Free callback support
1 parent da06e1a commit afbc65a

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

tests/api.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35747,6 +35747,23 @@ static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
3574735747
ret = 0;
3574835748
break;
3574935749
}
35750+
#endif
35751+
default:
35752+
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
35753+
break;
35754+
}
35755+
}
35756+
else if (info->free.algo == WC_ALGO_TYPE_CIPHER) {
35757+
switch (info->free.type) {
35758+
#ifndef NO_AES
35759+
case WC_CIPHER_AES:
35760+
{
35761+
Aes* aes = (Aes*)info->free.obj;
35762+
aes->devId = INVALID_DEVID;
35763+
wc_AesFree(aes);
35764+
ret = 0;
35765+
break;
35766+
}
3575035767
#endif
3575135768
default:
3575235769
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);

wolfcrypt/src/aes.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13402,10 +13402,34 @@ int wc_AesInit_Label(Aes* aes, const char* label, void* heap, int devId)
1340213402
/* Free Aes resources */
1340313403
void wc_AesFree(Aes* aes)
1340413404
{
13405+
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE)
13406+
int ret = 0;
13407+
#endif
13408+
1340513409
if (aes == NULL) {
1340613410
return;
1340713411
}
1340813412

13413+
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE)
13414+
#ifndef WOLF_CRYPTO_CB_FIND
13415+
if (aes->devId != INVALID_DEVID)
13416+
#endif
13417+
{
13418+
ret = wc_CryptoCb_Free(aes->devId, WC_ALGO_TYPE_CIPHER,
13419+
WC_CIPHER_AES, (void*)aes);
13420+
/* If they want the standard free, they can call it themselves */
13421+
/* via their callback setting devId to INVALID_DEVID */
13422+
/* otherwise assume the callback handled it */
13423+
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
13424+
return;
13425+
/* fall-through when unavailable */
13426+
}
13427+
13428+
/* silence compiler warning */
13429+
(void)ret;
13430+
13431+
#endif /* WOLF_CRYPTO_CB && WOLF_CRYPTO_CB_FREE */
13432+
1340913433
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
1341013434
(void)wc_debug_CipherLifecycleFree(&aes->CipherLifecycleTag, aes->heap, 1);
1341113435
#endif

wolfcrypt/test/test.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62522,6 +62522,23 @@ static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
6252262522
ret = 0;
6252362523
break;
6252462524
}
62525+
#endif
62526+
default:
62527+
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
62528+
break;
62529+
}
62530+
}
62531+
else if (info->free.algo == WC_ALGO_TYPE_CIPHER) {
62532+
switch (info->free.type) {
62533+
#ifndef NO_AES
62534+
case WC_CIPHER_AES:
62535+
{
62536+
Aes* aes = (Aes*)info->free.obj;
62537+
aes->devId = INVALID_DEVID;
62538+
wc_AesFree(aes);
62539+
ret = 0;
62540+
break;
62541+
}
6252562542
#endif
6252662543
default:
6252762544
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);

0 commit comments

Comments
 (0)