argon2/lib.rs
1// Copyright (c) 2017 Martijn Rijkeboer <[email protected]>
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9//! Library for hashing passwords using
10//! [Argon2](https://github.com/P-H-C/phc-winner-argon2), the password-hashing
11//! function that won the
12//! [Password Hashing Competition (PHC)](https://password-hashing.net).
13//!
14//! # Usage
15//!
16//! To use this crate, add the following to your Cargo.toml:
17//!
18//! ```toml
19//! [dependencies]
20//! rust-argon2 = "2.1"
21//! ```
22//!
23//! And the following to your crate root:
24//!
25//! ```rust
26//! extern crate argon2;
27//! ```
28//!
29//! # Examples
30//!
31//! Create a password hash using the defaults and verify it:
32//!
33//! ```rust
34//! use argon2::{self, Config};
35//!
36//! let password = b"password";
37//! let salt = b"randomsalt";
38//! let config = Config::default();
39//! let hash = argon2::hash_encoded(password, salt, &config).unwrap();
40//! let matches = argon2::verify_encoded(&hash, password).unwrap();
41//! assert!(matches);
42//! ```
43//!
44//! Create a password hash with custom settings and verify it:
45//!
46//! ```rust
47//! use argon2::{self, Config, ThreadMode, Variant, Version};
48//!
49//! let password = b"password";
50//! let salt = b"othersalt";
51//! let config = Config {
52//! variant: Variant::Argon2i,
53//! version: Version::Version13,
54//! mem_cost: 65536,
55//! time_cost: 10,
56#![cfg_attr(feature = "crossbeam-utils", doc = " lanes: 4,")]
57#![cfg_attr(
58 feature = "crossbeam-utils",
59 doc = " thread_mode: ThreadMode::Parallel,"
60)]
61#![cfg_attr(not(feature = "crossbeam-utils"), doc = " lanes: 1,")]
62#![cfg_attr(
63 not(feature = "crossbeam-utils"),
64 doc = " thread_mode: ThreadMode::Sequential,"
65)]
66//! secret: &[],
67//! ad: &[],
68//! hash_length: 32
69//! };
70//! let hash = argon2::hash_encoded(password, salt, &config).unwrap();
71//! let matches = argon2::verify_encoded(&hash, password).unwrap();
72//! assert!(matches);
73//! ```
74//!
75//! # Limitations
76//!
77//! This crate has the same limitation as the `blake2-rfc` crate that it uses.
78//! It does not attempt to clear potentially sensitive data from its work
79//! memory. To do so correctly without a heavy performance penalty would
80//! require help from the compiler. It's better to not attempt to do so than to
81//! present a false assurance.
82//!
83//! This version uses the standard implementation and does not yet implement
84//! optimizations. Therefore, it is not the fastest implementation available.
85
86mod argon2;
87mod block;
88mod common;
89mod config;
90mod context;
91mod core;
92mod decoded;
93mod encoding;
94mod error;
95mod memory;
96mod result;
97mod thread_mode;
98mod variant;
99mod version;
100
101pub use crate::argon2::*;
102pub use crate::config::Config;
103pub use crate::error::Error;
104pub use crate::result::Result;
105pub use crate::thread_mode::ThreadMode;
106pub use crate::variant::Variant;
107pub use crate::version::Version;