Expand description
BLAKE3: a fast cryptographic hash function with support for keyed hashing (MAC), key derivation and extendable output (XOF).
Pure-Rust implementation without heap allocation: the incremental Blake3 state
lives entirely on the stack (about 1.9 KiB).
§Backends
The tree structure of BLAKE3 lets several chunks be hashed in parallel:
| Target | Backend | Chunks in parallel |
|---|---|---|
x86_64 | AVX2 (runtime-detected with std) | 8 |
aarch64 | NEON (always available) | 4 |
wasm32 | simd128 (compile-time) | 4 |
| anything else | portable scalar | 1 |
On x86_64, runtime detection requires the std feature; without it the
backend is chosen at compile time from target_feature. On wasm32 the
simd128 kernel is compiled only when -C target-feature=+simd128 is set.
The portable fallback is written with 32-bit words so that it maps well onto
32-bit platforms.
§One-shot API
ⓘ
use crypto::{Hasher, blake3::Blake3};
let hash = Blake3::hash(b"hello world");§Incremental API
ⓘ
use crypto::{Hasher, blake3::Blake3};
let mut hasher = Blake3::new();
hasher.update(b"hello ");
hasher.update(b"world");
let hash = hasher.sum();§XOF (Extendable-Output Function) API
ⓘ
use crypto::{Hasher, blake3::Blake3};
let mut out = [0u8; 64];
let mut hasher = Blake3::new();
hasher.update(b"hello world");
hasher.finalize_xof().squeeze(&mut out);§Keyed hashing
ⓘ
use crypto::{Hasher, blake3::Blake3};
let key = b"whats the Elvish word for friend";
let mut hasher = Blake3::new_keyed(key);
hasher.update(b"hello world");
let hash = hasher.sum();The keyed_hash one-shot is also available:
ⓘ
use crypto::blake3::Blake3;
let key = b"whats the Elvish word for friend";
let hash = Blake3::keyed_hash(key, b"hello world");§Derive-key mode
ⓘ
use crypto::blake3::Blake3;
let key = Blake3::derive_key("my app context", b"key material");
let mut hasher = Blake3::new_keyed(&key);
hasher.update(b"hello world");
let hash = hasher.sum();§Security notes
- Outputs are truncated to
Hasher::OUTPUT_SIZEbytes; shorter outputs provide proportionally less security. Outputs longer than 32 bytes (via the XOF API) do not add any security margin. - The XOF seek position is not secret. An attacker who knows the message (and key, if any) can recover the offset of an extended output block, so do not treat the position as a secret.
- Inputs are limited to less than 2^64 bytes. All counter arithmetic wraps rather than panicking, so a longer input (only reachable with more than 2^64 bytes of input) yields an unspecified digest instead of a crash.
Blake3::derive_keyis not a password hash; use Argon2 or similar for passwords.
Structs§
- Blake3
- BLAKE3 hash function.
- Blake3
XofReader - BLAKE3 extensible-output function (XOF) reader.