Skip to content

Commit 8f8fca3

Browse files
committed
Use constant-time equality checking for DHKE
1 parent bdf1d83 commit 8f8fca3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/dhke.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
1818
use crate::keys::PublicKey;
1919

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

@@ -52,6 +52,16 @@ where P: PublicKey
5252
}
5353
}
5454

55+
impl<P> Eq for DiffieHellmanSharedSecret<P> where P: PublicKey {}
56+
57+
impl<P> PartialEq for DiffieHellmanSharedSecret<P>
58+
where P: PublicKey
59+
{
60+
fn eq(&self, other: &Self) -> bool {
61+
self.0.ct_eq(&other.0).into()
62+
}
63+
}
64+
5565
#[cfg(test)]
5666
mod test {
5767
use rand_core::OsRng;

0 commit comments

Comments
 (0)