Skip to main content
This is unreleased documentation for the main (development) branch of crypto-glue.

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 scrypt = Scrypt::default(); // Uses `Params::RECOMMENDED`
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)?;
scrypt.verify_password(password, &parsed_hash)?;

Modules§

errors
Errors for scrypt operations.

Structs§

Params
The Scrypt parameter values.

Functions§

scrypt
The scrypt key derivation function.