pub fn scrypt(
    password: &[u8],
    salt: &[u8],
    params: &Params,
    output: &mut [u8],
) -> Result<(), errors::InvalidOutputLen> {
    // This check required by Scrypt:
    // check output.len() > 0 && output.len() <= (2^32 - 1) * 32
    if output.is_empty() || output.len() / 32 > 0xffff_ffff {
        return Err(errors::InvalidOutputLen);
    }

    // The checks in the ScryptParams constructor guarantee
    // that the following is safe:
    let n = 1 << params.log_n;
    let r128 = (params.r as usize) * 128;
    let pr128 = (params.p as usize) * r128;
    let nr128 = n * r128;

    let mut b = vec![0u8; pr128];
    pbkdf2::<Hmac<Sha256>>(password, salt, 1, &mut b);

    let mut v = vec![0u8; nr128];
    let mut t = vec![0u8; r128];

    for chunk in &mut b.chunks_mut(r128) {
        romix::scrypt_ro_mix(chunk, &mut v, &mut t, n);
    }

    pbkdf2::<Hmac<Sha256>>(password, &b, 1, output);
    Ok(())
}
/// The scrypt key derivation function.
///
/// # Arguments
/// - `password` - The password to process as a byte vector
/// - `salt` - The salt value to use as a byte vector
/// - `params` - The ScryptParams to use
/// - `output` - The resulting derived key is returned in this byte vector.
///   **WARNING: Make sure to compare this value in constant time!**
///
/// # Return
/// `Ok(())` if calculation is succesfull and `Err(InvalidOutputLen)` if
/// `output` does not satisfy the following condition:
/// `output.len() > 0 && output.len() <= (2^32 - 1) * 32`.
The scrypt key derivation function.
The scrypt key derivation function .
pub fn scrypt(
    password: &[u8],
    salt: &[u8],
    params: &Params,
    output: &mut [u8],
) -> Result<(), errors::InvalidOutputLen> {
    // This check required by Scrypt:
    // check output.len() > 0 && output.len() <= (2^32 - 1) * 32
    if output.is_empty() || output.len() / 32 > 0xffff_ffff {
        return Err(errors::InvalidOutputLen);
    }
    // The checks in the ScryptParams constructor guarantee
    // that the following is safe:
    let n = 1 << params.log_n;
    let r128 = (params.r as usize) * 128;
    let pr128 = (params.p as usize) * r128;
    let nr128 = n * r128;
    let mut b = vec![0u8; pr128];
    pbkdf2::<Hmac<Sha256>>(password, salt, 1, &mut b);
    let mut v = vec![0u8; nr128];
    let mut t = vec![0u8; r128];
    for chunk in &mut b.chunks_mut(r128) {
        romix::scrypt_ro_mix(chunk, &mut v, &mut t, n);
    }
    pbkdf2::<Hmac<Sha256>>(password, &b, 1, output);
    Ok(())
}
pub fn scrypt ( password : & [ u8 ] , salt : & [ u8 ] , params : & Params , output : & mut [ u8 ] , ) -> Result < ( ) , errors :: InvalidOutputLen > { // This check required by Scrypt: // check output.len() > 0 && output.len() <= (2^32 - 1) * 32 if output . is_empty ( ) || output . len ( ) / 32 > 0xffff_ffff { return Err ( errors :: InvalidOutputLen ) ; } // The checks in the ScryptParams constructor guarantee // that the following is safe: let n = 1 << params . log_n ; let r128 = ( params . r as usize ) * 128 ; let pr128 = ( params . p as usize ) * r128 ; let nr128 = n * r128 ; let mut b = vec ! [ 0u8 pr128 ] ; pbkdf2 :: < Hmac < Sha256 > > ( password , salt , 1 , & mut b ) ; let mut v = vec ! [ 0u8 nr128 ] ; let mut t = vec ! [ 0u8 r128 ] ; for chunk in & mut b . chunks_mut ( r128 ) { romix :: scrypt_ro_mix ( chunk , & mut v , & mut t , n ) ; } pbkdf2 :: < Hmac < Sha256 > > ( password , & b , 1 , output ) ; Ok ( ( ) ) }
The scrypt key derivation function.
The scrypt key derivation function .
password
&[u8]
salt
&[u8]
params
&Params
output
&mut [u8]
`Ok(())` if calculation is succesfull and `Err(InvalidOutputLen)` if
`output` does not satisfy the following condition:
`output.len() > 0 && output.len() <= (2^32 - 1) * 32`.
` Ok (( )) ` if calculation is succesfull and ` Err ( InvalidOutputLen ) ` if ` output ` does not satisfy the following condition : ` output . len () > 0 && output . len () < = ( 2^32 - 1 ) * 32 ` .
password
&[u8]
The password to process as a byte vector
The password to process as a byte vector
salt
&[u8]
The salt value to use as a byte vector
The salt value to use as a byte vector
params
&Params
The ScryptParams to use
The ScryptParams to use
output
&mut [u8]
The resulting derived key is returned in this byte vector.
WARNING: Make sure to compare this value in constant time!
The resulting derived key is returned in this byte vector . WARNING : Make sure to compare this value in constant time!