From 9c15ea920e132d29ef64c40bdb5c5e78049de02e Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sat, 6 Jul 2024 20:15:23 +0200 Subject: [PATCH] happy clippy --- src/algorithms/generate.rs | 2 +- src/algorithms/rsa.rs | 10 +++++----- src/encoding.rs | 2 +- src/key.rs | 4 ++-- src/pkcs1v15.rs | 2 +- src/pss.rs | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/algorithms/generate.rs b/src/algorithms/generate.rs index 034cc985..dae13294 100644 --- a/src/algorithms/generate.rs +++ b/src/algorithms/generate.rs @@ -109,7 +109,7 @@ pub(crate) fn generate_multi_prime_key_with_exp( Ok(RsaPrivateKeyComponents { n: n_final, - e: exp.clone(), + e: exp, d: d_final, primes, }) diff --git a/src/algorithms/rsa.rs b/src/algorithms/rsa.rs index f659fa5c..705db92d 100644 --- a/src/algorithms/rsa.rs +++ b/src/algorithms/rsa.rs @@ -48,7 +48,7 @@ pub fn rsa_decrypt( 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 { @@ -60,7 +60,7 @@ pub fn rsa_decrypt( 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. @@ -78,10 +78,10 @@ pub fn rsa_decrypt( // 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()); @@ -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() } diff --git a/src/encoding.rs b/src/encoding.rs index 34860749..0084ac13 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -58,7 +58,7 @@ impl TryFrom> 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]; diff --git a/src/key.rs b/src/key.rs index 4cb52a94..1db11d78 100644 --- a/src/key.rs +++ b/src/key.rs @@ -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, } } @@ -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. diff --git a/src/pkcs1v15.rs b/src/pkcs1v15.rs index 3ac3bdc0..b0f17dd4 100644 --- a/src/pkcs1v15.rs +++ b/src/pkcs1v15.rs @@ -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()) } diff --git a/src/pss.rs b/src/pss.rs index 855069d7..9a59ab1e 100644 --- a/src/pss.rs +++ b/src/pss.rs @@ -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 _) } @@ -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::(hashed, &mut em, salt_len, pub_key.n().bits() as _) }