From e944f9db3baa4c2d97d2e704ab8704747e1c8ddf Mon Sep 17 00:00:00 2001 From: raphaelrobert Date: Tue, 4 Nov 2025 14:40:16 -0500 Subject: [PATCH] chore: update generic-array to v1 (#143) * update generic-array to v1 * revert displaydoc removal * fix cargo fmt --- Cargo.toml | 6 +++--- src/ciphersuite.rs | 5 +++-- src/common.rs | 16 +++++++--------- src/error.rs | 4 +--- src/group/elliptic_curve.rs | 14 ++++++++++---- src/group/mod.rs | 8 ++++---- src/poprf.rs | 15 +++++++++++---- 7 files changed, 39 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3874ad5..5fb9336 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ version = "0.5.0" alloc = [] danger = [] default = ["ristretto255-ciphersuite", "dep:serde"] -ristretto255 = ["dep:curve25519-dalek", "generic-array/more_lengths"] +ristretto255 = ["dep:curve25519-dalek"] ristretto255-ciphersuite = ["ristretto255", "dep:sha2"] serde = ["curve25519-dalek?/serde", "generic-array/serde", "dep:serde"] std = ["alloc"] @@ -33,7 +33,7 @@ elliptic-curve = { version = "0.13", features = [ "sec1", "voprf", ] } -generic-array = "0.14" +generic-array = "1" rand_core = { version = "0.6", default-features = false } serde = { version = "1", default-features = false, features = [ "derive", @@ -43,7 +43,7 @@ subtle = { version = "2.3", default-features = false } zeroize = { version = "1.5", default-features = false } [dev-dependencies] -generic-array = { version = "0.14", features = ["more_lengths"] } +generic-array = { version = "1" } hex = "0.4" p256 = { version = "0.13", default-features = false, features = [ "hash2curve", diff --git a/src/ciphersuite.rs b/src/ciphersuite.rs index ac346dc..c3a580a 100644 --- a/src/ciphersuite.rs +++ b/src/ciphersuite.rs @@ -12,6 +12,7 @@ use digest::core_api::BlockSizeUser; use digest::{FixedOutput, HashMarker, OutputSizeUser}; use elliptic_curve::VoprfParameters; use generic_array::typenum::{IsLess, IsLessOrEqual, U256}; +use generic_array::ArrayLength; use crate::Group; @@ -19,7 +20,7 @@ use crate::Group; pub trait CipherSuite where ::OutputSize: - IsLess + IsLessOrEqual<::BlockSize>, + ArrayLength + IsLess + IsLessOrEqual<::BlockSize>, { /// The ciphersuite identifier as dictated by /// @@ -39,7 +40,7 @@ where T: Group, T::Hash: BlockSizeUser + Default + FixedOutput + HashMarker, ::OutputSize: - IsLess + IsLessOrEqual<::BlockSize>, + ArrayLength + IsLess + IsLessOrEqual<::BlockSize>, { const ID: &'static str = T::ID; diff --git a/src/common.rs b/src/common.rs index bf4d345..3224791 100644 --- a/src/common.rs +++ b/src/common.rs @@ -12,7 +12,7 @@ use core::convert::TryFrom; use core::ops::Add; use derive_where::derive_where; -use digest::{Digest, Output}; +use digest::{Digest, Output, OutputSizeUser}; use generic_array::sequence::Concat; use generic_array::typenum::{IsLess, Unsigned, U2, U256, U9}; use generic_array::{ArrayLength, GenericArray}; @@ -283,7 +283,7 @@ fn compute_composites< .chain_update(seed_dst.i2osp_2()) .chain_update_multi(&seed_dst.as_dst()) .finalize(); - let seed_len = i2osp_2_array(&seed); + let seed_len = i2osp_2_array::<::OutputSize>(); let mut m = CS::Group::identity_elem(); let mut z = CS::Group::identity_elem(); @@ -442,23 +442,23 @@ pub(crate) fn server_evaluate_hash_input( .chain_update(info.as_ref()); } Ok(hash - .chain_update(i2osp_2(issued_element.as_ref().len()).map_err(|_| Error::Input)?) + .chain_update(i2osp_2(issued_element.as_slice().len()).map_err(|_| Error::Input)?) .chain_update(issued_element) .chain_update(STR_FINALIZE) .finalize()) } -pub(crate) struct Dst> { +pub(crate) struct Dst { dst_1: GenericArray, dst_2: &'static str, } -impl> Dst { +impl Dst { pub(crate) fn new(par_1: T, mode: Mode) -> Self where CS: CipherSuite, T: Into>, - TL: ArrayLength + Add, + TL: ArrayLength + Add, { let par_1 = par_1.into(); // Generates the contextString parameter as defined in @@ -518,8 +518,6 @@ pub(crate) fn i2osp_2(input: usize) -> Result<[u8; 2], InternalError> { .map_err(|_| InternalError::I2osp) } -pub(crate) fn i2osp_2_array + IsLess>( - _: &GenericArray, -) -> GenericArray { +pub(crate) fn i2osp_2_array>() -> GenericArray { L::U16.to_be_bytes().into() } diff --git a/src/error.rs b/src/error.rs index d33f16f..5289715 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,13 +8,11 @@ //! Errors which are produced during an execution of the protocol -use displaydoc::Display; - /// [`Result`](core::result::Result) shorthand that uses [`Error`]. pub type Result = core::result::Result; /// Represents an error in the manipulation of internal cryptographic data -#[derive(Clone, Copy, Debug, Display, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Debug, displaydoc::Display, Eq, Hash, Ord, PartialEq, PartialOrd)] pub enum Error { /// Size of info is longer then [`u16::MAX`]. Info, diff --git a/src/group/elliptic_curve.rs b/src/group/elliptic_curve.rs index fae084d..bb57083 100644 --- a/src/group/elliptic_curve.rs +++ b/src/group/elliptic_curve.rs @@ -14,7 +14,8 @@ use elliptic_curve::group::cofactor::CofactorGroup; use elliptic_curve::hash2curve::{ExpandMsgXmd, FromOkm, GroupDigest}; use elliptic_curve::sec1::{FromEncodedPoint, ModulusSize, ToEncodedPoint}; use elliptic_curve::{ - AffinePoint, Field, FieldBytesSize, Group as _, ProjectivePoint, PublicKey, Scalar, SecretKey, + AffinePoint, Field, FieldBytes, FieldBytesSize, Group as _, ProjectivePoint, PublicKey, Scalar, + SecretKey, }; use generic_array::typenum::{IsLess, IsLessOrEqual, Sum, U256}; use generic_array::{ArrayLength, GenericArray}; @@ -31,14 +32,16 @@ where C: GroupDigest, ProjectivePoint: CofactorGroup + ToEncodedPoint, ScalarLen: ModulusSize, + ScalarLen: ArrayLength, AffinePoint: FromEncodedPoint + ToEncodedPoint, Scalar: FromOkm, // `VoprfClientLen`, `PoprfClientLen`, `VoprfServerLen`, `PoprfServerLen` ScalarLen: Add>, - Sum, ElemLen>: ArrayLength, + Sum, ElemLen>: ArrayLength, // `ProofLen` ScalarLen: Add>, - Sum, ScalarLen>: ArrayLength, + Sum, ScalarLen>: ArrayLength, + ElemLen: ArrayLength, { type Elem = ProjectivePoint; @@ -108,7 +111,10 @@ where } fn serialize_scalar(scalar: Self::Scalar) -> GenericArray { - scalar.into() + let bytes: FieldBytes = scalar.into(); + let mut result = GenericArray::::default(); + result.as_mut_slice().copy_from_slice(bytes.as_ref()); + result } fn deserialize_scalar(scalar_bits: &[u8]) -> Result { diff --git a/src/group/mod.rs b/src/group/mod.rs index c51e06e..e5b3631 100644 --- a/src/group/mod.rs +++ b/src/group/mod.rs @@ -32,10 +32,10 @@ pub trait Group where // `VoprfClientLen`, `PoprfClientLen`, `VoprfServerLen`, `PoprfServerLen` Self::ScalarLen: Add, - Sum: ArrayLength, + Sum: ArrayLength, // `ProofLen` Self::ScalarLen: Add, - Sum: ArrayLength, + Sum: ArrayLength, { /// The type of group elements type Elem: ConstantTimeEq @@ -45,7 +45,7 @@ where + for<'a> Mul<&'a Self::Scalar, Output = Self::Elem>; /// The byte length necessary to represent group elements - type ElemLen: ArrayLength + 'static; + type ElemLen: ArrayLength + 'static; /// The type of base field scalars type Scalar: ConstantTimeEq @@ -56,7 +56,7 @@ where + for<'a> Sub<&'a Self::Scalar, Output = Self::Scalar>; /// The byte length necessary to represent scalars - type ScalarLen: ArrayLength + 'static; + type ScalarLen: ArrayLength + 'static; /// Transforms a password and domain separation tag (DST) into a curve point /// diff --git a/src/poprf.rs b/src/poprf.rs index 53393c4..fc7d789 100644 --- a/src/poprf.rs +++ b/src/poprf.rs @@ -15,7 +15,7 @@ use core::iter::{self, Map, Repeat, Zip}; use derive_where::derive_where; use digest::{Digest, Output, OutputSizeUser}; use generic_array::typenum::Unsigned; -use generic_array::GenericArray; +use generic_array::{ArrayLength, GenericArray}; use rand_core::{CryptoRng, RngCore}; use crate::common::{ @@ -132,7 +132,10 @@ impl PoprfClient { proof: &Proof, pk: ::Elem, info: Option<&[u8]>, - ) -> Result> { + ) -> Result> + where + <::Hash as OutputSizeUser>::OutputSize: ArrayLength, + { let clients = core::array::from_ref(self); let messages = core::array::from_ref(evaluation_element); @@ -167,6 +170,7 @@ impl PoprfClient { <&'a IC as IntoIterator>::IntoIter: ExactSizeIterator, &'a IM: 'a + IntoIterator>, <&'a IM as IntoIterator>::IntoIter: ExactSizeIterator, + <::Hash as OutputSizeUser>::OutputSize: ArrayLength, { let unblinded_elements = poprf_unblind(clients, messages, pk, proof, info)?; @@ -672,7 +676,7 @@ type FinalizeAfterUnblindResult<'a, CS, IE, II> = Map< Zip, Repeat<&'a [u8]>>, fn( ((<::Group as Group>::Elem, &[u8]), &[u8]), - ) -> Result::Hash as OutputSizeUser>::OutputSize>>, + ) -> Result::Hash>>, >; /// Can only fail with [`Error::Batch`] and returned values can only fail with @@ -686,7 +690,10 @@ fn finalize_after_unblind< unblinded_elements: IE, inputs: II, info: Option<&'a [u8]>, -) -> Result> { +) -> Result> +where + <::Hash as OutputSizeUser>::OutputSize: ArrayLength, +{ if unblinded_elements.len() != inputs.len() { return Err(Error::Batch); }