Skip to content

Commit

Permalink
RSA: Eliminate a redundant clone.
Browse files Browse the repository at this point in the history
Commit be27e8e made this clone
unnecessary.
  • Loading branch information
briansmith committed Nov 7, 2023
1 parent e51c88a commit de259a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/rsa/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}

Expand Down
6 changes: 3 additions & 3 deletions src/rsa/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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<N>) -> bigint::Elem<N> {
pub(super) fn exponentiate_elem(&self, base: &bigint::Elem<N>) -> bigint::Elem<N> {
// 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.
Expand All @@ -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)
}
}

Expand Down

0 comments on commit de259a2

Please sign in to comment.