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 2dab023
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/dhke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

use core::ops::Mul;

use digest::typenum::Diff;
use subtle::{Choice, ConstantTimeEq};
use tari_utilities::ByteArrayError;
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 +53,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 2dab023

Please sign in to comment.