Skip to content

Commit cf5c126

Browse files
committed
dh: deregister mem-zero entries in wc_FreeDhKey
wc_DhImportKeyPair() registers key->priv for zero-on-free tracking via mp_memzero_add() under WOLFSSL_CHECK_MEM_ZERO, but wc_FreeDhKey() cleared priv with mp_forcezero(), which zeroes the data without removing the registration. Unlike wc_FreeRsaKey(), wc_FreeDhKey() had no wc_MemZero_Check() to remove the entry, so the registration leaked past the DhKey's lifetime and a later, unrelated wc_MemZero_Check() over reused stack could false-abort on it. Add wc_MemZero_Check(key, sizeof(*key)) at the end of wc_FreeDhKey(), mirroring wc_FreeRsaKey().
1 parent 8dcef49 commit cf5c126

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

wolfcrypt/src/dh.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,13 @@ int wc_FreeDhKey(DhKey* key)
10131013
#ifdef WOLFSSL_KCAPI_DH
10141014
KcapiDh_Free(key);
10151015
#endif
1016+
#ifdef WOLFSSL_CHECK_MEM_ZERO
1017+
/* Deregister any mem-zero entries covering this key (e.g. key->priv
1018+
* registered by wc_DhImportKeyPair) now that its fields are zeroed.
1019+
* Mirrors wc_FreeRsaKey(); mp_forcezero() alone does not remove the
1020+
* registration, so without this the entry leaks into later checks. */
1021+
wc_MemZero_Check(key, sizeof(*key));
1022+
#endif
10161023
}
10171024
return 0;
10181025
}

0 commit comments

Comments
 (0)