项目作者: ExPixel

项目描述 :
Argon2 bindings for Rust.
高级语言: Rust
项目地址: git://github.com/ExPixel/argon2.git
创建时间: 2019-06-20T19:42:34Z
项目社区:https://github.com/ExPixel/argon2

开源协议:Apache License 2.0

下载


Argon2 Bindings

Build Status
crates.io
docs.rs

Bindings to the Argon2 C library for Rust. The C implementation can be found at https://github.com/P-H-C/phc-winner-argon2

NOTE: The crate exposed by this package is called argon2 and not just_argon2

Example Usage

  1. fn main() {
  2. const HASHLEN: usize = 32;
  3. const SALTLEN: usize = 16;
  4. const PWD: &[u8] = b"password";
  5. const PWDLEN: usize = 8;
  6. // so these don't get out of sync
  7. assert_eq!(PWD.len(), PWDLEN);
  8. let t_cost = 2; // 1-pass computation
  9. let m_cost = 1 << 16; // 64 mebibytes memory usage
  10. let parallelism = 1; // number of threads and lanes
  11. let mut hash1 = [0u8; HASHLEN];
  12. let mut hash2 = [0u8; HASHLEN];
  13. let mut salt = [0u8; SALTLEN];
  14. let mut pwd = [0u8; PWDLEN];
  15. // Copy the password string into the array.
  16. pwd.copy_from_slice(PWD);
  17. // High-level API
  18. argon2::i_hash_raw(t_cost, m_cost, parallelism, Some(&mut pwd), Some(&mut salt), &mut hash1).expect("Error hashing using high-level API.");
  19. // Low-level API
  20. let mut context = argon2::Context {
  21. out: &mut hash2,
  22. pwd: Some(&mut pwd),
  23. salt: Some(&mut salt),
  24. secret: None,
  25. ad: None,
  26. t_cost: t_cost,
  27. m_cost: m_cost,
  28. lanes: parallelism,
  29. threads: parallelism,
  30. version: argon2::Version::Version13,
  31. flags: argon2::Flags::DEFAULT,
  32. };
  33. argon2::i_ctx(&mut context).expect("Error hashing using low-level API.");
  34. assert_eq!(&hash1[0..], &hash2[0..], "Hashes do not match.");
  35. println!("Hashes match.");
  36. }