tuwunel_core/utils/hash.rs
1//! Password hashing and cryptographic digest utilities.
2//!
3//! Password helpers use Argon2id with a fresh random salt for each new hash.
4//! The SHA-256 submodule provides byte-oriented digest helpers.
5
6mod argon;
7
8pub mod sha256;
9
10use crate::Result;
11
12/// Verifies a plaintext password against an encoded Argon2 password hash.
13///
14/// Malformed hashes and password mismatches return an error. Success is
15/// represented by `Ok(())`.
16pub fn verify_password(password: &str, password_hash: &str) -> Result {
17 argon::verify_password(password, password_hash)
18}
19
20/// Hashes a plaintext password with Argon2id.
21///
22/// A fresh random salt is generated for every call. The result is a
23/// PHC-formatted string containing the salt and parameters needed for
24/// verification.
25pub fn password(password: &str) -> Result<String> { argon::password(password) }