From de259a201bb9ad4d72b25f5ebc8f7f6870acd1d8 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 4 Nov 2023 12:05:56 -0700 Subject: [PATCH] RSA: Eliminate a redundant clone. Commit be27e8e25946b2e975258cfb1ea21f6cc4731d8c made this clone unnecessary. --- src/rsa/keypair.rs | 2 +- src/rsa/public_key.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rsa/keypair.rs b/src/rsa/keypair.rs index f7cd945b2b..eeae584a6f 100644 --- a/src/rsa/keypair.rs +++ b/src/rsa/keypair.rs @@ -663,7 +663,7 @@ impl KeyPair { // minimum value, since the relationship of `e` to `d`, `p`, and `q` is // not verified during `KeyPair` construction. { - let verify = self.public.inner().exponentiate_elem(m.clone()); + let verify = self.public.inner().exponentiate_elem(&m); bigint::elem_verify_equal_consttime(&verify, &c)?; } diff --git a/src/rsa/public_key.rs b/src/rsa/public_key.rs index b21ee2d011..a10b21fd97 100644 --- a/src/rsa/public_key.rs +++ b/src/rsa/public_key.rs @@ -162,7 +162,7 @@ impl Inner { } // Step 2. - let m = self.exponentiate_elem(s); + let m = self.exponentiate_elem(&s); // Step 3. Ok(fill_be_bytes_n(m, self.n.len_bits(), out_buffer)) @@ -171,7 +171,7 @@ impl Inner { /// Calculates base**e (mod n). /// /// This is constant-time with respect to `base` only. - pub(super) fn exponentiate_elem(&self, base: bigint::Elem) -> bigint::Elem { + pub(super) fn exponentiate_elem(&self, base: &bigint::Elem) -> bigint::Elem { // The exponent was already checked to be at least 3. let exponent_without_low_bit = NonZeroU64::try_from(self.e.value().get() & !1).unwrap(); // The exponent was already checked to be odd. @@ -189,7 +189,7 @@ impl Inner { let acc = bigint::elem_exp_vartime(base_r, exponent_without_low_bit, n); // Now do the multiplication for the low bit and convert out of the Montgomery domain. - bigint::elem_mul(&base, acc, n) + bigint::elem_mul(base, acc, n) } }