Skip to content

Fix the signature wrapper for non-blocking keys and apply its hash floor to every entry point - #12397

Open
dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:sig_nonblock
Open

dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:sig_nonblock

Conversation

@dgarske

@dgarske dgarske commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes wolfcrypt/src/signature.c for non-blocking keys and closes gaps in its minimum hash strength check.

  • wc_SignatureVerifyHash() gave its temporary buffer to wc_RsaSSL_VerifyInline(). A non-blocking RsaKey keeps that buffer across FP_WOULDBLOCK returns, after the wrapper has freed it. Non-blocking keys now use wc_RsaSSL_Verify(), so the key owns its working buffer. (F-19063)
  • Non-blocking ECC verify now returns MP_WOULDBLOCK to the caller instead of SIG_VERIFY_E, which left the operation pending in the key. (F-19269)
  • wc_SignatureGenerate*() finishes its post-sign self-check within the call for non-blocking keys. If the check fails, it wipes the signature and sets *sig_len to 0. (F-18525)
  • A negative wc_SignatureGetSize() result is now returned instead of skipping the length check (F-7078). sig_len is compared unsigned (F-16919). A NULL key returns BAD_FUNC_ARG for every signature type (F-12152).
  • The hash floor now also applies to wc_SignatureVerifyHash() and wc_SignatureGenerateHash*() (F-6905) and rates MD5+SHA-1 as SHA-1 (F-16573). Strength is rated by nominal digest size, so the floor holds even when the floor hash itself isn't compiled in (F-9939).

Behavior change: callers of the *Hash APIs that pass MD5, SHA-1 or MD5+SHA-1 now get BAD_FUNC_ARG unless they define a lower WC_SIG_MIN_HASH_TYPE. That matches wc_SignatureVerify() and wc_SignatureGenerate() since v5.9.4. wc_SignatureGetSize() with a NULL ECC key now returns BAD_FUNC_ARG instead of 0.

Resolves F-19063, F-19269, F-18525, F-7078, F-16919, F-12152, F-6905, F-16573, F-9939.

Testing

New tests in tests/api/test_signature.c cover non-blocking RSA and ECC through the wrapper, and the hash floor. Without the fix, the RSA test reports a heap-use-after-free under ASan.

  • SP non-blocking RSA (smallstack and stack), fastmath non-blocking RSA, SP non-blocking ECC: ASan/UBSan.
  • --enable-all (unit.test --api), --enable-wolfclu, and -Werror builds without RSA, without MD5/SHA-1, SHA-512 only, and SHA3 only.

Copilot AI balanced review requested due to automatic review settings December 4, 2026 02:01
@dgarske dgarske self-assigned this Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m4

  • FLASH: .text +128 B (+0.1%, 214,316 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +128 B (+0.1%, 185,103 B / 262,144 B, total: 71% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .rodata +20 B, .text +64 B (+0.0%, 201,656 B / 1,048,576 B, total: 19% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .rodata +16 B, .text +128 B (+0.0%, 807,480 B / 1,048,576 B, total: 77% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +64 B (+0.0%, 227,344 B / 262,144 B, total: 87% used)

gcc-arm-cortex-m4-pq

  • FLASH: .rodata +20 B, .text +64 B (+0.0%, 320,244 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .rodata +16 B, .text +64 B (+0.0%, 349,992 B / 1,048,576 B, total: 33% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +64 B (+0.0%, 256,710 B / 262,144 B, total: 98% used)

gcc-arm-cortex-m7

  • FLASH: .text +128 B (+0.1%, 214,316 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m7-pq

  • FLASH: .rodata +20 B, .text +128 B (+0.0%, 321,140 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +64 B (+0.0%, 256,710 B / 262,144 B, total: 98% used)

stm32-sim-stm32h753

  • FLASH: .text +272 B (+0.1%, 220,840 B / 2,097,152 B, total: 11% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +128 B, text +13,976 B (+5.0%, 296,576 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

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.

🟡 Changes recommended

Hash-floor selection and normalization errors can reject valid signatures, while failed test setup can trigger a crypto free callback on an uninitialized RSA key.

3 open issues
What changed in this PR

This PR hardens wolfCrypt’s signature wrappers for non-blocking keys and applies minimum hash-strength checks consistently across entry points.

Changes:

  • Fixes non-blocking RSA buffer ownership and ECC retry handling.
  • Tightens signature validation and clears signatures when self-checks fail.
  • Adds regression tests and updates API documentation.
File Description
wolfssl/​wolfcrypt/​signature.h Defines default hash-floor selection and policy.
wolfcrypt/​src/​signature.c Updates non-blocking handling, validation, and hash enforcement.
tests/​api/​test_signature.h Registers new signature tests.
tests/​api/​test_signature.c Adds hash-floor and non-blocking regression coverage.
doc/​dox_comments/​header_files/​signature.h Documents argument and hash-strength restrictions.

Review effort: Balanced

Comment thread tests/api/test_signature.c Resolved
Comment thread wolfcrypt/src/signature.c Resolved
Comment thread wolfssl/wolfcrypt/signature.h Resolved
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.

2 participants