Skip to content

Commit

Permalink
happy clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jul 6, 2024
1 parent 53781fb commit 9c15ea9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/algorithms/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub(crate) fn generate_multi_prime_key_with_exp<R: CryptoRngCore>(

Ok(RsaPrivateKeyComponents {
n: n_final,
e: exp.clone(),
e: exp,
d: d_final,
primes,
})
Expand Down
10 changes: 5 additions & 5 deletions src/algorithms/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn rsa_decrypt<R: CryptoRngCore + ?Sized>(
let bits = d.bits_precision();

let c = if let Some(ref mut rng) = rng {
let (blinded, unblinder) = blind(rng, priv_key, &c, &n_params);
let (blinded, unblinder) = blind(rng, priv_key, c, &n_params);
ir = Some(unblinder);
blinded.widen(bits)
} else {
Expand All @@ -60,7 +60,7 @@ pub fn rsa_decrypt<R: CryptoRngCore + ?Sized>(

let m = if is_multiprime || !has_precomputes {
// c^d (mod n)
pow_mod_params(&c, &d, n_params.clone())
pow_mod_params(&c, d, n_params.clone())
} else {
// We have the precalculated values needed for the CRT.

Expand All @@ -78,10 +78,10 @@ pub fn rsa_decrypt<R: CryptoRngCore + ?Sized>(

// m1 = c^dP mod p
let cp = BoxedMontyForm::new(c.clone(), p_params.clone());
let mut m1 = cp.pow(&dp);
let mut m1 = cp.pow(dp);
// m2 = c^dQ mod q
let cq = BoxedMontyForm::new(c, q_params.clone());
let m2 = cq.pow(&dq).retrieve();
let m2 = cq.pow(dq).retrieve();

// (m1 - m2) mod p = (m1 mod p) - (m2 mod p) mod p
let m2r = BoxedMontyForm::new(m2.clone(), p_params.clone());
Expand Down Expand Up @@ -200,7 +200,7 @@ fn unblind(m: &BoxedUint, unblinder: &BoxedUint, n_params: BoxedMontyParams) ->

/// Computes `base.pow_mod(exp, n)` with precomputed `n_params`.
fn pow_mod_params(base: &BoxedUint, exp: &BoxedUint, n_params: BoxedMontyParams) -> BoxedUint {
let base = reduce(&base, n_params);
let base = reduce(base, n_params);
base.pow(exp).retrieve()
}

Expand Down
2 changes: 1 addition & 1 deletion src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl TryFrom<pkcs8::PrivateKeyInfo<'_>> for RsaPrivateKey {

let n = BoxedUint::from_be_slice(pkcs1_key.modulus.as_bytes(), bits)
.map_err(|_| key_malformed)?;
let n = Option::from(Odd::new(n)).ok_or_else(|| key_malformed)?;
let n = Option::from(Odd::new(n)).ok_or(key_malformed)?;

// exponent potentially needs padding
let mut e_slice = [0u8; 8];
Expand Down
4 changes: 2 additions & 2 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl From<&RsaPrivateKey> for RsaPublicKey {
let n_params = PublicKeyParts::n_params(private_key);
RsaPublicKey {
n: n.clone(),
e: e.clone(),
e,
n_params,
}
}
Expand Down Expand Up @@ -547,7 +547,7 @@ impl PrivateKeyParts for RsaPrivateKey {
/// Check that the public key is well formed and has an exponent within acceptable bounds.
#[inline]
pub fn check_public(public_key: &impl PublicKeyParts) -> Result<()> {
check_public_with_max_size(&public_key.n(), public_key.e(), RsaPublicKey::MAX_SIZE)
check_public_with_max_size(public_key.n(), public_key.e(), RsaPublicKey::MAX_SIZE)
}

/// Check that the public key is well formed and has an exponent within acceptable bounds.
Expand Down
2 changes: 1 addition & 1 deletion src/pkcs1v15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn verify(pub_key: &RsaPublicKey, prefix: &[u8], hashed: &[u8], sig: &BoxedUint)
return Err(Error::Verification);
}

let em = uint_to_be_pad(rsa_encrypt(pub_key, &sig)?, pub_key.size())?;
let em = uint_to_be_pad(rsa_encrypt(pub_key, sig)?, pub_key.size())?;

pkcs1v15_sign_unpad(prefix, hashed, &em, pub_key.size())
}
Expand Down
4 changes: 2 additions & 2 deletions src/pss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub(crate) fn verify(
return Err(Error::Verification);
}

let mut em = uint_to_be_pad(rsa_encrypt(pub_key, &sig)?, pub_key.size())?;
let mut em = uint_to_be_pad(rsa_encrypt(pub_key, sig)?, pub_key.size())?;

emsa_pss_verify(hashed, &mut em, salt_len, digest, pub_key.n().bits() as _)
}
Expand All @@ -155,7 +155,7 @@ where
return Err(Error::Verification);
}

let mut em = uint_to_be_pad(rsa_encrypt(pub_key, &sig)?, pub_key.size())?;
let mut em = uint_to_be_pad(rsa_encrypt(pub_key, sig)?, pub_key.size())?;

emsa_pss_verify_digest::<D>(hashed, &mut em, salt_len, pub_key.n().bits() as _)
}
Expand Down

0 comments on commit 9c15ea9

Please sign in to comment.