Update cshake fuzzing target
@@ -4,17 +4,10 @@ extern crate libfuzzer_sys;
extern crate orion;
extern crate rand;
-use orion::core::options::KeccakVariantOption;
-use orion::hazardous::cshake::CShake;
+use orion::hazardous::cshake;
use rand::prelude::*;
-fn fuzz_cshake(
- input: &[u8],
- name: &[u8],
- custom: &[u8],
- len_max: usize,
- keccak: KeccakVariantOption,
-) {
+fn fuzz_cshake(input: &[u8], name: &[u8], custom: &[u8], len_max: usize) {
let mut rng = rand::thread_rng();
let len_rand = rng.gen_range(1, len_max + 1);
@@ -22,63 +15,15 @@ fn fuzz_cshake(
let mut mod_custom = custom.to_vec();
mod_custom.push(0u8);
- let cshake = CShake {
- input: input.to_vec(),
- name: name.to_vec(),
- custom: mod_custom,
- length: len_rand,
- keccak,
- };
-
- let hash = cshake.finalize().unwrap();
-
- assert_eq!(cshake.verify(&hash).unwrap(), true);
+ let mut hash_out = vec![0u8; len_rand];
+ let mut cshake = cshake::init(&mod_custom, Some(name)).unwrap();
+ cshake.update(input);
+ cshake.finalize(&mut hash_out).unwrap();
}
fuzz_target!(|data: &[u8]| {
- fuzz_cshake(data, data, data, 65536, KeccakVariantOption::KECCAK256);
- fuzz_cshake(
- data,
- &Vec::new(),
- data,
- 65536,
- KeccakVariantOption::KECCAK256,
- );
- fuzz_cshake(
- data,
- data,
- &Vec::new(),
- 65536,
- KeccakVariantOption::KECCAK256,
- );
- fuzz_cshake(
- &Vec::new(),
- data,
- data,
- 65536,
- KeccakVariantOption::KECCAK256,
- );
-
- fuzz_cshake(data, data, data, 65536, KeccakVariantOption::KECCAK512);
- fuzz_cshake(
- data,
- &Vec::new(),
- data,
- 65536,
- KeccakVariantOption::KECCAK512,
- );
- fuzz_cshake(
- data,
- data,
- &Vec::new(),
- 65536,
- KeccakVariantOption::KECCAK512,
- );
- fuzz_cshake(
- &Vec::new(),
- data,
- data,
- 65536,
- KeccakVariantOption::KECCAK512,
- );
+ fuzz_cshake(data, data, data, 65536);
+ fuzz_cshake(data, &Vec::new(), data, 65536);
+ fuzz_cshake(data, data, &Vec::new(), 65536);
+ fuzz_cshake(&Vec::new(), data, data, 65536);
});
