mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-01-26 23:22:21 +01:00
Merge pull request #9573 from night1rider/aes-free-callbacks
Aes Free callback support
This commit is contained in:
17
tests/api.c
17
tests/api.c
@@ -35747,6 +35747,23 @@ static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (info->free.algo == WC_ALGO_TYPE_CIPHER) {
|
||||
switch (info->free.type) {
|
||||
#ifndef NO_AES
|
||||
case WC_CIPHER_AES:
|
||||
{
|
||||
Aes* aes = (Aes*)info->free.obj;
|
||||
aes->devId = INVALID_DEVID;
|
||||
wc_AesFree(aes);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
|
||||
|
||||
@@ -13402,10 +13402,34 @@ int wc_AesInit_Label(Aes* aes, const char* label, void* heap, int devId)
|
||||
/* Free Aes resources */
|
||||
void wc_AesFree(Aes* aes)
|
||||
{
|
||||
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE)
|
||||
int ret = 0;
|
||||
#endif
|
||||
|
||||
if (aes == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE)
|
||||
#ifndef WOLF_CRYPTO_CB_FIND
|
||||
if (aes->devId != INVALID_DEVID)
|
||||
#endif
|
||||
{
|
||||
ret = wc_CryptoCb_Free(aes->devId, WC_ALGO_TYPE_CIPHER,
|
||||
WC_CIPHER_AES, (void*)aes);
|
||||
/* If they want the standard free, they can call it themselves */
|
||||
/* via their callback setting devId to INVALID_DEVID */
|
||||
/* otherwise assume the callback handled it */
|
||||
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||
return;
|
||||
/* fall-through when unavailable */
|
||||
}
|
||||
|
||||
/* silence compiler warning */
|
||||
(void)ret;
|
||||
|
||||
#endif /* WOLF_CRYPTO_CB && WOLF_CRYPTO_CB_FREE */
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
(void)wc_debug_CipherLifecycleFree(&aes->CipherLifecycleTag, aes->heap, 1);
|
||||
#endif
|
||||
|
||||
@@ -62522,6 +62522,23 @@ static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (info->free.algo == WC_ALGO_TYPE_CIPHER) {
|
||||
switch (info->free.type) {
|
||||
#ifndef NO_AES
|
||||
case WC_CIPHER_AES:
|
||||
{
|
||||
Aes* aes = (Aes*)info->free.obj;
|
||||
aes->devId = INVALID_DEVID;
|
||||
wc_AesFree(aes);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
|
||||
|
||||
Reference in New Issue
Block a user