fix: do not panic on a prime being 1 when loading a secret key#624
Merged
dignifiedquire merged 2 commits into0-9-xfrom Jan 6, 2026
Merged
fix: do not panic on a prime being 1 when loading a secret key#624dignifiedquire merged 2 commits into0-9-xfrom
dignifiedquire merged 2 commits into0-9-xfrom
Conversation
tarcieri
approved these changes
Jan 6, 2026
tarcieri
reviewed
Jan 6, 2026
| @@ -391,7 +391,7 @@ impl RsaPrivateKey { | |||
| let mut m = BigUint::one(); | |||
| for prime in &self.primes { | |||
| // Any primes ≤ 1 will cause divide-by-zero panics later. | |||
Member
There was a problem hiding this comment.
This comment could perhaps say that 0 and 1 are not prime numbers, but...
mbfm
added a commit
to eclipse-opendut/opendut
that referenced
this pull request
Jan 7, 2026
See for more information: RustCrypto/RSA#624
tarcieri
pushed a commit
that referenced
this pull request
May 1, 2026
…#692) Per @tarcieri's reply on #690: > The fix for the logic is there, however it looks like the regression test wasn't carried over and probably should be. > As it were, the entire implementation diverged as we moved from `num-bigint` to `crypto-bigint`. The production fix lives on master already (`validate_private_key_parts` rejects any `prime <= one` with `Error::InvalidPrime`, src/key.rs:760-763). What was missing was the regression test added alongside it in upstream commit `2926c91bef` (PR #624). This PR ports just that test. ## Adaptations vs the original test - **Type swap**: original used `num-bigint::BigUint` constructors (`BigUint::from_u64`, `BigUint::zero()`); ported to `crypto-bigint::BoxedUint::from(u64)` since that's what current master's `from_components` API takes. - **API path**: the original numeric inputs (`n=239, e=185, d=0, primes=[1, 239]`) include an `e` below master's `MIN_PUB_EXPONENT` bound, so the test calls `from_components_with_large_exponent` (gated `#[cfg(feature = "hazmat")]`, matching the existing `test_from_components_with_small_exponent` / `test_from_components_with_large_exponent` neighbors) rather than `from_components`. Ordering inside `validate_skip_exponent_size` -> `validate_private_key_parts` still hits the `prime <= one` check first, so we exercise exactly the path the original test did. - **Assertion**: `Err(Error::InvalidPrime)` (not a panic) — same intent as the original. No production-code changes. Single-file diff in `src/key.rs`. Refs: GHSA-9c48-w39g-hm26, #690, #624, upstream `2926c91bef`. Co-authored-by: vulgraph <[email protected]>
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.
Fixes GHSA-9c48-w39g-hm26