Skip to main content

Crate blake2b_192

Crate blake2b_192 

Source
Expand description

BLAKE2b with a fixed 24-byte (192-bit) digest.

This crate’s headline API implements exactly one primitive: unkeyed, sequential BLAKE2b parameterized with a digest length of 24 bytes, as defined by RFC 7693 and the BLAKE2 specification.

The digest length is part of BLAKE2b’s parameterization (it is mixed into the initial state), so this is not BLAKE2b-512 truncated to 24 bytes; the two functions produce unrelated outputs. The implemented function is byte-for-byte compatible with libsodium’s crypto_generichash(out, 24, msg, len, NULL, 0), CPython’s hashlib.blake2b(msg, digest_size=24), and RustCrypto’s Blake2b::<U24>.

Properties:

  • no_std, no heap allocation, zero dependencies;
  • no unsafe code (enforced by #![forbid(unsafe_code)]);
  • keyed hashing, salts, personalization, and tree mode are deliberately out of scope. Other digest lengths are out of scope for the headline API; the engine module exposes the validated engine at 1..=64 bytes for crates that build on it.

A 24-byte digest provides at most ~96-bit collision resistance (and ~192-bit preimage resistance); use a longer digest where general-purpose collision resistance matters.

§Examples

One-shot:

let digest: [u8; 24] = blake2b_192::hash(b"abc");
assert_eq!(
    digest[..4],
    [0x56, 0xa1, 0x7e, 0x38],
);

Streaming:

let mut hasher = blake2b_192::Blake2b192::new();
hasher.update(b"ab");
hasher.update(b"c");
assert_eq!(hasher.finalize(), blake2b_192::hash(b"abc"));

Modules§

engine
The validated BLAKE2b engine, exposed for crates that build on it.

Structs§

Blake2b192
Streaming BLAKE2b-192 hasher.

Constants§

DIGEST_LEN
Digest length in bytes (24 bytes = 192 bits).

Functions§

hash
Computes the BLAKE2b-192 digest of input in one call.