Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSA: Eliminate a redundant clone. #1797

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading