Crate scrypt

Crate scrypt 

Source
Expand description

§RustCrypto: scrypt

crate Docs Build Status Apache2/MIT licensed Rust Version Project Chat

Pure Rust implementation of the scrypt key derivation function, a sequential memory hard function which can also be used for password hashing.

§License

Licensed under either of:

at your option.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

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.12", default-features = false }

§Usage (simple PHC password hash usage with default params)

// NOTE: example requires `getrandom` feature is enabled

use scrypt::{
    password_hash::{
        PasswordHasher, PasswordVerifier, phc::{PasswordHash, Salt}
    },
    Scrypt
};

let password = b"hunter42"; // Bad password; don't actually use!

// Hash password to PHC string ($scrypt$...)
let hash: PasswordHash = Scrypt.hash_password(password)?;
let hash_string = hash.to_string();

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

Re-exports§

pub use password_hash;password-hash

Modules§

errors
Errors for scrypt operations.
mcfmcf
Implementation of the password-hash traits for Modular Crypt Format (MCF) password hash strings which begin with $7$:
phcphc
Implementation of the password-hash crate API.

Structs§

Params
The Scrypt parameter values.
Scrypt
scrypt password hashing type which can produce and verify strings in either the Password Hashing Competition (PHC) string format which begin with $scrypt$, or in Modular Crypt Format (MCF) which begin with $7$.

Functions§

scrypt
The scrypt key derivation function.