3个稳定版本
1.2.0 | 2019年6月23日 |
---|---|
1.1.0 | 2019年6月23日 |
1.0.0 | 2019年6月23日 |
#2030 在 加密学
112 每月下载量
190KB
3.5K SLoC
Argon2绑定
为Rust绑定的Argon2 C库。C实现可在此找到:https://github.com/P-H-C/phc-winner-argon2
注意:此包暴露的crate名为argon2
,而不是just_argon2
示例用法
fn main() {
const HASHLEN: usize = 32;
const SALTLEN: usize = 16;
const PWD: &[u8] = b"password";
const PWDLEN: usize = 8;
// so these don't get out of sync
assert_eq!(PWD.len(), PWDLEN);
let t_cost = 2; // 1-pass computation
let m_cost = 1 << 16; // 64 mebibytes memory usage
let parallelism = 1; // number of threads and lanes
let mut hash1 = [0u8; HASHLEN];
let mut hash2 = [0u8; HASHLEN];
let mut salt = [0u8; SALTLEN];
let mut pwd = [0u8; PWDLEN];
// Copy the password string into the array.
pwd.copy_from_slice(PWD);
// High-level API
argon2::i_hash_raw(t_cost, m_cost, parallelism, Some(&mut pwd), Some(&mut salt), &mut hash1).expect("Error hashing using high-level API.");
// Low-level API
let mut context = argon2::Context {
out: &mut hash2,
pwd: Some(&mut pwd),
salt: Some(&mut salt),
secret: None,
ad: None,
t_cost: t_cost,
m_cost: m_cost,
lanes: parallelism,
threads: parallelism,
version: argon2::Version::Version13,
flags: argon2::Flags::DEFAULT,
};
argon2::i_ctx(&mut context).expect("Error hashing using low-level API.");
assert_eq!(&hash1[0..], &hash2[0..], "Hashes do not match.");
println!("Hashes match.");
}
依赖
~71–280KB