diff --git a/polyfuzzy/src/fmd2.rs b/polyfuzzy/src/fmd2.rs index 9cd0acc..4e4f766 100644 --- a/polyfuzzy/src/fmd2.rs +++ b/polyfuzzy/src/fmd2.rs @@ -16,7 +16,7 @@ use crate::{ DetectionKey, FmdKeyGen, FmdSecretKey, MultiFmdScheme, }; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// γ public subkeys (points). The basepoint is hardcoded to the Ristretto basepoint. pub struct FmdPublicKey { @@ -31,7 +31,7 @@ impl From for FmdPublicKey { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// A point `u`, a scalar `y`, and γ ciphertext bits `c`. pub struct FlagCiphertexts { @@ -59,7 +59,7 @@ impl From for FlagCiphertexts { } /// The multi-key scheme. -#[derive(Debug, Clone)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Fmd2MultikeyScheme { gamma: usize, } diff --git a/polyfuzzy/src/fmd2_compact/mod.rs b/polyfuzzy/src/fmd2_compact/mod.rs index 9338a71..111be85 100644 --- a/polyfuzzy/src/fmd2_compact/mod.rs +++ b/polyfuzzy/src/fmd2_compact/mod.rs @@ -19,6 +19,7 @@ use crate::{ }; /// A polynomial over the scalar field of Ristretto of degree = `t` (the threshold parameter). +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct CompactSecretKey(Polynomial); @@ -33,7 +34,7 @@ impl CompactSecretKey { /// An encoded polynomial over Ristretto. t+2 points. /// The first point is the basepoint, the remaining /// t+1 points the encoded coefficients. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct CompactPublicKey { fingerprint: [u8; 20], polynomial: EncodedPolynomial, @@ -73,7 +74,7 @@ impl CompactPublicKey { /// A compressed representation that drops the basepoint. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct CompressedCompactPublicKey { coeffs: Vec, } @@ -90,13 +91,13 @@ impl CompressedCompactPublicKey { /// The evaluations of the secret polynomial /// encoded using an arbitrary basepoint. -#[derive(PartialEq, Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct FmdPublicKey(PointEvaluations); /// The basepoint for the chamaleon hash, /// and `u`, `y`, `c`. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct FlagCiphertexts(GenericFlagCiphertexts); impl FlagCiphertexts { @@ -108,7 +109,7 @@ impl FlagCiphertexts { } /// Cache of expanded FMD public keys. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] struct ExpandedKeyCache { /// Fingerprint of the [`CompactPublicKey`]. fingerprint: [u8; 20], @@ -134,7 +135,7 @@ impl ExpandedKeyCache { } /// The multi-key FMD scheme supporting key expansion and key randomization. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct MultiFmd2CompactScheme { /// The threshold parameter threshold: usize, diff --git a/polyfuzzy/src/fmd2_compact/polynomial.rs b/polyfuzzy/src/fmd2_compact/polynomial.rs index 4887fa3..aacafca 100644 --- a/polyfuzzy/src/fmd2_compact/polynomial.rs +++ b/polyfuzzy/src/fmd2_compact/polynomial.rs @@ -5,6 +5,7 @@ use curve25519_dalek::{RistrettoPoint, Scalar}; use serde::{Deserialize, Serialize}; /// A degree `t` polynomial p(X) in Z_q[X] given by its t+1 coefficients. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub(crate) struct Polynomial { coeffs: Vec, @@ -12,7 +13,7 @@ pub(crate) struct Polynomial { /// A degree t polynomial encoded in the exponent of a Ristretto point /// given by its t+1 points. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct EncodedPolynomial { pub(crate) basepoint: RistrettoPoint, pub(crate) coeffs: Vec, @@ -20,13 +21,14 @@ pub(crate) struct EncodedPolynomial { /// γ scalar evaluations of the polynomial p(X) at public scalars. /// result[i] = p(public_scalar[i]) +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub(crate) struct ScalarEvaluations { pub(crate) results: Vec, } /// γ point evaluations of the polynomial p(X) at public scalars. /// result[i] = p(public_scalar[i]) * basepoint -#[derive(PartialEq, Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct PointEvaluations { pub(crate) basepoint: RistrettoPoint, pub(crate) results: Vec, diff --git a/polyfuzzy/src/fmd2_generic.rs b/polyfuzzy/src/fmd2_generic.rs index f71b90a..f0ffa38 100644 --- a/polyfuzzy/src/fmd2_generic.rs +++ b/polyfuzzy/src/fmd2_generic.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256, Sha512}; /// Compressed representation of the γ bit-ciphertexts of a [`GenericFlagCiphertexts`]. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub(crate) struct CompressedCiphertextBits(pub(crate) Vec); @@ -31,7 +31,7 @@ impl CompressedCiphertextBits { } /// Decompressed inner bit-ciphertexts of a [`GenericFlagCiphertexts`]. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub(crate) struct CiphertextBits(pub(crate) Vec); @@ -55,7 +55,7 @@ impl CiphertextBits { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// γ secret subkeys (scalars). For minimum false-positive rate p:=2^{-γ}. pub struct FmdSecretKey(pub(crate) Vec); @@ -135,7 +135,7 @@ impl FmdSecretKey { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// A subset of n-out-γ secret subkeys, and the positions /// they occupy in [FmdSecretKey]. @@ -193,12 +193,13 @@ impl DetectionKey { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct GenericFmdPublicKey { pub(crate) basepoint_eg: RistrettoPoint, // Basepoint to generate the DDH mask (for ElGamal). pub(crate) keys: Vec, } +#[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct ChamaleonHashBasepoint { base: RistrettoPoint, // Basepoint for the Chamaleon Hash. dlog: Scalar, // Discrete log of `basepoint_ch` in base `GenericPublicKey.basepoint_eg`. @@ -222,7 +223,7 @@ impl Default for ChamaleonHashBasepoint { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub(crate) struct GenericFlagCiphertexts { pub(crate) basepoint_ch: RistrettoPoint, // Basepoint for the Chamaleon Hash.