Skip to content

Commit

Permalink
fuzz: add upper bound for scrypt's password and salt sizes (#535)
Browse files Browse the repository at this point in the history
Also change ranges used to generate scrypt parameters to prevent
potential timeout issues.
  • Loading branch information
newpavlov authored Nov 1, 2024
1 parent d44ff8f commit 34bbf65
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions fuzz/fuzz_targets/scrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub struct ScryptRandParams(pub scrypt::Params);
impl<'a> Arbitrary<'a> for ScryptRandParams {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
let log_n = u.int_in_range(0..=15)?;
let r = u.int_in_range(1..=32)?;
let p = u.int_in_range(1..=16)?;
let r = u.int_in_range(1..=16)?;
let p = u.int_in_range(1..=8)?;
let len = u.int_in_range(10..=64)?;

let params = scrypt::Params::new(log_n, r, p, len).unwrap();
Expand All @@ -24,14 +24,19 @@ impl<'a> Arbitrary<'a> for ScryptRandParams {
fuzz_target!(|data: (&[u8], &[u8], ScryptRandParams)| {
let (password, salt, ScryptRandParams(params)) = data;

if password.len() > 64 {
return;
}

if salt.len() < Salt::MIN_LENGTH || salt.len() > (6 * Salt::MAX_LENGTH) / 8 {
return;
}

// Check direct hashing
let mut result = [0u8; 64];
scrypt(password, salt, &params, &mut result).unwrap();

// Check PHC hashing
if salt.len() < Salt::MIN_LENGTH {
return;
}
let salt_string = SaltString::encode_b64(salt).unwrap();
let phc_hash = Scrypt
.hash_password_customized(
Expand Down

0 comments on commit 34bbf65

Please sign in to comment.