Skip to main content

Crate hsh_digest

Crate hsh_digest 

Source
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 hmac crate on top).
  • Random-oracle / commitment schemes.
  • PHC-string parsing for non-hsh hashes.
  • Building blocks for higher-level protocols (e.g. Merkle trees).

§Algorithms

FamilyMembersFeature flag
SHA-2SHA-256, SHA-384, SHA-512sha2 (default)
SHA-3SHA3-256, SHA3-384, SHA3-512sha3 (default)
BLAKE3BLAKE3-256blake3 (default)
K12KangarooTwelve, TurboSHAKE128/256k12 (stub)
AsconAscon-Hash256, Ascon-XOF128ascon (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-digest crate.

Structs§

Hasher
Streaming hasher — call Hasher::update one or more times, then Hasher::finalize.

Enums§

Algorithm
Supported general-purpose hash algorithms.

Functions§

constant_time_eq
Constant-time comparison of two byte slices.
hash
One-shot convenience: hashes data with algorithm and returns the digest bytes.