From b1ea2dfba6464814be0c5c7f8d60b447e668f635 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 7 Mar 2023 03:10:55 -0500 Subject: [PATCH] Add support for hashing (as in HashMap) dalek points --- crypto/dalek-ff-group/src/lib.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crypto/dalek-ff-group/src/lib.rs b/crypto/dalek-ff-group/src/lib.rs index 9ff5f76a..56aaf275 100644 --- a/crypto/dalek-ff-group/src/lib.rs +++ b/crypto/dalek-ff-group/src/lib.rs @@ -2,9 +2,10 @@ #![no_std] use core::{ - ops::{Deref, Add, AddAssign, Sub, SubAssign, Neg, Mul, MulAssign}, borrow::Borrow, + ops::{Deref, Add, AddAssign, Sub, SubAssign, Neg, Mul, MulAssign}, iter::{Iterator, Sum}, + hash::{Hash, Hasher}, }; use zeroize::Zeroize; @@ -413,6 +414,16 @@ macro_rules! dalek_group { $Point(&b.0 * &self.0) } } + + // Support being used as a key in a table + // While it is expensive as a key, due to the field operations required, there's frequently + // use cases for public key -> value lookups + #[allow(clippy::derived_hash_with_manual_eq)] + impl Hash for $Point { + fn hash(&self, state: &mut H) { + self.to_bytes().hash(state); + } + } }; }