Skip to content

Commit c530a53

Browse files
committed
Move ExpandMsg lifetime to expander
1 parent c5b8215 commit c530a53

6 files changed

Lines changed: 26 additions & 30 deletions

File tree

elliptic-curve/src/hash2curve/group_digest.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ pub trait GroupDigest: CurveArithmetic<ProjectivePoint: CofactorGroup, Scalar: F
3535
///
3636
/// [`ExpandMsgXmd`]: crate::hash2curve::ExpandMsgXmd
3737
/// [`ExpandMsgXof`]: crate::hash2curve::ExpandMsgXof
38-
fn hash_from_bytes<'a, X>(msg: &[&[u8]], dst: &'a [&'a [u8]]) -> Result<ProjectivePoint<Self>>
38+
fn hash_from_bytes<X>(msg: &[&[u8]], dst: &[&[u8]]) -> Result<ProjectivePoint<Self>>
3939
where
40-
X: ExpandMsg<'a, Self::K>,
40+
X: ExpandMsg<Self::K>,
4141
{
4242
let mut u = [Self::FieldElement::default(), Self::FieldElement::default()];
4343
hash_to_field::<X, _, _>(msg, dst, &mut u)?;
@@ -75,9 +75,9 @@ pub trait GroupDigest: CurveArithmetic<ProjectivePoint: CofactorGroup, Scalar: F
7575
///
7676
/// [`ExpandMsgXmd`]: crate::hash2curve::ExpandMsgXmd
7777
/// [`ExpandMsgXof`]: crate::hash2curve::ExpandMsgXof
78-
fn encode_from_bytes<'a, X>(msg: &[&[u8]], dst: &'a [&'a [u8]]) -> Result<ProjectivePoint<Self>>
78+
fn encode_from_bytes<X>(msg: &[&[u8]], dst: &[&[u8]]) -> Result<ProjectivePoint<Self>>
7979
where
80-
X: ExpandMsg<'a, Self::K>,
80+
X: ExpandMsg<Self::K>,
8181
{
8282
let mut u = [Self::FieldElement::default()];
8383
hash_to_field::<X, _, _>(msg, dst, &mut u)?;
@@ -98,9 +98,9 @@ pub trait GroupDigest: CurveArithmetic<ProjectivePoint: CofactorGroup, Scalar: F
9898
///
9999
/// [`ExpandMsgXmd`]: crate::hash2curve::ExpandMsgXmd
100100
/// [`ExpandMsgXof`]: crate::hash2curve::ExpandMsgXof
101-
fn hash_to_scalar<'a, X>(msg: &[&[u8]], dst: &'a [&'a [u8]]) -> Result<Self::Scalar>
101+
fn hash_to_scalar<X>(msg: &[&[u8]], dst: &[&[u8]]) -> Result<Self::Scalar>
102102
where
103-
X: ExpandMsg<'a, Self::K>,
103+
X: ExpandMsg<Self::K>,
104104
{
105105
let mut u = [Self::Scalar::default()];
106106
hash_to_field::<X, _, _>(msg, dst, &mut u)?;

elliptic-curve/src/hash2curve/hash2field.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@ pub trait FromOkm {
3737
/// [`ExpandMsgXmd`]: crate::hash2field::ExpandMsgXmd
3838
/// [`ExpandMsgXof`]: crate::hash2field::ExpandMsgXof
3939
#[doc(hidden)]
40-
pub fn hash_to_field<'a, E, K, T>(
41-
data: &[&[u8]],
42-
domain: &'a [&'a [u8]],
43-
out: &mut [T],
44-
) -> Result<()>
40+
pub fn hash_to_field<E, K, T>(data: &[&[u8]], domain: &[&[u8]], out: &mut [T]) -> Result<()>
4541
where
46-
E: ExpandMsg<'a, K>,
42+
E: ExpandMsg<K>,
4743
T: FromOkm + Default,
4844
{
4945
let len_in_bytes = T::Length::to_usize()

elliptic-curve/src/hash2curve/hash2field/expand_msg.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ const MAX_DST_LEN: usize = 255;
2323
///
2424
/// # Errors
2525
/// See implementors of [`ExpandMsg`] for errors.
26-
pub trait ExpandMsg<'a, K> {
26+
pub trait ExpandMsg<K> {
2727
/// Type holding data for the [`Expander`].
28-
type Expander: Expander + Sized;
28+
type Expander<'dst>: Expander + Sized;
2929

3030
/// Expands `msg` to the required number of bytes.
3131
///
3232
/// Returns an expander that can be used to call `read` until enough
3333
/// bytes have been consumed
34-
fn expand_message(
34+
fn expand_message<'dst>(
3535
msg: &[&[u8]],
36-
dst: &'a [&'a [u8]],
36+
dst: &'dst [&[u8]],
3737
len_in_bytes: NonZero<usize>,
38-
) -> Result<Self::Expander>;
38+
) -> Result<Self::Expander<'dst>>;
3939
}
4040

4141
/// Expander that, call `read` until enough bytes have been consumed.

elliptic-curve/src/hash2curve/hash2field/expand_msg/xmd.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ where
2727
HashT::OutputSize: IsLess<U256, Output = True>,
2828
HashT::OutputSize: IsLessOrEqual<HashT::BlockSize, Output = True>;
2929

30-
impl<'a, HashT, K> ExpandMsg<'a, K> for ExpandMsgXmd<HashT>
30+
impl<HashT, K> ExpandMsg<K> for ExpandMsgXmd<HashT>
3131
where
3232
HashT: BlockSizeUser + Default + FixedOutput + HashMarker,
3333
// If DST is larger than 255 bytes, the length of the computed DST will depend on the output
@@ -42,13 +42,13 @@ where
4242
K: Mul<U2>,
4343
HashT::OutputSize: IsGreaterOrEqual<Prod<K, U2>, Output = True>,
4444
{
45-
type Expander = ExpanderXmd<'a, HashT>;
45+
type Expander<'dst> = ExpanderXmd<'dst, HashT>;
4646

47-
fn expand_message(
47+
fn expand_message<'dst>(
4848
msg: &[&[u8]],
49-
dst: &'a [&'a [u8]],
49+
dst: &'dst [&[u8]],
5050
len_in_bytes: NonZero<usize>,
51-
) -> Result<Self::Expander> {
51+
) -> Result<Self::Expander<'dst>> {
5252
let len_in_bytes_u16 = u16::try_from(len_in_bytes.get()).map_err(|_| Error)?;
5353

5454
// `255 * <b_in_bytes>` can not exceed `u16::MAX`
@@ -221,7 +221,7 @@ mod test {
221221
assert_message::<HashT>(self.msg, domain, L::to_u16(), self.msg_prime);
222222

223223
let dst = [dst];
224-
let mut expander = <ExpandMsgXmd<HashT> as ExpandMsg<'_, U4>>::expand_message(
224+
let mut expander = <ExpandMsgXmd<HashT> as ExpandMsg<U4>>::expand_message(
225225
&[self.msg],
226226
&dst,
227227
NonZero::new(L::to_usize()).ok_or(Error)?,

elliptic-curve/src/hash2curve/hash2field/expand_msg/xof.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ where
3434
}
3535
}
3636

37-
impl<'a, HashT, K> ExpandMsg<'a, K> for ExpandMsgXof<HashT>
37+
impl<HashT, K> ExpandMsg<K> for ExpandMsgXof<HashT>
3838
where
3939
HashT: Default + ExtendableOutput + Update + HashMarker,
4040
// If DST is larger than 255 bytes, the length of the computed DST is calculated by `K * 2`.
4141
// https://www.rfc-editor.org/rfc/rfc9380.html#section-5.3.1-2.1
4242
K: Mul<U2, Output: ArraySize + IsLess<U256, Output = True>>,
4343
{
44-
type Expander = Self;
44+
type Expander<'dst> = Self;
4545

46-
fn expand_message(
46+
fn expand_message<'dst>(
4747
msg: &[&[u8]],
48-
dst: &'a [&'a [u8]],
48+
dst: &'dst [&[u8]],
4949
len_in_bytes: NonZero<usize>,
50-
) -> Result<Self::Expander> {
50+
) -> Result<Self::Expander<'dst>> {
5151
let len_in_bytes = u16::try_from(len_in_bytes.get()).map_err(|_| Error)?;
5252

5353
let domain = Domain::<Prod<K, U2>>::xof::<HashT>(dst)?;
@@ -119,7 +119,7 @@ mod test {
119119
{
120120
assert_message(self.msg, domain, L::to_u16(), self.msg_prime);
121121

122-
let mut expander = <ExpandMsgXof<HashT> as ExpandMsg<'_, U16>>::expand_message(
122+
let mut expander = <ExpandMsgXof<HashT> as ExpandMsg<U16>>::expand_message(
123123
&[self.msg],
124124
&[dst],
125125
NonZero::new(L::to_usize()).ok_or(Error)?,

elliptic-curve/src/oprf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ pub trait OprfParameters: GroupDigest + PrimeCurve {
2626
/// and `HashToScalar` as defined in [section 4 of RFC9497][oprf].
2727
///
2828
/// [oprf]: https://www.rfc-editor.org/rfc/rfc9497.html#name-ciphersuites
29-
type ExpandMsg: for<'a> ExpandMsg<'a, <Self as GroupDigest>::K>;
29+
type ExpandMsg: ExpandMsg<<Self as GroupDigest>::K>;
3030
}

0 commit comments

Comments
 (0)