Skip to content

Commit e767543

Browse files
authored
Embrace digest::Output (#51)
1 parent d316ce4 commit e767543

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/voprf.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use core::marker::PhantomData;
1515

1616
use derive_where::DeriveWhere;
1717
use digest::core_api::BlockSizeUser;
18-
use digest::{Digest, FixedOutputReset};
18+
use digest::{Digest, FixedOutputReset, Output};
1919
use generic_array::sequence::Concat;
2020
use generic_array::typenum::{U1, U11, U2, U20};
2121
use generic_array::GenericArray;
@@ -245,7 +245,7 @@ impl<G: Group, H: BlockSizeUser + Digest + FixedOutputReset> NonVerifiableClient
245245
input: &[u8],
246246
evaluation_element: &EvaluationElement<G, H>,
247247
metadata: Option<&[u8]>,
248-
) -> Result<GenericArray<u8, H::OutputSize>> {
248+
) -> Result<Output<H>> {
249249
let unblinded_element = evaluation_element.value * &G::scalar_invert(&self.blind);
250250
let mut outputs = finalize_after_unblind::<G, H, _, _>(
251251
Some((input, unblinded_element)).into_iter(),
@@ -330,7 +330,7 @@ impl<G: Group, H: BlockSizeUser + Digest + FixedOutputReset> VerifiableClient<G,
330330
proof: &Proof<G, H>,
331331
pk: G,
332332
metadata: Option<&[u8]>,
333-
) -> Result<GenericArray<u8, H::OutputSize>> {
333+
) -> Result<Output<H>> {
334334
// `core::array::from_ref` needs a MSRV of 1.53
335335
let inputs: &[&[u8]; 1] = core::slice::from_ref(&input).try_into().unwrap();
336336
let clients: &[Self; 1] = core::slice::from_ref(self).try_into().unwrap();
@@ -397,7 +397,7 @@ impl<G: Group, H: BlockSizeUser + Digest + FixedOutputReset> VerifiableClient<G,
397397
impl<G: Group, H: BlockSizeUser + Digest + FixedOutputReset> NonVerifiableServer<G, H> {
398398
/// Produces a new instance of a [NonVerifiableServer] using a supplied RNG
399399
pub fn new<R: RngCore + CryptoRng>(rng: &mut R) -> Result<Self> {
400-
let mut seed = GenericArray::<_, H::OutputSize>::default();
400+
let mut seed = Output::<H>::default();
401401
rng.fill_bytes(&mut seed);
402402
Self::new_from_seed(&seed)
403403
}
@@ -463,7 +463,7 @@ impl<G: Group, H: BlockSizeUser + Digest + FixedOutputReset> NonVerifiableServer
463463
impl<G: Group, H: BlockSizeUser + Digest + FixedOutputReset> VerifiableServer<G, H> {
464464
/// Produces a new instance of a [VerifiableServer] using a supplied RNG
465465
pub fn new<R: RngCore + CryptoRng>(rng: &mut R) -> Result<Self> {
466-
let mut seed = GenericArray::<_, H::OutputSize>::default();
466+
let mut seed = Output::<H>::default();
467467
rng.fill_bytes(&mut seed);
468468
Self::new_from_seed(&seed)
469469
}
@@ -852,13 +852,15 @@ fn deterministic_blind_unchecked<G: Group, H: BlockSizeUser + Digest + FixedOutp
852852
Ok(hashed_point * blind)
853853
}
854854

855-
#[allow(type_alias_bounds)]
856-
type VerifiableUnblindResult<'a, G: Group, H, IC, IM> = Map<
855+
type VerifiableUnblindResult<'a, G, H, IC, IM> = Map<
857856
Zip<
858-
Map<<&'a IC as IntoIterator>::IntoIter, fn(&VerifiableClient<G, H>) -> G::Scalar>,
857+
Map<
858+
<&'a IC as IntoIterator>::IntoIter,
859+
fn(&VerifiableClient<G, H>) -> <G as Group>::Scalar,
860+
>,
859861
<&'a IM as IntoIterator>::IntoIter,
860862
>,
861-
fn((G::Scalar, &EvaluationElement<G, H>)) -> G,
863+
fn((<G as Group>::Scalar, &EvaluationElement<G, H>)) -> G,
862864
>;
863865

864866
fn verifiable_unblind<
@@ -989,10 +991,9 @@ fn verify_proof<G: Group, H: BlockSizeUser + Digest + FixedOutputReset>(
989991
}
990992
}
991993

992-
#[allow(type_alias_bounds)]
993-
type FinalizeAfterUnblindResult<'a, G, H: Digest, I, IE> = Map<
994+
type FinalizeAfterUnblindResult<'a, G, H, I, IE> = Map<
994995
Zip<IE, Repeat<(&'a [u8], GenericArray<u8, U20>)>>,
995-
fn(((I, G), (&'a [u8], GenericArray<u8, U20>))) -> Result<GenericArray<u8, H::OutputSize>>,
996+
fn(((I, G), (&'a [u8], GenericArray<u8, U20>))) -> Result<Output<H>>,
996997
>;
997998

998999
fn finalize_after_unblind<
@@ -1111,7 +1112,7 @@ mod tests {
11111112
key: G::Scalar,
11121113
info: &[u8],
11131114
mode: Mode,
1114-
) -> GenericArray<u8, H::OutputSize> {
1115+
) -> Output<H> {
11151116
let dst =
11161117
GenericArray::from(STR_HASH_TO_GROUP).concat(get_context_string::<G>(mode).unwrap());
11171118
let point = G::hash_to_curve::<H, _>(input, dst).unwrap();

0 commit comments

Comments
 (0)