Skip to content

Make RsaPrivateKey::from_components fallible#167

Merged
tarcieri merged 1 commit intomasterfrom
make-rsaprivatekey-from-components-fallible
Jul 25, 2022
Merged

Make RsaPrivateKey::from_components fallible#167
tarcieri merged 1 commit intomasterfrom
make-rsaprivatekey-from-components-fallible

Conversation

@tarcieri
Copy link
Member

Adds an error case in the event the number of primes provides is fewer than 2, which prevents panics when invoking methods which expect primes to always be present at indices 0 and 1 (i.e. p and q)

Fixes #163

Adds an error case in the event the number of `primes` provides is fewer
than 2, which prevents panics when invoking methods which expect primes
to always be present at indices 0 and 1 (i.e. `p` and `q`)

Fixes #163
Comment on lines +67 to +68
[profile.dev]
opt-level = 2
Copy link
Member Author

Choose a reason for hiding this comment

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

Threw this in there too. It significantly speeds up non-release tests.

@tarcieri
Copy link
Member Author

We could also add a check that the modulus is under some prescribed sanity limit (e.g. 16384 bits)

@Erik1000
Copy link

We could also add a check that the modulus is under some prescribed sanity limit (e.g. 16384 bits)

Yes, there should definitely be a sanity check. E.g. because of #166 since this would probably work with private keys too.

Copy link
Member

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

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

lgtm, thanks

@dignifiedquire
Copy link
Member

We could also add a check that the modulus is under some prescribed sanity limit (e.g. 16384 bits)

Lets do that together with the compile time flags though, as that will be a (bigger) breaking change

@tarcieri tarcieri merged commit 4ccdcf9 into master Jul 25, 2022
@tarcieri tarcieri deleted the make-rsaprivatekey-from-components-fallible branch July 25, 2022 12:35
@tarcieri tarcieri mentioned this pull request Oct 10, 2022
takumi-earth pushed a commit to earthlings-dev/RSA that referenced this pull request Jan 27, 2026
Adds an error case in the event the number of `primes` provides is fewer
than 2, which prevents panics when invoking methods which expect primes
to always be present at indices 0 and 1 (i.e. `p` and `q`)

Fixes RustCrypto#163
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.

RsaPrivateKey::from_components might panic

3 participants