logo
Expand description

This crate implements the Scrypt key derivation function as specified in [1].

If you are only using the low-level scrypt function instead of the higher-level Scrypt struct to produce/verify hash strings, it’s recommended to disable default features in your Cargo.toml:

[dependencies]
scrypt = { version = "0.2", default-features = false }

Usage (simple with default params)

use scrypt::{
    password_hash::{
        rand_core::OsRng,
        PasswordHash, PasswordHasher, PasswordVerifier, SaltString
    },
    Scrypt
};

let password = b"hunter42"; // Bad password; don't actually use!
let salt = SaltString::generate(&mut OsRng);

// Hash password to PHC string ($scrypt$...)
let password_hash = Scrypt.hash_password(password, &salt)?.to_string();

// Verify password against PHC string
let parsed_hash = PasswordHash::new(&password_hash)?;
assert!(Scrypt.verify_password(password, &parsed_hash).is_ok());

References

[1] - C. Percival. Stronger Key Derivation Via Sequential Memory-Hard Functions

Re-exports

pub use password_hash;

Modules

Errors for scrypt operations.

Structs

The Scrypt parameter values.

Scryptsimple

scrypt type for use with PasswordHasher.

Constants

Algorithm identifier

Functions

The scrypt key derivation function.