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

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::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
    Argon2
};
use rand_core::OsRng;

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_simple(password, salt.as_ref()).unwrap().to_string();

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

Re-exports

pub use password_hash;

Structs

Argon2 context.

Argon2 password hash parameters.

Builder for Argon2 Params.

PasswordHashpassword-hash

Password hash.

Enums

Argon2 primitive type: variants of the algorithm.

Error type.

Version of the algorithm.

Constants

ARGON2D_IDENTpassword-hash

Argon2d algorithm identifier

ARGON2ID_IDENTpassword-hash

Argon2id algorithm identifier

ARGON2I_IDENTpassword-hash

Argon2i algorithm identifier

Minimum and maximum associated data length in bytes

Minimum and maximum number of lanes (degree of parallelism)

Maximum number of memory blocks.

Maximum digest size in bytes

Maximum password length in bytes

Maximum salt length in bytes

Maximum key length in bytes

Minimum and maximum number of threads

Maximum number of passes

Minimum and maximum number of lanes (degree of parallelism)

Minimum number of memory blocks.

Minimum digest size in bytes

Minimum and maximum salt length in bytes

Minimum and maximum number of threads

Minimum number of passes

Traits

PasswordHasherpassword-hash

Trait for password hashing functions.

PasswordVerifierpassword-hash

Trait for password verification.

Type Definitions

Result with argon2’s Error type.