Skip to content

Commit b3278af

Browse files
anhuJacobBarthelmeh
authored andcommitted
Fix wc_*_delete() functions (ZD 21415)
Save key->heap before calling wc_*_free(), which zeros the entire key structure via ForceZero. The saved heap pointer is then passed to XFREE instead of the now-zeroed key->heap.
1 parent e042182 commit b3278af

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

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
@@ -10737,10 +10737,12 @@ dilithium_key* wc_dilithium_new(void* heap, int devId)
1073710737

1073810738
int wc_dilithium_delete(dilithium_key* key, dilithium_key** key_p)
1073910739
{
10740+
void* heap;
1074010741
if (key == NULL)
1074110742
return BAD_FUNC_ARG;
10743+
heap = key->heap;
1074210744
wc_dilithium_free(key);
10743-
XFREE(key, key->heap, DYNAMIC_TYPE_DILITHIUM);
10745+
XFREE(key, heap, DYNAMIC_TYPE_DILITHIUM);
1074410746
if (key_p != NULL)
1074510747
*key_p = NULL;
1074610748

wolfcrypt/src/ed25519.c

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

10491049
int wc_ed25519_delete(ed25519_key* key, ed25519_key** key_p) {
1050+
void* heap;
10501051
if (key == NULL)
10511052
return BAD_FUNC_ARG;
1053+
heap = key->heap;
10521054
wc_ed25519_free(key);
1053-
XFREE(key, key->heap, DYNAMIC_TYPE_ED25519);
1055+
XFREE(key, heap, DYNAMIC_TYPE_ED25519);
10541056
if (key_p != NULL)
10551057
*key_p = NULL;
10561058
return 0;

0 commit comments

Comments
 (0)