Expand description
§hsh-digest — general-purpose hashing primitives
⚠️ This crate is NOT for password storage. Hashing passwords
requires a memory-hard / iteration-hard KDF (Argon2id, scrypt,
bcrypt, PBKDF2). For that, use hsh::api::hash from the hsh
crate, not the primitives here.
Use hsh-digest when you need a standard cryptographic digest for
things like:
- Content addressing (Git-style, IPFS-style content hashes).
- Message authentication codes (with the
hmaccrate on top). - Random-oracle / commitment schemes.
- PHC-string parsing for non-
hshhashes. - Building blocks for higher-level protocols (e.g. Merkle trees).
§Algorithms
| Family | Members | Feature flag |
|---|---|---|
| SHA-2 | SHA-256, SHA-384, SHA-512 | sha2 (default) |
| SHA-3 | SHA3-256, SHA3-384, SHA3-512 | sha3 (default) |
| BLAKE3 | BLAKE3-256 | blake3 (default) |
| K12 | KangarooTwelve, TurboSHAKE128/256 | k12 (stub) |
| Ascon | Ascon-Hash256, Ascon-XOF128 | ascon (stub) |
§Example
§One-shot
use hsh_digest::{Algorithm, hash};
let digest = hash(Algorithm::Sha256, b"hello, world").unwrap();
assert_eq!(digest.len(), 32);§Streaming
use hsh_digest::{Algorithm, Hasher};
let mut hasher = Hasher::new(Algorithm::Blake3).unwrap();
hasher.update(b"hello, ");
hasher.update(b"world");
let digest = hasher.finalize();
assert_eq!(digest.len(), 32);Re-exports§
pub use error::DigestError;
Modules§
- error
- Structured error type for the
hsh-digestcrate.
Structs§
- Hasher
- Streaming hasher — call
Hasher::updateone or more times, thenHasher::finalize.
Enums§
- Algorithm
- Supported general-purpose hash algorithms.
Functions§
- constant_
time_ eq - Constant-time comparison of two byte slices.
- hash
- One-shot convenience: hashes
datawithalgorithmand returns the digest bytes.