Skip to content

Commit

Permalink
Use constant-time compressed equality testing
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Jul 30, 2024
1 parent 0964f80 commit dcd3218
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion curve25519-dalek/src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,16 @@ use crate::traits::{MultiscalarMul, VartimeMultiscalarMul, VartimePrecomputedMul
///
/// The Ristretto encoding is canonical, so two points are equal if and
/// only if their encodings are equal.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Hash)]
pub struct CompressedRistretto(pub [u8; 32]);

impl Eq for CompressedRistretto {}
impl PartialEq for CompressedRistretto {
fn eq(&self, other: &Self) -> bool {
self.ct_eq(other).into()
}
}

impl ConstantTimeEq for CompressedRistretto {
fn ct_eq(&self, other: &CompressedRistretto) -> Choice {
self.as_bytes().ct_eq(other.as_bytes())
Expand Down

0 comments on commit dcd3218

Please sign in to comment.