Skip to content

Commit 56b2017

Browse files
committed
Save heap before *_free in *_delete to avoid XFREE with zeroed memory after ForceZero
1 parent e0be977 commit 56b2017

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13581,10 +13581,12 @@ Aes* wc_AesNew(void* heap, int devId, int *result_code)
1358113581

1358213582
int wc_AesDelete(Aes *aes, Aes** aes_p)
1358313583
{
13584+
void* heap;
1358413585
if (aes == NULL)
1358513586
return BAD_FUNC_ARG;
13587+
heap = aes->heap;
1358613588
wc_AesFree(aes);
13587-
XFREE(aes, aes->heap, DYNAMIC_TYPE_AES);
13589+
XFREE(aes, heap, DYNAMIC_TYPE_AES);
1358813590
if (aes_p != NULL)
1358913591
*aes_p = NULL;
1359013592
return 0;

wolfcrypt/src/curve25519.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,10 +1113,12 @@ curve25519_key* wc_curve25519_new(void* heap, int devId, int *result_code)
11131113
}
11141114

11151115
int wc_curve25519_delete(curve25519_key* key, curve25519_key** key_p) {
1116+
void* heap;
11161117
if (key == NULL)
11171118
return BAD_FUNC_ARG;
1119+
heap = key->heap;
11181120
wc_curve25519_free(key);
1119-
XFREE(key, key->heap, DYNAMIC_TYPE_CURVE25519);
1121+
XFREE(key, heap, DYNAMIC_TYPE_CURVE25519);
11201122
if (key_p != NULL)
11211123
*key_p = NULL;
11221124
return 0;

wolfcrypt/src/dilithium.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10730,10 +10730,12 @@ dilithium_key* wc_dilithium_new(void* heap, int devId)
1073010730

1073110731
int wc_dilithium_delete(dilithium_key* key, dilithium_key** key_p)
1073210732
{
10733+
void* heap;
1073310734
if (key == NULL)
1073410735
return BAD_FUNC_ARG;
10736+
heap = key->heap;
1073510737
wc_dilithium_free(key);
10736-
XFREE(key, key->heap, DYNAMIC_TYPE_DILITHIUM);
10738+
XFREE(key, heap, DYNAMIC_TYPE_DILITHIUM);
1073710739
if (key_p != NULL)
1073810740
*key_p = NULL;
1073910741

wolfcrypt/src/ed25519.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,10 +1035,12 @@ ed25519_key* wc_ed25519_new(void* heap, int devId, int *result_code)
10351035
}
10361036

10371037
int wc_ed25519_delete(ed25519_key* key, ed25519_key** key_p) {
1038+
void* heap;
10381039
if (key == NULL)
10391040
return BAD_FUNC_ARG;
1041+
heap = key->heap;
10401042
wc_ed25519_free(key);
1041-
XFREE(key, key->heap, DYNAMIC_TYPE_ED25519);
1043+
XFREE(key, heap, DYNAMIC_TYPE_ED25519);
10421044
if (key_p != NULL)
10431045
*key_p = NULL;
10441046
return 0;

0 commit comments

Comments
 (0)