-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
52 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![no_main] | ||
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured}; | ||
use libfuzzer_sys::fuzz_target; | ||
use scrypt::password_hash::{ | ||
Ident, PasswordHash, PasswordHasher, PasswordVerifier, Salt, SaltString, | ||
}; | ||
use scrypt::{scrypt, Scrypt}; | ||
|
||
#[derive(Debug)] | ||
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 len = u.int_in_range(10..=64)?; | ||
|
||
let params = scrypt::Params::new(log_n, r, p, len).unwrap(); | ||
Ok(Self(params)) | ||
} | ||
} | ||
|
||
fuzz_target!(|data: (&[u8], &[u8], ScryptRandParams)| { | ||
let (password, salt, ScryptRandParams(params)) = data; | ||
|
||
// Check direct hashing | ||
let mut result = [0u8; 64]; | ||
scrypt(password, salt, ¶ms, &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( | ||
password, | ||
Some(Ident::new_unwrap("scrypt")), | ||
None, | ||
params, | ||
&salt_string, | ||
) | ||
.unwrap() | ||
.to_string(); | ||
|
||
// Check PHC verification | ||
let hash = PasswordHash::new(&phc_hash).unwrap(); | ||
Scrypt.verify_password(password, &hash).unwrap(); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.