Adds RsaPrivateKey::from_primes and RsaPrivateKey::from_p_q methods#386
Merged
tarcieri merged 1 commit intoRustCrypto:masterfrom Nov 28, 2023
Merged
Conversation
649f3ee to
dd51b36
Compare
RsaPrivateKey::from_primes methodRsaPrivateKey::from_primes and RsaPrivateKey::from_p_q methods
baloo
added a commit
to baloo/yubihsm.rs
that referenced
this pull request
Nov 21, 2023
baloo
added a commit
to baloo/yubihsm.rs
that referenced
this pull request
Nov 22, 2023
tarcieri
reviewed
Nov 22, 2023
tarcieri
reviewed
Nov 22, 2023
Comment on lines
+259
to
+278
| /// Compute the private exponent from its primes (p and q) and public exponent | ||
| pub(crate) fn compute_private_exponent(primes: &[BigUint], exp: &BigUint) -> Result<BigUint> { | ||
| if primes.len() < 2 { | ||
| return Err(Error::InvalidPrime); | ||
| } | ||
|
|
||
| let mut totient = BigUint::one(); | ||
|
|
||
| for prime in primes { | ||
| totient *= prime - BigUint::one(); | ||
| } | ||
|
|
||
| if let Some(d) = exp.mod_inverse(totient) { | ||
| Ok(d.to_biguint().unwrap()) | ||
| } else { | ||
| // `exp` evenly divides `totient` | ||
| Err(Error::InvalidPrime) | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Member
Author
There was a problem hiding this comment.
I tried something to reuse those bits. Let me know what you think.
Member
Author
There was a problem hiding this comment.
or make generate reuse those bits, I guess.
Member
|
Couple nits but otherwise this looks fine to me |
ilebedev-arista
left a comment
There was a problem hiding this comment.
Not much of a rust reviewer, but this does look fine to me!
dd51b36 to
4543edd
Compare
This is used on Yubico HSM for import/export under wrap as well as when importing a key unsealed.
4543edd to
7badaa3
Compare
tarcieri
approved these changes
Nov 28, 2023
baloo
added a commit
to baloo/yubihsm.rs
that referenced
this pull request
Nov 28, 2023
Merged
baloo
added a commit
to baloo/yubihsm.rs
that referenced
this pull request
Nov 28, 2023
tony-iqlusion
pushed a commit
to iqlusioninc/yubihsm.rs
that referenced
this pull request
Nov 28, 2023
takumi-earth
pushed a commit
to earthlings-dev/RSA
that referenced
this pull request
Jan 27, 2026
…ds (RustCrypto#386) This is used on Yubico HSM for import/export under wrap as well as when importing a key unsealed.
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.
This is used on Yubico HSM for import/export under wrap as well as when importing a key unsealed.