From 1467732616868f43055f44012096477933959ec5 Mon Sep 17 00:00:00 2001 From: BGluth Date: Mon, 14 Feb 2022 12:41:24 -0700 Subject: [PATCH] Impled `Hash` for `AffinePoint` --- plonky2/src/curve/curve_types.rs | 12 ++++++++++++ plonky2/src/curve/ecdsa.rs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plonky2/src/curve/curve_types.rs b/plonky2/src/curve/curve_types.rs index 15f80bc6..264120c7 100644 --- a/plonky2/src/curve/curve_types.rs +++ b/plonky2/src/curve/curve_types.rs @@ -1,4 +1,5 @@ use std::fmt::Debug; +use std::hash::Hash; use std::ops::Neg; use plonky2_field::field_types::{Field, PrimeField}; @@ -120,6 +121,17 @@ impl PartialEq for AffinePoint { impl Eq for AffinePoint {} +impl Hash for AffinePoint { + fn hash(&self, state: &mut H) { + if self.zero { + self.zero.hash(state); + } else { + self.x.hash(state); + self.y.hash(state); + } + } +} + /// A point on a short Weierstrass curve, represented in projective coordinates. #[derive(Copy, Clone, Debug)] pub struct ProjectivePoint { diff --git a/plonky2/src/curve/ecdsa.rs b/plonky2/src/curve/ecdsa.rs index 11e05535..cabe038a 100644 --- a/plonky2/src/curve/ecdsa.rs +++ b/plonky2/src/curve/ecdsa.rs @@ -13,7 +13,7 @@ pub struct ECDSASignature { #[derive(Copy, Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] pub struct ECDSASecretKey(pub C::ScalarField); -#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Copy, Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] pub struct ECDSAPublicKey(pub AffinePoint); pub fn sign_message(msg: C::ScalarField, sk: ECDSASecretKey) -> ECDSASignature {