|
@ -530,12 +530,11 @@ impl PRFGadget for Blake2sGadget |
|
|
#[cfg(test)]
|
|
|
#[cfg(test)]
|
|
|
mod test {
|
|
|
mod test {
|
|
|
use algebra::jubjub::Fq as Fr;
|
|
|
use algebra::jubjub::Fq as Fr;
|
|
|
use digest::{FixedOutput, Input};
|
|
|
|
|
|
use rand::{Rng, SeedableRng};
|
|
|
use rand::{Rng, SeedableRng};
|
|
|
use rand_xorshift::XorShiftRng;
|
|
|
use rand_xorshift::XorShiftRng;
|
|
|
|
|
|
|
|
|
use crate::prf::blake2s::{constraints::blake2s_gadget, Blake2s as B2SPRF};
|
|
|
use crate::prf::blake2s::{constraints::blake2s_gadget, Blake2s as B2SPRF};
|
|
|
use blake2::Blake2s;
|
|
|
|
|
|
|
|
|
use blake2::VarBlake2s;
|
|
|
use r1cs_core::ConstraintSystem;
|
|
|
use r1cs_core::ConstraintSystem;
|
|
|
|
|
|
|
|
|
use super::Blake2sGadget;
|
|
|
use super::Blake2sGadget;
|
|
@ -634,13 +633,15 @@ mod test { |
|
|
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
|
|
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
|
|
|
|
|
|
|
|
for input_len in (0..32).chain((32..256).filter(|a| a % 8 == 0)) {
|
|
|
for input_len in (0..32).chain((32..256).filter(|a| a % 8 == 0)) {
|
|
|
let mut h = Blake2s::new_keyed(&[], 32);
|
|
|
|
|
|
|
|
|
use digest::*;
|
|
|
|
|
|
let mut h = VarBlake2s::new_keyed(&[], 32);
|
|
|
|
|
|
|
|
|
let data: Vec<u8> = (0..input_len).map(|_| rng.gen()).collect();
|
|
|
let data: Vec<u8> = (0..input_len).map(|_| rng.gen()).collect();
|
|
|
|
|
|
|
|
|
h.process(&data);
|
|
|
|
|
|
|
|
|
h.input(&data);
|
|
|
|
|
|
|
|
|
let hash_result = h.fixed_result();
|
|
|
|
|
|
|
|
|
let mut hash_result = Vec::with_capacity(h.output_size());
|
|
|
|
|
|
h.variable_result(|res| hash_result.extend_from_slice(res));
|
|
|
|
|
|
|
|
|
let mut cs = TestConstraintSystem::<Fr>::new();
|
|
|
let mut cs = TestConstraintSystem::<Fr>::new();
|
|
|
|
|
|
|
|
@ -663,7 +664,6 @@ mod test { |
|
|
assert!(cs.is_satisfied());
|
|
|
assert!(cs.is_satisfied());
|
|
|
|
|
|
|
|
|
let mut s = hash_result
|
|
|
let mut s = hash_result
|
|
|
.as_ref()
|
|
|
|
|
|
.iter()
|
|
|
.iter()
|
|
|
.flat_map(|&byte| (0..8).map(move |i| (byte >> i) & 1u8 == 1u8));
|
|
|
.flat_map(|&byte| (0..8).map(move |i| (byte >> i) & 1u8 == 1u8));
|
|
|
|
|
|
|
|
|