Crate argon2[−][src]
Expand description
Pure Rust implementation of the Argon2 password hashing function.
About
Argon2 is a memory-hard key derivation function chosen as the winner of the Password Hashing Competition in July 2015.
It provides three algorithmic variants (chosen via the Algorithm
enum):
- Argon2d: maximizes resistance to GPU cracking attacks
- Argon2i: optimized to resist side-channel attacks
- Argon2id: (default) hybrid version combining both Argon2i and Argon2d
Support is provided for embedded (i.e. no_std
) environments, including
ones without alloc
support.
Usage (simple with default params)
Note: this example requires the rand_core
crate with the std
feature
enabled for rand_core::OsRng
(embedded platforms can substitute their
own RNG)
Add the following to your crate’s Cargo.toml
to import it:
[dependencies]
argon2 = "0.2"
rand_core = { version = "0.6", features = ["std"] }
The following example demonstrates the high-level password hashing API:
use argon2::{
password_hash::{
rand_core::OsRng,
PasswordHash, PasswordHasher, PasswordVerifier, SaltString
},
Argon2
};
let password = b"hunter42"; // Bad password; don't actually use!
let salt = SaltString::generate(&mut OsRng);
// Argon2 with default params (Argon2id v19)
let argon2 = Argon2::default();
// Hash password to PHC string ($argon2id$v=19$...)
let password_hash = argon2.hash_password(password, &salt)?.to_string();
// Verify password against PHC string
let parsed_hash = PasswordHash::new(&password_hash)?;
assert!(argon2.verify_password(password, &parsed_hash).is_ok());
Re-exports
pub use password_hash;
Structs
Argon2 context.
Structure for the (1KB) memory block implemented as 128 64-bit words.
Argon2 password hash parameters.
Builder for Argon2 Params
.
password-hash
Password hash.
Enums
Argon2 primitive type: variants of the algorithm.
Error type.
Version of the algorithm.
Constants
password-hash
Argon2d algorithm identifier
password-hash
Argon2id algorithm identifier
password-hash
Argon2i algorithm identifier
Maximum password length in bytes.
Maximum salt length in bytes.
Maximum secret key length in bytes.
Minimum and maximum salt length in bytes.
Traits
password-hash
Trait for password hashing functions.
password-hash
Trait for password verification.