Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Improve code comments and documentation

Co-authored-by: Tony Arcieri <bascule@gmail.com>
  • Loading branch information
zheylmun and tarcieri authored Nov 11, 2023
1 parent d82394b commit 3db40ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/algorithms/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ fn unblind(key: &impl PublicKeyParts, m: &BigUint, unblinder: &BigUint) -> BigUi
}

/// The following (deterministic) algorithm also recovers the prime factors `p` and `q` of a modulus `n`, given the
/// public exponent `e` and private exponent `d`.
/// public exponent `e` and private exponent `d` using the method described in
/// [NIST 800-56B Appendix C.2](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Br2.pdf).
pub fn recover_primes(n: &BigUint, e: &BigUint, d: &BigUint) -> Result<(BigUint, BigUint)> {
// 1. Let a = (de – 1) × GCD(n – 1, de – 1).
let mut a = (d * e - BigUint::one()) * (n - BigUint::one()).gcd(&(d * e - BigUint::one()));
Expand Down
2 changes: 1 addition & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl RsaPrivateKey {
return Err(Error::NprimesTooSmall);
}
// Recover `p` and `q` from `d`.
// See method in Appendix C: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Br1.pdf
// See method in Appendix C.2: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Br2.pdf
let (p, q) = recover_primes(&n, &e, &d)?;
primes.push(p);
primes.push(q);
Expand Down

0 comments on commit 3db40ad

Please sign in to comment.