Skip to content

TLS: reject zero and even RSA moduli before arithmetic - #173

Merged
tinic merged 1 commit into
mainfrom
fix/n171-rsa-even-modulus
Oct 3, 2026
Merged

tinic merged 1 commit into
mainfrom
fix/n171-rsa-even-modulus

Conversation

@tinic

@tinic tinic commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Change

Reject an even RSA modulus, including zero, in our RSA exponentiation boundary before scratch setup or reference/accelerated public/CRT arithmetic. Return NX_CRYPTO_INVALID_KEY without changing output. No vendor arithmetic or certificate-policy change.

Verification

Maintained 32-bit ASan/UBSan contract: 32 checks pass. Four wrapped exponentiation entry points prevent invalid moduli reaching real arithmetic in the old control; old main fails 20 checks while valid odd-key controls pass. Focused production-style m68k Werror compile passed. Host32 test census rises from 26 to 27; LP64 remains 551. These are focused contracts and compilation, not a new full runtime campaign.

Independent exact-diff review is pending; required normal CI must pass before merge. Task branches/build/staging will be cleaned after integration.

ami_rsa_exponentiate() now returns NX_CRYPTO_INVALID_KEY for a modulus
whose last byte is even, before any number is set up.  The X.509 parser
accepts any modulus bytes after the leading zero, so a peer's
intermediate can carry 0x00 and 128 zero bytes; chain verification
checks the leaf against it before it is anchored.  crypto68k refuses an
even modulus and falls back to the vendored arithmetic, whose modulus
scan walks below its buffer for zero.  An RSA modulus is odd, so the
one test covers zero and every other even value, on the public and CRT
paths in both arithmetic modes.  Vendored arithmetic and X.509 policy
are unchanged.

tests/fuzz/tls_rsa_modulus_parity wraps the four exponentiation entry
points at link time; an even modulus never reaches real arithmetic, with
or without this change.  Zero and even moduli on the public and CRT
paths, accelerated and reference: status, no exponentiation, output
canary.  Controls: a real signature verified with the CA key, and the
device key through the CRT inverted by its public key.  af41c34: 32
checks, 20 failures, controls passing.  Here: 0.  Host32 census 26 ->
27; the 64-bit census stays 551.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@tinic
tinic merged commit 21090ed into main Oct 3, 2026
42 of 43 checks passed
@tinic
tinic deleted the fix/n171-rsa-even-modulus branch October 3, 2026 07:26
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.

1 participant