13 releases (7 breaking)

0.8.3 Nov 24, 2020
0.8.2 Mar 26, 2020
0.8.1 Feb 11, 2020
0.6.1 Dec 26, 2019
0.3.0 Mar 22, 2017

#32 in Cryptography

Download history 82986/week @ 2021-08-11 87691/week @ 2021-08-18 48469/week @ 2021-08-25 54968/week @ 2021-09-01 55925/week @ 2021-09-08 50969/week @ 2021-09-15 35654/week @ 2021-09-22 42260/week @ 2021-09-29 62826/week @ 2021-10-06 68860/week @ 2021-10-13 56588/week @ 2021-10-20 53490/week @ 2021-10-27 50102/week @ 2021-11-03 46021/week @ 2021-11-10 33966/week @ 2021-11-17 24052/week @ 2021-11-24

164,131 downloads per month
Used in 69 crates (47 directly)

MIT/Apache

92KB
2K 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 = "0.8"

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.

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

~500–740KB
~15K SLoC