Skip to content

Always run RSA software cleanup after free callback - #12028

Merged
SparkiDev merged 1 commit into
wolfSSL:masterfrom
night1rider:fix-forceZero-callback-fix
Nov 6, 2026
Merged

SparkiDev merged 1 commit into
wolfSSL:masterfrom
night1rider:fix-forceZero-callback-fix

Conversation

@night1rider

Copy link
Copy Markdown
Contributor

Description

wc_FreeRsaKey() returned right after the crypto callback free when the
callback returned anything other than CRYPTOCB_UNAVAILABLE. That skipped
the software cleanup, so d, p, q, dP, dQ and u could stay in
memory 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_HmacFree and wc_CmacFree already work.

Note: a callback that returns 0 no longer skips the software cleanup. A
callback that already frees the key itself (sets devId to INVALID_DEVID
and calls wc_FreeRsaKey) now gets the cleanup run twice. That is safe:
mp_forcezero/mp_clear handle already-cleared values.

Testing

  • New test_wc_FreeRsaKey_CryptoCb in tests/api/test_rsa.c: device returns
    0, device returns an error, device declines, and no device. Checks the
    return value, the callback count, and that every key field is zero.
  • Added a wc_FreeRsaKey(NULL) check to test_wc_InitRsaKey.
  • The new test fails on the old rsa.c and passes with this change.
  • unit.test --group rsa and testwolfcrypt pass with
    --enable-cryptocb --enable-cryptocbutils, on SP math, --enable-heapmath,
    and -DWOLFSSL_CHECK_MEM_ZERO.

Keep the device status but still wipe private key fields in wc_FreeRsaKey.
Copilot AI balanced review requested due to automatic review settings November 5, 2026 23:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the RSA key cleanup change.

No open issues 🎉

Review effort: Balanced

@SparkiDev
SparkiDev merged commit de87113 into wolfSSL:master Nov 6, 2026
441 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants