Repository navigation
Fix RSA state machine for the pending crypto operations - #12289
yosuke-wolfssl wants to merge 3 commits into
Conversation
- The input range checks in wc_RsaFunction_ex() set ret and fall through to the shared error handler. - Add test_wc_RsaOaep_AsyncRangeFailReset. Issue: F-19064
|
There was a problem hiding this comment.
🟡 Changes recommended
The new guard enables RSA handshake tests in public-only and verify-only builds where RSA signing is unavailable, causing failures in supported configurations unless both restricted modes are excluded.
1 open issue
What changed in this PR
This PR fixes RSA operation recovery after asynchronous validation failures and pending crypto callbacks, including signature verification during TLS handshakes.
Changes:
- Routes RSA range-check failures through shared state and buffer cleanup.
- Preserves callback retry states and reinitializes signature events where reinvocation is required.
- Adds regression tests for key reuse after failure and repeated pending callbacks.
| File | Description |
|---|---|
wolfcrypt/src/rsa.c |
Fixes error cleanup and pending-operation state transitions. |
wolfcrypt/src/asn.c |
Reinitializes async events when retrying signature verification. |
tests/api/test_tls13.c |
Adds RSA callback tests and repeated-pending handshake coverage. |
tests/api/test_rsa.h |
Declares and registers the new RSA regression tests. |
tests/api/test_rsa.c |
Tests range-failure recovery and callback reinvocation. |
Review effort: Balanced
5ff3f62 to
3a88f21
Compare
|
@claude review |
- wc_RsaDirect(), RsaPublicEncryptEx() and RsaPrivateDecryptEx() move past the exponentiation on WC_PENDING_E only with WOLFSSL_ASYNC_CRYPT_SW, HAVE_INTEL_QA or HAVE_CAVIUM. - ConfirmSignature() sets up the async event at the start of SIG_STATE_DO when none of those backends is built in. - tests: add test_wc_RsaPending_CryptoCbReinvoke, extend rsa_pending_test_cb, and stop test_rsa_oaep_async after TEST_RSA_PENDING_MAX_CALLS. Issue: F-19075
- FreeSignatureCtx() sets sigCtx->asyncDev to NULL along with freeing the key it points into.
3a88f21 to
e3aaa6b
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12289
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_rsa.h
Coverage: 4 of 4 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max

Problem
Two bugs in how an
RsaKeyresumes an operation after it returnsWC_PENDING_E:wc_RsaFunction_ex()returned before the shared error handler that resetskey->stateand freeskey->data.RsaPublicEncryptEx(),RsaPrivateDecryptEx()andwc_RsaDirect()still moved past the exponentiation onWC_PENDING_E. The next call never reached the callback and un-padded its own input.Fix (
wolfcrypt/src/rsa.c,wolfcrypt/src/asn.c)wc_RsaFunction_ex(): the range checks setretand fall through to the shared error handler.WC_PENDING_Eonly withWOLFSSL_ASYNC_CRYPT_SW,HAVE_INTEL_QAorHAVE_CAVIUM, the same split asWOLFSSL_ASYNC_REINVOKE.ConfirmSignature()sets up the event at the start ofSIG_STATE_DOon every entry in those builds. The block inSIG_STATE_KEYis unchanged, so builds where the poll finishes the job compile as before (Nitrox readsevent.reton resume).FreeSignatureCtx: Clears sigCtx->asyncDev along with the freed key for WOLFSSL_ASYNC_CRYPT.Behaviour change: a callback that computes the result and then returns
WC_PENDING_Eis now called again for RSA.Closes f-19064 and f-19075.
Tests
test_wc_RsaOaep_AsyncRangeFailResettest_wc_RsaPending_CryptoCbReinvoketest_tls13_cryptocb_asyncrsa_pending_test_cbnow pends first and computes when called again.Verification
--enable-all --enable-asynccrypt, GCC-Terror:unit.test3313 tests, 0 failed.--enable-all --enable-asynccrypt-sw: the async-SW test passes; the only failures are 2 AES-GCM nonce tests that also fail on master.--enable-asynccrypt --enable-cryptocb, with and withoutWOLF_CRYPTO_CB_ASYNC_POLL:rsa,tls13andasyncgroups 0 failed. Clean under ASan + UBSan, and LeakSanitizer on Linux.--enable-cryptocb,--enable-alland the default build:rsagroup andtestwolfcryptpass; defaultmake check0 failed.Not in this PR
wc_RsaUnPad_ex().