From 4c3fd82e7a8f899ef37904d5a77acf8b395f834f Mon Sep 17 00:00:00 2001 From: Aaron Feickert <66188213+AaronFeickert@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:56:29 -0500 Subject: [PATCH] Use constant-time compressed equality testing --- curve25519-dalek/src/ristretto.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/curve25519-dalek/src/ristretto.rs b/curve25519-dalek/src/ristretto.rs index 8e14c1030..201e72bd8 100644 --- a/curve25519-dalek/src/ristretto.rs +++ b/curve25519-dalek/src/ristretto.rs @@ -215,9 +215,17 @@ 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)] +#[allow(clippy::derived_hash_with_manual_eq)] +#[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())