Skip to content

Commit e944f9d

Browse files
chore: update generic-array to v1 (#143)
* update generic-array to v1 * revert displaydoc removal * fix cargo fmt
1 parent f3f4fef commit e944f9d

File tree

7 files changed

+39
-29
lines changed

7 files changed

+39
-29
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ version = "0.5.0"
1515
alloc = []
1616
danger = []
1717
default = ["ristretto255-ciphersuite", "dep:serde"]
18-
ristretto255 = ["dep:curve25519-dalek", "generic-array/more_lengths"]
18+
ristretto255 = ["dep:curve25519-dalek"]
1919
ristretto255-ciphersuite = ["ristretto255", "dep:sha2"]
2020
serde = ["curve25519-dalek?/serde", "generic-array/serde", "dep:serde"]
2121
std = ["alloc"]
@@ -33,7 +33,7 @@ elliptic-curve = { version = "0.13", features = [
3333
"sec1",
3434
"voprf",
3535
] }
36-
generic-array = "0.14"
36+
generic-array = "1"
3737
rand_core = { version = "0.6", default-features = false }
3838
serde = { version = "1", default-features = false, features = [
3939
"derive",
@@ -43,7 +43,7 @@ subtle = { version = "2.3", default-features = false }
4343
zeroize = { version = "1.5", default-features = false }
4444

4545
[dev-dependencies]
46-
generic-array = { version = "0.14", features = ["more_lengths"] }
46+
generic-array = { version = "1" }
4747
hex = "0.4"
4848
p256 = { version = "0.13", default-features = false, features = [
4949
"hash2curve",

src/ciphersuite.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ use digest::core_api::BlockSizeUser;
1212
use digest::{FixedOutput, HashMarker, OutputSizeUser};
1313
use elliptic_curve::VoprfParameters;
1414
use generic_array::typenum::{IsLess, IsLessOrEqual, U256};
15+
use generic_array::ArrayLength;
1516

1617
use crate::Group;
1718

1819
/// Configures the underlying primitives used in VOPRF
1920
pub trait CipherSuite
2021
where
2122
<Self::Hash as OutputSizeUser>::OutputSize:
22-
IsLess<U256> + IsLessOrEqual<<Self::Hash as BlockSizeUser>::BlockSize>,
23+
ArrayLength + IsLess<U256> + IsLessOrEqual<<Self::Hash as BlockSizeUser>::BlockSize>,
2324
{
2425
/// The ciphersuite identifier as dictated by
2526
/// <https://www.rfc-editor.org/rfc/rfc9497>
@@ -39,7 +40,7 @@ where
3940
T: Group,
4041
T::Hash: BlockSizeUser + Default + FixedOutput + HashMarker,
4142
<T::Hash as OutputSizeUser>::OutputSize:
42-
IsLess<U256> + IsLessOrEqual<<T::Hash as BlockSizeUser>::BlockSize>,
43+
ArrayLength + IsLess<U256> + IsLessOrEqual<<T::Hash as BlockSizeUser>::BlockSize>,
4344
{
4445
const ID: &'static str = T::ID;
4546

src/common.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core::convert::TryFrom;
1212
use core::ops::Add;
1313

1414
use derive_where::derive_where;
15-
use digest::{Digest, Output};
15+
use digest::{Digest, Output, OutputSizeUser};
1616
use generic_array::sequence::Concat;
1717
use generic_array::typenum::{IsLess, Unsigned, U2, U256, U9};
1818
use generic_array::{ArrayLength, GenericArray};
@@ -283,7 +283,7 @@ fn compute_composites<
283283
.chain_update(seed_dst.i2osp_2())
284284
.chain_update_multi(&seed_dst.as_dst())
285285
.finalize();
286-
let seed_len = i2osp_2_array(&seed);
286+
let seed_len = i2osp_2_array::<<CS::Hash as OutputSizeUser>::OutputSize>();
287287

288288
let mut m = CS::Group::identity_elem();
289289
let mut z = CS::Group::identity_elem();
@@ -442,23 +442,23 @@ pub(crate) fn server_evaluate_hash_input<CS: CipherSuite>(
442442
.chain_update(info.as_ref());
443443
}
444444
Ok(hash
445-
.chain_update(i2osp_2(issued_element.as_ref().len()).map_err(|_| Error::Input)?)
445+
.chain_update(i2osp_2(issued_element.as_slice().len()).map_err(|_| Error::Input)?)
446446
.chain_update(issued_element)
447447
.chain_update(STR_FINALIZE)
448448
.finalize())
449449
}
450450

451-
pub(crate) struct Dst<L: ArrayLength<u8>> {
451+
pub(crate) struct Dst<L: ArrayLength> {
452452
dst_1: GenericArray<u8, L>,
453453
dst_2: &'static str,
454454
}
455455

456-
impl<L: ArrayLength<u8>> Dst<L> {
456+
impl<L: ArrayLength> Dst<L> {
457457
pub(crate) fn new<CS, T, TL>(par_1: T, mode: Mode) -> Self
458458
where
459459
CS: CipherSuite,
460460
T: Into<GenericArray<u8, TL>>,
461-
TL: ArrayLength<u8> + Add<U9, Output = L>,
461+
TL: ArrayLength + Add<U9, Output = L>,
462462
{
463463
let par_1 = par_1.into();
464464
// Generates the contextString parameter as defined in
@@ -518,8 +518,6 @@ pub(crate) fn i2osp_2(input: usize) -> Result<[u8; 2], InternalError> {
518518
.map_err(|_| InternalError::I2osp)
519519
}
520520

521-
pub(crate) fn i2osp_2_array<L: ArrayLength<u8> + IsLess<U256>>(
522-
_: &GenericArray<u8, L>,
523-
) -> GenericArray<u8, U2> {
521+
pub(crate) fn i2osp_2_array<L: ArrayLength + IsLess<U256>>() -> GenericArray<u8, U2> {
524522
L::U16.to_be_bytes().into()
525523
}

src/error.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88

99
//! Errors which are produced during an execution of the protocol
1010
11-
use displaydoc::Display;
12-
1311
/// [`Result`](core::result::Result) shorthand that uses [`Error`].
1412
pub type Result<T, E = Error> = core::result::Result<T, E>;
1513

1614
/// Represents an error in the manipulation of internal cryptographic data
17-
#[derive(Clone, Copy, Debug, Display, Eq, Hash, Ord, PartialEq, PartialOrd)]
15+
#[derive(Clone, Copy, Debug, displaydoc::Display, Eq, Hash, Ord, PartialEq, PartialOrd)]
1816
pub enum Error {
1917
/// Size of info is longer then [`u16::MAX`].
2018
Info,

src/group/elliptic_curve.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use elliptic_curve::group::cofactor::CofactorGroup;
1414
use elliptic_curve::hash2curve::{ExpandMsgXmd, FromOkm, GroupDigest};
1515
use elliptic_curve::sec1::{FromEncodedPoint, ModulusSize, ToEncodedPoint};
1616
use elliptic_curve::{
17-
AffinePoint, Field, FieldBytesSize, Group as _, ProjectivePoint, PublicKey, Scalar, SecretKey,
17+
AffinePoint, Field, FieldBytes, FieldBytesSize, Group as _, ProjectivePoint, PublicKey, Scalar,
18+
SecretKey,
1819
};
1920
use generic_array::typenum::{IsLess, IsLessOrEqual, Sum, U256};
2021
use generic_array::{ArrayLength, GenericArray};
@@ -31,14 +32,16 @@ where
3132
C: GroupDigest,
3233
ProjectivePoint<Self>: CofactorGroup + ToEncodedPoint<Self>,
3334
ScalarLen<Self>: ModulusSize,
35+
ScalarLen<Self>: ArrayLength,
3436
AffinePoint<Self>: FromEncodedPoint<Self> + ToEncodedPoint<Self>,
3537
Scalar<Self>: FromOkm,
3638
// `VoprfClientLen`, `PoprfClientLen`, `VoprfServerLen`, `PoprfServerLen`
3739
ScalarLen<Self>: Add<ElemLen<Self>>,
38-
Sum<ScalarLen<Self>, ElemLen<Self>>: ArrayLength<u8>,
40+
Sum<ScalarLen<Self>, ElemLen<Self>>: ArrayLength,
3941
// `ProofLen`
4042
ScalarLen<Self>: Add<ScalarLen<Self>>,
41-
Sum<ScalarLen<Self>, ScalarLen<Self>>: ArrayLength<u8>,
43+
Sum<ScalarLen<Self>, ScalarLen<Self>>: ArrayLength,
44+
ElemLen<Self>: ArrayLength,
4245
{
4346
type Elem = ProjectivePoint<Self>;
4447

@@ -108,7 +111,10 @@ where
108111
}
109112

110113
fn serialize_scalar(scalar: Self::Scalar) -> GenericArray<u8, Self::ScalarLen> {
111-
scalar.into()
114+
let bytes: FieldBytes<Self> = scalar.into();
115+
let mut result = GenericArray::<u8, Self::ScalarLen>::default();
116+
result.as_mut_slice().copy_from_slice(bytes.as_ref());
117+
result
112118
}
113119

114120
fn deserialize_scalar(scalar_bits: &[u8]) -> Result<Self::Scalar> {

src/group/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ pub trait Group
3232
where
3333
// `VoprfClientLen`, `PoprfClientLen`, `VoprfServerLen`, `PoprfServerLen`
3434
Self::ScalarLen: Add<Self::ElemLen>,
35-
Sum<Self::ScalarLen, Self::ElemLen>: ArrayLength<u8>,
35+
Sum<Self::ScalarLen, Self::ElemLen>: ArrayLength,
3636
// `ProofLen`
3737
Self::ScalarLen: Add<Self::ScalarLen>,
38-
Sum<Self::ScalarLen, Self::ScalarLen>: ArrayLength<u8>,
38+
Sum<Self::ScalarLen, Self::ScalarLen>: ArrayLength,
3939
{
4040
/// The type of group elements
4141
type Elem: ConstantTimeEq
@@ -45,7 +45,7 @@ where
4545
+ for<'a> Mul<&'a Self::Scalar, Output = Self::Elem>;
4646

4747
/// The byte length necessary to represent group elements
48-
type ElemLen: ArrayLength<u8> + 'static;
48+
type ElemLen: ArrayLength + 'static;
4949

5050
/// The type of base field scalars
5151
type Scalar: ConstantTimeEq
@@ -56,7 +56,7 @@ where
5656
+ for<'a> Sub<&'a Self::Scalar, Output = Self::Scalar>;
5757

5858
/// The byte length necessary to represent scalars
59-
type ScalarLen: ArrayLength<u8> + 'static;
59+
type ScalarLen: ArrayLength + 'static;
6060

6161
/// Transforms a password and domain separation tag (DST) into a curve point
6262
///

src/poprf.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use core::iter::{self, Map, Repeat, Zip};
1515
use derive_where::derive_where;
1616
use digest::{Digest, Output, OutputSizeUser};
1717
use generic_array::typenum::Unsigned;
18-
use generic_array::GenericArray;
18+
use generic_array::{ArrayLength, GenericArray};
1919
use rand_core::{CryptoRng, RngCore};
2020

2121
use crate::common::{
@@ -132,7 +132,10 @@ impl<CS: CipherSuite> PoprfClient<CS> {
132132
proof: &Proof<CS>,
133133
pk: <CS::Group as Group>::Elem,
134134
info: Option<&[u8]>,
135-
) -> Result<Output<CS::Hash>> {
135+
) -> Result<Output<CS::Hash>>
136+
where
137+
<<CS as CipherSuite>::Hash as OutputSizeUser>::OutputSize: ArrayLength,
138+
{
136139
let clients = core::array::from_ref(self);
137140
let messages = core::array::from_ref(evaluation_element);
138141

@@ -167,6 +170,7 @@ impl<CS: CipherSuite> PoprfClient<CS> {
167170
<&'a IC as IntoIterator>::IntoIter: ExactSizeIterator,
168171
&'a IM: 'a + IntoIterator<Item = &'a EvaluationElement<CS>>,
169172
<&'a IM as IntoIterator>::IntoIter: ExactSizeIterator,
173+
<<CS as CipherSuite>::Hash as OutputSizeUser>::OutputSize: ArrayLength,
170174
{
171175
let unblinded_elements = poprf_unblind(clients, messages, pk, proof, info)?;
172176

@@ -672,7 +676,7 @@ type FinalizeAfterUnblindResult<'a, CS, IE, II> = Map<
672676
Zip<Zip<IE, II>, Repeat<&'a [u8]>>,
673677
fn(
674678
((<<CS as CipherSuite>::Group as Group>::Elem, &[u8]), &[u8]),
675-
) -> Result<GenericArray<u8, <<CS as CipherSuite>::Hash as OutputSizeUser>::OutputSize>>,
679+
) -> Result<Output<<CS as CipherSuite>::Hash>>,
676680
>;
677681

678682
/// Can only fail with [`Error::Batch`] and returned values can only fail with
@@ -686,7 +690,10 @@ fn finalize_after_unblind<
686690
unblinded_elements: IE,
687691
inputs: II,
688692
info: Option<&'a [u8]>,
689-
) -> Result<FinalizeAfterUnblindResult<'a, CS, IE, II>> {
693+
) -> Result<FinalizeAfterUnblindResult<'a, CS, IE, II>>
694+
where
695+
<<CS as CipherSuite>::Hash as OutputSizeUser>::OutputSize: ArrayLength,
696+
{
690697
if unblinded_elements.len() != inputs.len() {
691698
return Err(Error::Batch);
692699
}

0 commit comments

Comments
 (0)