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 Aug 2, 2024
1 parent 0964f80 commit d548318
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion curve25519-dalek/src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ use crate::traits::{VartimeMultiscalarMul, VartimePrecomputedMultiscalarMul};
///
/// The first 255 bits of a `CompressedEdwardsY` represent the
/// \\(y\\)-coordinate. The high bit of the 32nd byte gives the sign of \\(x\\).
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[allow(clippy::derived_hash_with_manual_eq)]
#[derive(Copy, Clone, Hash)]
pub struct CompressedEdwardsY(pub [u8; 32]);

impl ConstantTimeEq for CompressedEdwardsY {
Expand All @@ -170,6 +171,13 @@ impl ConstantTimeEq for CompressedEdwardsY {
}
}

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

impl Debug for CompressedEdwardsY {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "CompressedEdwardsY: {:?}", self.as_bytes())
Expand Down

0 comments on commit d548318

Please sign in to comment.