Skip to content

Commit 4a0553a

Browse files
committed
use primitive array instead of hybrid_array::Array
1 parent 6f022b9 commit 4a0553a

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

hash2curve/src/group_digest.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Traits for handling hash to curve.
22
33
use super::{ExpandMsg, MapToCurve, hash_to_field};
4-
use digest::consts::{U1, U2};
54
use elliptic_curve::array::typenum::Unsigned;
65
use elliptic_curve::{ProjectivePoint, Result};
76

@@ -37,9 +36,9 @@ pub trait GroupDigest: MapToCurve {
3736
where
3837
X: ExpandMsg<Self::K>,
3938
{
40-
let u = hash_to_field::<X, _, Self::FieldElement, U2>(msg, dst)?;
41-
let q0 = Self::map_to_curve(u[0]);
42-
let q1 = Self::map_to_curve(u[1]);
39+
let [u0, u1] = hash_to_field::<2, X, _, Self::FieldElement>(msg, dst)?;
40+
let q0 = Self::map_to_curve(u0);
41+
let q1 = Self::map_to_curve(u1);
4342
Ok(Self::add_and_map_to_subgroup(q0, q1))
4443
}
4544

@@ -67,8 +66,8 @@ pub trait GroupDigest: MapToCurve {
6766
where
6867
X: ExpandMsg<Self::K>,
6968
{
70-
let u = hash_to_field::<X, _, Self::FieldElement, U1>(msg, dst)?;
71-
let q0 = Self::map_to_curve(u[0]);
69+
let [u] = hash_to_field::<1, X, _, Self::FieldElement>(msg, dst)?;
70+
let q0 = Self::map_to_curve(u);
7271
Ok(Self::map_to_subgroup(q0))
7372
}
7473

@@ -90,7 +89,7 @@ pub trait GroupDigest: MapToCurve {
9089
where
9190
X: ExpandMsg<Self::K>,
9291
{
93-
let u = hash_to_field::<X, _, Self::Scalar, U1>(msg, dst)?;
94-
Ok(u[0])
92+
let [u] = hash_to_field::<1, X, _, Self::Scalar>(msg, dst)?;
93+
Ok(u)
9594
}
9695
}

hash2curve/src/hash2field.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,20 @@ pub trait FromOkm {
3838
/// [`ExpandMsgXmd`]: crate::hash2field::ExpandMsgXmd
3939
/// [`ExpandMsgXof`]: crate::hash2field::ExpandMsgXof
4040
#[doc(hidden)]
41-
pub fn hash_to_field<E, K, T, C>(data: &[&[u8]], domain: &[&[u8]]) -> Result<Array<T, C>>
41+
pub fn hash_to_field<const N: usize, E, K, T>(data: &[&[u8]], domain: &[&[u8]]) -> Result<[T; N]>
4242
where
4343
E: ExpandMsg<K>,
4444
T: FromOkm + Default,
45-
C: ArraySize,
4645
{
4746
let len_in_bytes = T::Length::USIZE
48-
.checked_mul(C::USIZE)
47+
.checked_mul(N)
4948
.and_then(|len| len.try_into().ok())
5049
.and_then(NonZeroU16::new)
5150
.ok_or(Error)?;
5251
let mut tmp = Array::<u8, <T as FromOkm>::Length>::default();
5352
let mut expander = E::expand_message(data, domain, len_in_bytes)?;
54-
let mut out = Array::<T, C>::default();
55-
for o in out.iter_mut() {
53+
Ok(core::array::from_fn(|_| {
5654
expander.fill_bytes(&mut tmp);
57-
*o = T::from_okm(&tmp);
58-
}
59-
Ok(out)
55+
T::from_okm(&tmp)
56+
}))
6057
}

0 commit comments

Comments
 (0)