Repository navigation
Always run RSA software cleanup after free callback - #12028
Merged
Merged
Conversation
Keep the device status but still wipe private key fields in wc_FreeRsaKey.
|
SparkiDev
approved these changes
Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
wc_FreeRsaKey()returned right after the crypto callback free when thecallback returned anything other than
CRYPTOCB_UNAVAILABLE. That skippedthe software cleanup, so
d,p,q,dP,dQanducould stay inmemory if the device did not wipe them.
Now the callback status is kept and the software cleanup always runs. The
function still returns the callback's status (0, or the device error). This
matches how
wc_ecc_free,wc_HmacFreeandwc_CmacFreealready work.Note: a callback that returns 0 no longer skips the software cleanup. A
callback that already frees the key itself (sets
devIdtoINVALID_DEVIDand calls
wc_FreeRsaKey) now gets the cleanup run twice. That is safe:mp_forcezero/mp_clearhandle already-cleared values.Testing
test_wc_FreeRsaKey_CryptoCbintests/api/test_rsa.c: device returns0, device returns an error, device declines, and no device. Checks the
return value, the callback count, and that every key field is zero.
wc_FreeRsaKey(NULL)check totest_wc_InitRsaKey.rsa.cand passes with this change.unit.test --group rsaandtestwolfcryptpass with--enable-cryptocb --enable-cryptocbutils, on SP math,--enable-heapmath,and
-DWOLFSSL_CHECK_MEM_ZERO.