Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
¨Jeff committed Sep 8, 2023
1 parent 7705c90 commit 6ec3708
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
22 changes: 10 additions & 12 deletions ff/src/fields/field_hashers/expander/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

use ark_std::vec::Vec;

use digest::{FixedOutputReset, ExtendableOutput, Update};
use arrayvec::ArrayVec;

use digest::{ExtendableOutput, FixedOutputReset, Update};

pub trait Expander {
fn expand(&self, msg: &[u8], length: usize) -> Vec<u8>;
Expand All @@ -15,23 +14,23 @@ const MAX_DST_LENGTH: usize = 255;
const LONG_DST_PREFIX: &[u8; 17] = b"H2C-OVERSIZE-DST-";

/// Implements section [5.3.3](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#section-5.3.3)
/// "Using DSTs longer than 255 bytes" of the
/// "Using DSTs longer than 255 bytes" of the
/// [IRTF CFRG hash-to-curve draft #16](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#section-5.3.3).
pub struct DST(arrayvec::ArrayVec<u8,MAX_DST_LENGTH>);
pub struct DST(arrayvec::ArrayVec<u8, MAX_DST_LENGTH>);

impl DST {
pub fn new_xmd<H: FixedOutputReset+Default>(dst: &[u8]) -> DST {
pub fn new_xmd<H: FixedOutputReset + Default>(dst: &[u8]) -> DST {
DST(if dst.len() > MAX_DST_LENGTH {
let mut long = H::default();
long.update(&LONG_DST_PREFIX[..]);
long.update(&dst);
ArrayVec::try_from( long.finalize_fixed().as_ref() ).unwrap()
ArrayVec::try_from(long.finalize_fixed().as_ref()).unwrap()
} else {
ArrayVec::try_from(dst).unwrap()
})
}

pub fn new_xof<H: ExtendableOutput+Default>(dst: &[u8], k: usize) -> DST {
pub fn new_xof<H: ExtendableOutput + Default>(dst: &[u8], k: usize) -> DST {
DST(if dst.len() > MAX_DST_LENGTH {
let mut long = H::default();
long.update(&LONG_DST_PREFIX[..]);
Expand All @@ -40,7 +39,7 @@ impl DST {
let mut new_dst = [0u8; MAX_DST_LENGTH];
let new_dst = &mut new_dst[0..((2 * k + 7) >> 3)];
long.finalize_xof_into(new_dst);
ArrayVec::try_from( &*new_dst ).unwrap()
ArrayVec::try_from(&*new_dst).unwrap()
} else {
ArrayVec::try_from(dst).unwrap()
})
Expand All @@ -53,7 +52,6 @@ impl DST {
}
}


pub(super) struct ExpanderXof<H: ExtendableOutput + Clone + Default> {
pub(super) xofer: H,

Check warning on line 56 in ff/src/fields/field_hashers/expander/mod.rs

View workflow job for this annotation

GitHub Actions / Check no_std

field `xofer` is never read

Check failure on line 56 in ff/src/fields/field_hashers/expander/mod.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

field `xofer` is never read

Check failure on line 56 in ff/src/fields/field_hashers/expander/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

field `xofer` is never read

Check warning on line 56 in ff/src/fields/field_hashers/expander/mod.rs

View workflow job for this annotation

GitHub Actions / Check Documentation

field `xofer` is never read

Check warning on line 56 in ff/src/fields/field_hashers/expander/mod.rs

View workflow job for this annotation

GitHub Actions / Test assembly

field `xofer` is never read
pub(super) dst: Vec<u8>,
Expand Down Expand Up @@ -105,12 +103,12 @@ impl<H: FixedOutputReset + Default + Clone> Expander for ExpanderXmd<H> {
hasher.update(msg);
hasher.update(&lib_str);
hasher.update(&[0u8]);
dst_prime.update(& mut hasher);
dst_prime.update(&mut hasher);
let b0 = hasher.finalize_fixed_reset();

hasher.update(&b0);
hasher.update(&[1u8]);
dst_prime.update(& mut hasher);
dst_prime.update(&mut hasher);
let mut bi = hasher.finalize_fixed_reset();

let mut uniform_bytes: Vec<u8> = Vec::with_capacity(n);
Expand All @@ -121,7 +119,7 @@ impl<H: FixedOutputReset + Default + Clone> Expander for ExpanderXmd<H> {
hasher.update(&[*l ^ *r]);
}
hasher.update(&[i as u8]);
dst_prime.update(& mut hasher);
dst_prime.update(&mut hasher);
bi = hasher.finalize_fixed_reset();
uniform_bytes.extend_from_slice(&bi);
}
Expand Down
10 changes: 5 additions & 5 deletions ff/src/fields/field_hashers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod expander;
use crate::{Field, PrimeField};

use ark_std::vec::Vec;

Check warning on line 5 in ff/src/fields/field_hashers/mod.rs

View workflow job for this annotation

GitHub Actions / Check no_std

unused import: `ark_std::vec::Vec`

Check failure on line 5 in ff/src/fields/field_hashers/mod.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `ark_std::vec::Vec`

Check failure on line 5 in ff/src/fields/field_hashers/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unused import: `ark_std::vec::Vec`

Check warning on line 5 in ff/src/fields/field_hashers/mod.rs

View workflow job for this annotation

GitHub Actions / Check Documentation

unused import: `ark_std::vec::Vec`

Check warning on line 5 in ff/src/fields/field_hashers/mod.rs

View workflow job for this annotation

GitHub Actions / Test assembly

unused import: `ark_std::vec::Vec`
use digest::{FixedOutputReset,XofReader};
use digest::{FixedOutputReset, XofReader};
use expander::Expander;

use self::expander::ExpanderXmd;
Expand Down Expand Up @@ -77,13 +77,13 @@ impl<F: Field, H: FixedOutputReset + Default + Clone, const SEC_PARAM: usize> Ha
&uniform_bytes[elm_offset..][..self.len_per_base_elem],
)
};
F::from_base_prime_field_elems( (0..m).map( base_prime_field_elem ) ).unwrap()
F::from_base_prime_field_elems((0..m).map(base_prime_field_elem)).unwrap()
};
ark_std::array::from_fn::<F,N,_>(cb)
ark_std::array::from_fn::<F, N, _>(cb)
}
}

pub fn hash_to_field<F: Field,H: XofReader, const SEC_PARAM: usize>(h: &mut H) -> F {
pub fn hash_to_field<F: Field, H: XofReader, const SEC_PARAM: usize>(h: &mut H) -> F {
// The final output of `hash_to_field` will be an array of field
// elements from F::BaseField, each of size `len_per_elem`.
let len_per_base_elem = get_len_per_elem::<F, SEC_PARAM>();
Expand All @@ -97,7 +97,7 @@ pub fn hash_to_field<F: Field,H: XofReader, const SEC_PARAM: usize>(h: &mut H) -
h.read(alloca);
F::BasePrimeField::from_be_bytes_mod_order(alloca)
};
F::from_base_prime_field_elems( (0..m).map(base_prime_field_elem) ).unwrap()
F::from_base_prime_field_elems((0..m).map(base_prime_field_elem)).unwrap()
}

/// This function computes the length in bytes that a hash function should output
Expand Down
2 changes: 1 addition & 1 deletion test-templates/src/h2c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ macro_rules! test_h2c {

for v in data.vectors.iter() {
// first, hash-to-field tests
let got: [$base_prime_field; { 2* $m } ] =
let got: [$base_prime_field; { 2 * $m }] =
hasher.hash_to_field(&v.msg.as_bytes());
let want: Vec<$base_prime_field> =
v.u.iter().map(read_fq_vec).flatten().collect();
Expand Down

0 comments on commit 6ec3708

Please sign in to comment.