Clamp Montgomery exponent bit bounds#1273
Open
tob-joe wants to merge 1 commit into
Open
Conversation
Treat oversized bounded Montgomery exponent lengths as requests for all available exponent bits instead of indexing past the exponent limbs. Clamp exponent_bits at the shared Montgomery exponentiation entry points so missing high exponent bits are handled as zero. Add regression tests for the standard, AMM, array multi-exponentiation, and alloc slice multi-exponentiation helpers. Co-authored-by: GPT 5.5 <gpt-5.5@openai.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1273 +/- ##
==========================================
+ Coverage 90.99% 91.02% +0.02%
==========================================
Files 189 189
Lines 22139 22195 +56
==========================================
+ Hits 20146 20202 +56
Misses 1993 1993 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Bounded Montgomery exponentiation APIs define
exponent_bitsas the number of least-significant exponent bits to take into account:crypto-bigint/src/modular/fixed_monty_form/pow.rs
Lines 21 to 30 in 4c6f87d
crypto-bigint/src/modular/const_monty_form/pow.rs
Lines 21 to 30 in 4c6f87d
crypto-bigint/src/modular/boxed_monty_form/pow.rs
Lines 13 to 24 in 4c6f87d
When
exponent_bitsexceeded the supplied exponent precision, the Montgomery helpers could derive an out-of-range limb index. Since exponent limbs are little-endian, those missing high exponent bits should be treated as zero.Fix
Clamp
exponent_bitsto the supplied exponent precision at the shared Montgomery exponentiation entry points. This makes oversized bounded exponent lengths behave like full-precision exponentiation instead of indexing past the exponent limbs.Tests
Added regression tests covering oversized
exponent_bitsfor:Verified with:
This work was completed by Trail of Bits as part of the Patch The Planet project in collaboration with OpenAI. The issue was identified primarily by the Codex coding agent, and manually reviewed before submission.