17 releases (4 stable)

2.1.0 Jan 8, 2024
2.0.0 Aug 11, 2023
1.0.1 Aug 7, 2023
1.0.0 Jan 7, 2022
0.3.0 Mar 22, 2017

#208 in Cryptography

Download history 15501/week @ 2023-12-23 23331/week @ 2023-12-30 32392/week @ 2024-01-06 32777/week @ 2024-01-13 36959/week @ 2024-01-20 31716/week @ 2024-01-27 34432/week @ 2024-02-03 39507/week @ 2024-02-10 35144/week @ 2024-02-17 38963/week @ 2024-02-24 33679/week @ 2024-03-02 40162/week @ 2024-03-09 39771/week @ 2024-03-16 43003/week @ 2024-03-23 48000/week @ 2024-03-30 27906/week @ 2024-04-06

166,027 downloads per month
Used in 150 crates (90 directly)

MIT/Apache

79KB
1.5K SLoC

Rust-argon2

Rust library for hashing passwords using Argon2, the password-hashing function that won the Password Hashing Competition (PHC).

Usage

To use rust-argon2, add the following to your Cargo.toml:

[dependencies]
rust-argon2 = "2.1"

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, 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,
    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.

License

Rust-argon2 is dual licensed under the MIT and Apache 2.0 licenses, the same licenses as the Rust compiler.

Contributions

Contributions are welcome. By submitting a pull request you are agreeing to make you work available under the license terms of the Rust-argon2 project.

Dependencies

~425–630KB
~13K SLoC