TLS: reject zero and even RSA moduli before arithmetic - #173
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.