Skip to content

Commit

Permalink
Impl core::hash::Hash for RsaPrivateKey (#308)
Browse files Browse the repository at this point in the history
Adds an impl which hashes only the public key components, along with a
domain separator string (`RsaPrivateKey`).

Closes #165
  • Loading branch information
tarcieri committed Apr 25, 2023
1 parent faabaa7 commit c012868
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use alloc::vec::Vec;
use core::ops::Deref;
use core::{
hash::{Hash, Hasher},
ops::Deref,
};
use num_bigint::traits::ModInverse;
use num_bigint::Sign::Plus;
use num_bigint::{BigInt, BigUint};
Expand Down Expand Up @@ -40,6 +43,7 @@ pub struct RsaPrivateKey {
pub(crate) precomputed: Option<PrecomputedValues>,
}

impl Eq for RsaPrivateKey {}
impl PartialEq for RsaPrivateKey {
#[inline]
fn eq(&self, other: &RsaPrivateKey) -> bool {
Expand All @@ -49,7 +53,13 @@ impl PartialEq for RsaPrivateKey {
}
}

impl Eq for RsaPrivateKey {}
impl Hash for RsaPrivateKey {
fn hash<H: Hasher>(&self, state: &mut H) -> () {
// Domain separator for RSA private keys
state.write(b"RsaPrivateKey");
Hash::hash(&self.pubkey_components, state);
}
}

impl Zeroize for RsaPrivateKey {
fn zeroize(&mut self) {
Expand Down

0 comments on commit c012868

Please sign in to comment.