[−][src]Crate argon2
Library for hashing passwords using Argon2, the password-hashing function that won the Password Hashing Competition (PHC).
Usage
To use this crate, add the following to your Cargo.toml:
[dependencies]
rust-argon2 = "0.6"
And the following to your crate root:
extern crate argon2;
Examples
Create a password hash using the defaults and verify it:
use argon2::{self, Config}; let password = b"password"; let salt = b"randomsalt"; let config = Config::default(); let hash = argon2::hash_encoded(password, salt, &config).unwrap(); let matches = argon2::verify_encoded(&hash, password).unwrap(); assert!(matches);
Create a password hash with custom settings and verify it:
use argon2::{self, Config, ThreadMode, Variant, Version}; let password = b"password"; let salt = b"othersalt"; let config = Config { variant: Variant::Argon2i, version: Version::Version13, mem_cost: 65536, time_cost: 10, lanes: 4, thread_mode: ThreadMode::Parallel, secret: &[], ad: &[], hash_length: 32 }; let hash = argon2::hash_encoded(password, salt, &config).unwrap(); let matches = argon2::verify_encoded(&hash, password).unwrap(); assert!(matches);
Limitations
This crate has the same limitation as the blake2-rfc
crate that it uses.
It does not attempt to clear potentially sensitive data from its work
memory. To do so correctly without a heavy performance penalty would
require help from the compiler. It's better to not attempt to do so than to
present a false assurance.
This version uses the standard implementation and does not yet implement optimizations. Therefore, it is not the fastest implementation available.
Structs
Config | Structure containing configuration settings. |
Enums
Error | Error type for Argon2 errors. |
ThreadMode | The thread mode used to perform the hashing. |
Variant | The Argon2 variant. |
Version | The Argon2 version. |
Functions
encoded_len | Returns the length of the encoded string. |
hash_encoded | Hashes the password and returns the encoded hash. |
hash_encoded_defaults | Deprecated Hashes the password using default settings and returns the encoded hash. |
hash_encoded_old | Deprecated Hashes the password and returns the encoded hash (pre 0.2.0 |
hash_encoded_std | Deprecated Hashes the password and returns the encoded hash (standard). |
hash_raw | Hashes the password and returns the hash as a vector. |
hash_raw_defaults | Deprecated Hashes the password using default settings and returns the hash as a vector. |
hash_raw_old | Deprecated Hashes the password and returns the hash as a vector (pre 0.2.0 |
hash_raw_std | Deprecated Hashes the password and returns the hash as a vector (standard). |
verify_encoded | Verifies the password with the encoded hash. |
verify_encoded_ext | Verifies the password with the encoded hash, secret and associated data. |
verify_raw | Verifies the password with the supplied configuration. |
verify_raw_old | Deprecated Verifies the password with the supplied settings (pre 0.2.0 |
verify_raw_std | Deprecated Verifies the password with the supplied settings (standard). |
Type Definitions
Result | A specialized result type for Argon2 operations. |