Skip to content

Commit

Permalink
Use constant-time equality checking for DHKE
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Jul 3, 2024
1 parent bdf1d83 commit 9740715
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/dhke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
use crate::keys::PublicKey;

/// The result of a Diffie-Hellman key exchange
#[derive(PartialEq, Eq, Zeroize, ZeroizeOnDrop)]
#[derive(Zeroize, ZeroizeOnDrop)]
pub struct DiffieHellmanSharedSecret<P>(P)
where P: PublicKey;

Expand Down Expand Up @@ -52,6 +52,16 @@ where P: PublicKey
}
}

impl<P> Eq for DiffieHellmanSharedSecret<P> where P: PublicKey {}

impl<P> PartialEq for DiffieHellmanSharedSecret<P>
where P: PublicKey
{
fn eq(&self, other: &Self) -> bool {
self.0.ct_eq(&other.0).into()
}
}

#[cfg(test)]
mod test {
use rand_core::OsRng;
Expand Down

0 comments on commit 9740715

Please sign in to comment.