Skip to content

Left-pad X9.31 RSA signature complement to the modulus size - #256

Closed
aidangarske wants to merge 1 commit into
wolfSSL:masterfrom
aidangarske:fix-x931-sig-leading-zero
Closed

aidangarske wants to merge 1 commit into
wolfSSL:masterfrom
aidangarske:fix-x931-sig-leading-zero

Conversation

@aidangarske

Copy link
Copy Markdown
Member
  • X9.31 signing returns n - s when that is smaller than s, but writes it with mp_to_unsigned_bin, which drops leading zero
    bytes.
  • When n - s is shorter than the modulus, the signature bytes land at the wrong offset and the last byte is left stale, so the
    signature is invalid.
  • This makes test_rsa_sign_verify_x931 fail on about 0.5% of runs, depending on the random message; it showed up as a flaky
    valgrind CI failure.
  • The fix left-pads the value with zeros to the full signature length on both the sign and verify paths.
  • Both paths now read back only the bytes the RSA operation wrote, not the caller's full buffer length.
  • New regression test: a fixed message whose X9.31 signature starts with a zero byte. It checks that wolfEngine's signature
    matches OpenSSL's byte for byte, and that each side verifies the other's signature.
  • Testing: the new test fails without the fix. With the fix, ./test/unit.test --static 70 looped 1500 times had 0 failures
    (unmodified master: 7/1500), and the full unit suite passes in dynamic and static modes.

@aidangarske aidangarske self-assigned this Oct 20, 2026
@aidangarske

Copy link
Copy Markdown
Member Author

Jenkins retest this please

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #256

Scan targets checked: wolfengine-src, wolfengine-bugs
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: test/test_rsa.c

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: Lite

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