Fuzz: Use rand range for hkdf
@@ -5,17 +5,20 @@ extern crate rand;
use orion::hazardous::hkdf::Hkdf;
use orion::core::options::ShaVariantOption;
+use rand::prelude::*;
-fn fuzz_hkdf(salt: &[u8], ikm: &[u8], info: &[u8], okm_len: usize, hmac: ShaVariantOption) {
- // Make sure to cover all possible length selections
- for okm_len_inter in 1..okm_len+1 {
+fn fuzz_hkdf(salt: &[u8], ikm: &[u8], info: &[u8], len_max: usize, hmac: ShaVariantOption) {
+
+ let mut rng = rand::thread_rng();
+
+ let okm_len_rand = rng.gen_range(1, len_max+1);
let dk = Hkdf {
salt: salt.to_vec(),
ikm: ikm.to_vec(),
info: info.to_vec(),
- length: okm_len_inter,
+ length: okm_len_rand,
hmac,
};
@@ -24,8 +27,6 @@ fn fuzz_hkdf(salt: &[u8], ikm: &[u8], info: &[u8], okm_len: usize, hmac: ShaVari
assert_eq!(dk_fin, dk.derive_key().unwrap());
assert_eq!(dk.verify(&dk_fin).unwrap(), true);
-
- }
}
fuzz_target!(|data: &[u8]| {
