From 7f575f06e598e7b3113e0e11114da3c149dd8482 Mon Sep 17 00:00:00 2001 From: David Palm Date: Thu, 22 Aug 2024 11:46:00 +0200 Subject: [PATCH] Derive Hash for a bunch of types --- src/modular/boxed_monty_form.rs | 4 ++-- src/modular/boxed_monty_form/inv.rs | 2 +- src/modular/const_monty_form.rs | 2 +- src/modular/monty_form.rs | 4 ++-- src/uint/div_limb.rs | 2 +- src/wrapping.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/modular/boxed_monty_form.rs b/src/modular/boxed_monty_form.rs index 5d989156..09224f38 100644 --- a/src/modular/boxed_monty_form.rs +++ b/src/modular/boxed_monty_form.rs @@ -20,7 +20,7 @@ use zeroize::Zeroize; /// Parameters to efficiently go to/from the Montgomery form for an odd modulus whose size and value /// are both chosen at runtime. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Hash)] pub struct BoxedMontyParams { /// The constant modulus modulus: Odd, @@ -115,7 +115,7 @@ impl BoxedMontyParams { } /// An integer in Montgomery form represented using heap-allocated limbs. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Hash)] pub struct BoxedMontyForm { /// Value in the Montgomery form. montgomery_form: BoxedUint, diff --git a/src/modular/boxed_monty_form/inv.rs b/src/modular/boxed_monty_form/inv.rs index 38bf308f..99ad3116 100644 --- a/src/modular/boxed_monty_form/inv.rs +++ b/src/modular/boxed_monty_form/inv.rs @@ -37,7 +37,7 @@ impl PrecomputeInverter for BoxedMontyParams { } } -/// Bernstein-Yang inverter which inverts [`DynResidue`] types. +/// Bernstein-Yang inverter which inverts [`MontyForm`] types. pub struct BoxedMontyFormInverter { /// Precomputed Bernstein-Yang inverter. inverter: BoxedSafeGcdInverter, diff --git a/src/modular/const_monty_form.rs b/src/modular/const_monty_form.rs index ae4d2a7a..0e0c973f 100644 --- a/src/modular/const_monty_form.rs +++ b/src/modular/const_monty_form.rs @@ -68,7 +68,7 @@ pub trait ConstMontyParams: /// The modulus is constant, so it cannot be set at runtime. /// /// Internally, the value is stored in Montgomery form (multiplied by MOD::ONE) until it is retrieved. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct ConstMontyForm, const LIMBS: usize> { montgomery_form: Uint, phantom: PhantomData, diff --git a/src/modular/monty_form.rs b/src/modular/monty_form.rs index 95c4aadb..9e5af5c4 100644 --- a/src/modular/monty_form.rs +++ b/src/modular/monty_form.rs @@ -17,7 +17,7 @@ use crate::{Concat, Limb, Monty, NonZero, Odd, Split, Uint, Word}; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq}; /// Parameters to efficiently go to/from the Montgomery form for an odd modulus provided at runtime. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct MontyParams { /// The constant modulus modulus: Odd>, @@ -145,7 +145,7 @@ impl ConstantTimeEq for MontyParams { /// An integer in Montgomery form represented using `LIMBS` limbs. /// The odd modulus is set at runtime. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct MontyForm { montgomery_form: Uint, params: MontyParams, diff --git a/src/uint/div_limb.rs b/src/uint/div_limb.rs index 775bac64..1d16461e 100644 --- a/src/uint/div_limb.rs +++ b/src/uint/div_limb.rs @@ -187,7 +187,7 @@ pub(crate) const fn div3by2( } /// A pre-calculated reciprocal for division by a single limb. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct Reciprocal { divisor_normalized: Word, shift: u32, diff --git a/src/wrapping.rs b/src/wrapping.rs index 86640246..6b0c639b 100644 --- a/src/wrapping.rs +++ b/src/wrapping.rs @@ -17,7 +17,7 @@ use serdect::serde::{Deserialize, Deserializer, Serialize, Serializer}; /// /// This is analogous to [`core::num::Wrapping`] but allows this crate to /// define trait impls for this type. -#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct Wrapping(pub T); impl Add for Wrapping {