chore: update generic-array to v1 (#143)
* update generic-array to v1 * revert displaydoc removal * fix cargo fmt
This commit is contained in:
+3
-3
@@ -15,7 +15,7 @@ version = "0.5.0"
|
|||||||
alloc = []
|
alloc = []
|
||||||
danger = []
|
danger = []
|
||||||
default = ["ristretto255-ciphersuite", "dep:serde"]
|
default = ["ristretto255-ciphersuite", "dep:serde"]
|
||||||
ristretto255 = ["dep:curve25519-dalek", "generic-array/more_lengths"]
|
ristretto255 = ["dep:curve25519-dalek"]
|
||||||
ristretto255-ciphersuite = ["ristretto255", "dep:sha2"]
|
ristretto255-ciphersuite = ["ristretto255", "dep:sha2"]
|
||||||
serde = ["curve25519-dalek?/serde", "generic-array/serde", "dep:serde"]
|
serde = ["curve25519-dalek?/serde", "generic-array/serde", "dep:serde"]
|
||||||
std = ["alloc"]
|
std = ["alloc"]
|
||||||
@@ -33,7 +33,7 @@ elliptic-curve = { version = "0.13", features = [
|
|||||||
"sec1",
|
"sec1",
|
||||||
"voprf",
|
"voprf",
|
||||||
] }
|
] }
|
||||||
generic-array = "0.14"
|
generic-array = "1"
|
||||||
rand_core = { version = "0.6", default-features = false }
|
rand_core = { version = "0.6", default-features = false }
|
||||||
serde = { version = "1", default-features = false, features = [
|
serde = { version = "1", default-features = false, features = [
|
||||||
"derive",
|
"derive",
|
||||||
@@ -43,7 +43,7 @@ subtle = { version = "2.3", default-features = false }
|
|||||||
zeroize = { version = "1.5", default-features = false }
|
zeroize = { version = "1.5", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
generic-array = { version = "0.14", features = ["more_lengths"] }
|
generic-array = { version = "1" }
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
p256 = { version = "0.13", default-features = false, features = [
|
p256 = { version = "0.13", default-features = false, features = [
|
||||||
"hash2curve",
|
"hash2curve",
|
||||||
|
|||||||
+3
-2
@@ -12,6 +12,7 @@ use digest::core_api::BlockSizeUser;
|
|||||||
use digest::{FixedOutput, HashMarker, OutputSizeUser};
|
use digest::{FixedOutput, HashMarker, OutputSizeUser};
|
||||||
use elliptic_curve::VoprfParameters;
|
use elliptic_curve::VoprfParameters;
|
||||||
use generic_array::typenum::{IsLess, IsLessOrEqual, U256};
|
use generic_array::typenum::{IsLess, IsLessOrEqual, U256};
|
||||||
|
use generic_array::ArrayLength;
|
||||||
|
|
||||||
use crate::Group;
|
use crate::Group;
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ use crate::Group;
|
|||||||
pub trait CipherSuite
|
pub trait CipherSuite
|
||||||
where
|
where
|
||||||
<Self::Hash as OutputSizeUser>::OutputSize:
|
<Self::Hash as OutputSizeUser>::OutputSize:
|
||||||
IsLess<U256> + IsLessOrEqual<<Self::Hash as BlockSizeUser>::BlockSize>,
|
ArrayLength + IsLess<U256> + IsLessOrEqual<<Self::Hash as BlockSizeUser>::BlockSize>,
|
||||||
{
|
{
|
||||||
/// The ciphersuite identifier as dictated by
|
/// The ciphersuite identifier as dictated by
|
||||||
/// <https://www.rfc-editor.org/rfc/rfc9497>
|
/// <https://www.rfc-editor.org/rfc/rfc9497>
|
||||||
@@ -39,7 +40,7 @@ where
|
|||||||
T: Group,
|
T: Group,
|
||||||
T::Hash: BlockSizeUser + Default + FixedOutput + HashMarker,
|
T::Hash: BlockSizeUser + Default + FixedOutput + HashMarker,
|
||||||
<T::Hash as OutputSizeUser>::OutputSize:
|
<T::Hash as OutputSizeUser>::OutputSize:
|
||||||
IsLess<U256> + IsLessOrEqual<<T::Hash as BlockSizeUser>::BlockSize>,
|
ArrayLength + IsLess<U256> + IsLessOrEqual<<T::Hash as BlockSizeUser>::BlockSize>,
|
||||||
{
|
{
|
||||||
const ID: &'static str = T::ID;
|
const ID: &'static str = T::ID;
|
||||||
|
|
||||||
|
|||||||
+7
-9
@@ -12,7 +12,7 @@ use core::convert::TryFrom;
|
|||||||
use core::ops::Add;
|
use core::ops::Add;
|
||||||
|
|
||||||
use derive_where::derive_where;
|
use derive_where::derive_where;
|
||||||
use digest::{Digest, Output};
|
use digest::{Digest, Output, OutputSizeUser};
|
||||||
use generic_array::sequence::Concat;
|
use generic_array::sequence::Concat;
|
||||||
use generic_array::typenum::{IsLess, Unsigned, U2, U256, U9};
|
use generic_array::typenum::{IsLess, Unsigned, U2, U256, U9};
|
||||||
use generic_array::{ArrayLength, GenericArray};
|
use generic_array::{ArrayLength, GenericArray};
|
||||||
@@ -283,7 +283,7 @@ fn compute_composites<
|
|||||||
.chain_update(seed_dst.i2osp_2())
|
.chain_update(seed_dst.i2osp_2())
|
||||||
.chain_update_multi(&seed_dst.as_dst())
|
.chain_update_multi(&seed_dst.as_dst())
|
||||||
.finalize();
|
.finalize();
|
||||||
let seed_len = i2osp_2_array(&seed);
|
let seed_len = i2osp_2_array::<<CS::Hash as OutputSizeUser>::OutputSize>();
|
||||||
|
|
||||||
let mut m = CS::Group::identity_elem();
|
let mut m = CS::Group::identity_elem();
|
||||||
let mut z = CS::Group::identity_elem();
|
let mut z = CS::Group::identity_elem();
|
||||||
@@ -442,23 +442,23 @@ pub(crate) fn server_evaluate_hash_input<CS: CipherSuite>(
|
|||||||
.chain_update(info.as_ref());
|
.chain_update(info.as_ref());
|
||||||
}
|
}
|
||||||
Ok(hash
|
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(issued_element)
|
||||||
.chain_update(STR_FINALIZE)
|
.chain_update(STR_FINALIZE)
|
||||||
.finalize())
|
.finalize())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct Dst<L: ArrayLength<u8>> {
|
pub(crate) struct Dst<L: ArrayLength> {
|
||||||
dst_1: GenericArray<u8, L>,
|
dst_1: GenericArray<u8, L>,
|
||||||
dst_2: &'static str,
|
dst_2: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: ArrayLength<u8>> Dst<L> {
|
impl<L: ArrayLength> Dst<L> {
|
||||||
pub(crate) fn new<CS, T, TL>(par_1: T, mode: Mode) -> Self
|
pub(crate) fn new<CS, T, TL>(par_1: T, mode: Mode) -> Self
|
||||||
where
|
where
|
||||||
CS: CipherSuite,
|
CS: CipherSuite,
|
||||||
T: Into<GenericArray<u8, TL>>,
|
T: Into<GenericArray<u8, TL>>,
|
||||||
TL: ArrayLength<u8> + Add<U9, Output = L>,
|
TL: ArrayLength + Add<U9, Output = L>,
|
||||||
{
|
{
|
||||||
let par_1 = par_1.into();
|
let par_1 = par_1.into();
|
||||||
// Generates the contextString parameter as defined in
|
// 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)
|
.map_err(|_| InternalError::I2osp)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn i2osp_2_array<L: ArrayLength<u8> + IsLess<U256>>(
|
pub(crate) fn i2osp_2_array<L: ArrayLength + IsLess<U256>>() -> GenericArray<u8, U2> {
|
||||||
_: &GenericArray<u8, L>,
|
|
||||||
) -> GenericArray<u8, U2> {
|
|
||||||
L::U16.to_be_bytes().into()
|
L::U16.to_be_bytes().into()
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -8,13 +8,11 @@
|
|||||||
|
|
||||||
//! Errors which are produced during an execution of the protocol
|
//! Errors which are produced during an execution of the protocol
|
||||||
|
|
||||||
use displaydoc::Display;
|
|
||||||
|
|
||||||
/// [`Result`](core::result::Result) shorthand that uses [`Error`].
|
/// [`Result`](core::result::Result) shorthand that uses [`Error`].
|
||||||
pub type Result<T, E = Error> = core::result::Result<T, E>;
|
pub type Result<T, E = Error> = core::result::Result<T, E>;
|
||||||
|
|
||||||
/// Represents an error in the manipulation of internal cryptographic data
|
/// 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 {
|
pub enum Error {
|
||||||
/// Size of info is longer then [`u16::MAX`].
|
/// Size of info is longer then [`u16::MAX`].
|
||||||
Info,
|
Info,
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ use elliptic_curve::group::cofactor::CofactorGroup;
|
|||||||
use elliptic_curve::hash2curve::{ExpandMsgXmd, FromOkm, GroupDigest};
|
use elliptic_curve::hash2curve::{ExpandMsgXmd, FromOkm, GroupDigest};
|
||||||
use elliptic_curve::sec1::{FromEncodedPoint, ModulusSize, ToEncodedPoint};
|
use elliptic_curve::sec1::{FromEncodedPoint, ModulusSize, ToEncodedPoint};
|
||||||
use elliptic_curve::{
|
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::typenum::{IsLess, IsLessOrEqual, Sum, U256};
|
||||||
use generic_array::{ArrayLength, GenericArray};
|
use generic_array::{ArrayLength, GenericArray};
|
||||||
@@ -31,14 +32,16 @@ where
|
|||||||
C: GroupDigest,
|
C: GroupDigest,
|
||||||
ProjectivePoint<Self>: CofactorGroup + ToEncodedPoint<Self>,
|
ProjectivePoint<Self>: CofactorGroup + ToEncodedPoint<Self>,
|
||||||
ScalarLen<Self>: ModulusSize,
|
ScalarLen<Self>: ModulusSize,
|
||||||
|
ScalarLen<Self>: ArrayLength,
|
||||||
AffinePoint<Self>: FromEncodedPoint<Self> + ToEncodedPoint<Self>,
|
AffinePoint<Self>: FromEncodedPoint<Self> + ToEncodedPoint<Self>,
|
||||||
Scalar<Self>: FromOkm,
|
Scalar<Self>: FromOkm,
|
||||||
// `VoprfClientLen`, `PoprfClientLen`, `VoprfServerLen`, `PoprfServerLen`
|
// `VoprfClientLen`, `PoprfClientLen`, `VoprfServerLen`, `PoprfServerLen`
|
||||||
ScalarLen<Self>: Add<ElemLen<Self>>,
|
ScalarLen<Self>: Add<ElemLen<Self>>,
|
||||||
Sum<ScalarLen<Self>, ElemLen<Self>>: ArrayLength<u8>,
|
Sum<ScalarLen<Self>, ElemLen<Self>>: ArrayLength,
|
||||||
// `ProofLen`
|
// `ProofLen`
|
||||||
ScalarLen<Self>: Add<ScalarLen<Self>>,
|
ScalarLen<Self>: Add<ScalarLen<Self>>,
|
||||||
Sum<ScalarLen<Self>, ScalarLen<Self>>: ArrayLength<u8>,
|
Sum<ScalarLen<Self>, ScalarLen<Self>>: ArrayLength,
|
||||||
|
ElemLen<Self>: ArrayLength,
|
||||||
{
|
{
|
||||||
type Elem = ProjectivePoint<Self>;
|
type Elem = ProjectivePoint<Self>;
|
||||||
|
|
||||||
@@ -108,7 +111,10 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_scalar(scalar: Self::Scalar) -> GenericArray<u8, Self::ScalarLen> {
|
fn serialize_scalar(scalar: Self::Scalar) -> GenericArray<u8, Self::ScalarLen> {
|
||||||
scalar.into()
|
let bytes: FieldBytes<Self> = scalar.into();
|
||||||
|
let mut result = GenericArray::<u8, Self::ScalarLen>::default();
|
||||||
|
result.as_mut_slice().copy_from_slice(bytes.as_ref());
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_scalar(scalar_bits: &[u8]) -> Result<Self::Scalar> {
|
fn deserialize_scalar(scalar_bits: &[u8]) -> Result<Self::Scalar> {
|
||||||
|
|||||||
+4
-4
@@ -32,10 +32,10 @@ pub trait Group
|
|||||||
where
|
where
|
||||||
// `VoprfClientLen`, `PoprfClientLen`, `VoprfServerLen`, `PoprfServerLen`
|
// `VoprfClientLen`, `PoprfClientLen`, `VoprfServerLen`, `PoprfServerLen`
|
||||||
Self::ScalarLen: Add<Self::ElemLen>,
|
Self::ScalarLen: Add<Self::ElemLen>,
|
||||||
Sum<Self::ScalarLen, Self::ElemLen>: ArrayLength<u8>,
|
Sum<Self::ScalarLen, Self::ElemLen>: ArrayLength,
|
||||||
// `ProofLen`
|
// `ProofLen`
|
||||||
Self::ScalarLen: Add<Self::ScalarLen>,
|
Self::ScalarLen: Add<Self::ScalarLen>,
|
||||||
Sum<Self::ScalarLen, Self::ScalarLen>: ArrayLength<u8>,
|
Sum<Self::ScalarLen, Self::ScalarLen>: ArrayLength,
|
||||||
{
|
{
|
||||||
/// The type of group elements
|
/// The type of group elements
|
||||||
type Elem: ConstantTimeEq
|
type Elem: ConstantTimeEq
|
||||||
@@ -45,7 +45,7 @@ where
|
|||||||
+ for<'a> Mul<&'a Self::Scalar, Output = Self::Elem>;
|
+ for<'a> Mul<&'a Self::Scalar, Output = Self::Elem>;
|
||||||
|
|
||||||
/// The byte length necessary to represent group elements
|
/// The byte length necessary to represent group elements
|
||||||
type ElemLen: ArrayLength<u8> + 'static;
|
type ElemLen: ArrayLength + 'static;
|
||||||
|
|
||||||
/// The type of base field scalars
|
/// The type of base field scalars
|
||||||
type Scalar: ConstantTimeEq
|
type Scalar: ConstantTimeEq
|
||||||
@@ -56,7 +56,7 @@ where
|
|||||||
+ for<'a> Sub<&'a Self::Scalar, Output = Self::Scalar>;
|
+ for<'a> Sub<&'a Self::Scalar, Output = Self::Scalar>;
|
||||||
|
|
||||||
/// The byte length necessary to represent scalars
|
/// The byte length necessary to represent scalars
|
||||||
type ScalarLen: ArrayLength<u8> + 'static;
|
type ScalarLen: ArrayLength + 'static;
|
||||||
|
|
||||||
/// Transforms a password and domain separation tag (DST) into a curve point
|
/// Transforms a password and domain separation tag (DST) into a curve point
|
||||||
///
|
///
|
||||||
|
|||||||
+11
-4
@@ -15,7 +15,7 @@ use core::iter::{self, Map, Repeat, Zip};
|
|||||||
use derive_where::derive_where;
|
use derive_where::derive_where;
|
||||||
use digest::{Digest, Output, OutputSizeUser};
|
use digest::{Digest, Output, OutputSizeUser};
|
||||||
use generic_array::typenum::Unsigned;
|
use generic_array::typenum::Unsigned;
|
||||||
use generic_array::GenericArray;
|
use generic_array::{ArrayLength, GenericArray};
|
||||||
use rand_core::{CryptoRng, RngCore};
|
use rand_core::{CryptoRng, RngCore};
|
||||||
|
|
||||||
use crate::common::{
|
use crate::common::{
|
||||||
@@ -132,7 +132,10 @@ impl<CS: CipherSuite> PoprfClient<CS> {
|
|||||||
proof: &Proof<CS>,
|
proof: &Proof<CS>,
|
||||||
pk: <CS::Group as Group>::Elem,
|
pk: <CS::Group as Group>::Elem,
|
||||||
info: Option<&[u8]>,
|
info: Option<&[u8]>,
|
||||||
) -> Result<Output<CS::Hash>> {
|
) -> Result<Output<CS::Hash>>
|
||||||
|
where
|
||||||
|
<<CS as CipherSuite>::Hash as OutputSizeUser>::OutputSize: ArrayLength,
|
||||||
|
{
|
||||||
let clients = core::array::from_ref(self);
|
let clients = core::array::from_ref(self);
|
||||||
let messages = core::array::from_ref(evaluation_element);
|
let messages = core::array::from_ref(evaluation_element);
|
||||||
|
|
||||||
@@ -167,6 +170,7 @@ impl<CS: CipherSuite> PoprfClient<CS> {
|
|||||||
<&'a IC as IntoIterator>::IntoIter: ExactSizeIterator,
|
<&'a IC as IntoIterator>::IntoIter: ExactSizeIterator,
|
||||||
&'a IM: 'a + IntoIterator<Item = &'a EvaluationElement<CS>>,
|
&'a IM: 'a + IntoIterator<Item = &'a EvaluationElement<CS>>,
|
||||||
<&'a IM as IntoIterator>::IntoIter: ExactSizeIterator,
|
<&'a IM as IntoIterator>::IntoIter: ExactSizeIterator,
|
||||||
|
<<CS as CipherSuite>::Hash as OutputSizeUser>::OutputSize: ArrayLength,
|
||||||
{
|
{
|
||||||
let unblinded_elements = poprf_unblind(clients, messages, pk, proof, info)?;
|
let unblinded_elements = poprf_unblind(clients, messages, pk, proof, info)?;
|
||||||
|
|
||||||
@@ -672,7 +676,7 @@ type FinalizeAfterUnblindResult<'a, CS, IE, II> = Map<
|
|||||||
Zip<Zip<IE, II>, Repeat<&'a [u8]>>,
|
Zip<Zip<IE, II>, Repeat<&'a [u8]>>,
|
||||||
fn(
|
fn(
|
||||||
((<<CS as CipherSuite>::Group as Group>::Elem, &[u8]), &[u8]),
|
((<<CS as CipherSuite>::Group as Group>::Elem, &[u8]), &[u8]),
|
||||||
) -> Result<GenericArray<u8, <<CS as CipherSuite>::Hash as OutputSizeUser>::OutputSize>>,
|
) -> Result<Output<<CS as CipherSuite>::Hash>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Can only fail with [`Error::Batch`] and returned values can only fail with
|
/// Can only fail with [`Error::Batch`] and returned values can only fail with
|
||||||
@@ -686,7 +690,10 @@ fn finalize_after_unblind<
|
|||||||
unblinded_elements: IE,
|
unblinded_elements: IE,
|
||||||
inputs: II,
|
inputs: II,
|
||||||
info: Option<&'a [u8]>,
|
info: Option<&'a [u8]>,
|
||||||
) -> Result<FinalizeAfterUnblindResult<'a, CS, IE, II>> {
|
) -> Result<FinalizeAfterUnblindResult<'a, CS, IE, II>>
|
||||||
|
where
|
||||||
|
<<CS as CipherSuite>::Hash as OutputSizeUser>::OutputSize: ArrayLength,
|
||||||
|
{
|
||||||
if unblinded_elements.len() != inputs.len() {
|
if unblinded_elements.len() != inputs.len() {
|
||||||
return Err(Error::Batch);
|
return Err(Error::Batch);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user