Skip to content

Commit

Permalink
test_fuzz_xof
Browse files Browse the repository at this point in the history
  • Loading branch information
oconnor663 committed Aug 15, 2024
1 parent cfb305d commit eb15bce
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,42 @@ fn test_fuzz_hasher() {
}
}

#[test]
fn test_fuzz_xof() {
let mut input_buf = [0u8; 3 * BLOCK_LEN];
paint_test_input(&mut input_buf);

// Don't do too many iterations in debug mode, to keep the tests under a
// second or so. CI should run tests in release mode also. Provide an
// environment variable for specifying a larger number of fuzz iterations.
let num_tests = if cfg!(debug_assertions) { 100 } else { 2500 };

// Use a fixed RNG seed for reproducibility.
let mut rng = rand_chacha::ChaCha8Rng::from_seed([1; 32]);
for _num_test in 0..num_tests {
#[cfg(feature = "std")]
dbg!(_num_test);
// 31 (16 + 8 + 4 + 2 + 1) outputs
let mut output_buf = [0; 31 * CHUNK_LEN];
let input_len = rng.gen_range(0..input_buf.len());
let mut xof = crate::Hasher::new()
.update(&input_buf[..input_len])
.finalize_xof();
let partial_start = rng.gen_range(0..output_buf.len());
let partial_end = rng.gen_range(partial_start..output_buf.len());
xof.fill(&mut output_buf[..partial_start]);
xof.fill(&mut output_buf[partial_start..partial_end]);
xof.fill(&mut output_buf[partial_end..]);

let mut reference_buf = [0; 31 * CHUNK_LEN];
let mut reference_hasher = reference_impl::Hasher::new();
reference_hasher.update(&input_buf[..input_len]);
reference_hasher.finalize(&mut reference_buf);

assert_eq!(reference_buf, output_buf);
}
}

#[test]
fn test_xof_seek() {
let mut out = [0; 533];
Expand Down

0 comments on commit eb15bce

Please sign in to comment.