Expand description
The official Rust implementation of the BLAKE3 cryptographic hash function.
Examples
// Hash an input all at once.
let hash1 = blake3::hash(b"foobarbaz");
// Hash an input incrementally.
let mut hasher = blake3::Hasher::new();
hasher.update(b"foo");
hasher.update(b"bar");
hasher.update(b"baz");
let hash2 = hasher.finalize();
assert_eq!(hash1, hash2);
// Extended output. OutputReader also implements Read and Seek.
let mut output = [0; 1000];
let mut output_reader = hasher.finalize_xof();
output_reader.fill(&mut output);
assert_eq!(&output[..32], hash1.as_bytes());
// Print a hash as hex.
println!("{}", hash1);
Cargo Features
The std
feature (the only feature enabled by default) is required for
implementations of the Write
and Seek
traits, and also for runtime
CPU feature detection. If this feature is disabled, the only way to use the
SIMD implementations in this crate is to enable the corresponding
instruction sets globally, with e.g. RUSTFLAGS="-C target-cpu=native"
. The
resulting binary will not be portable to other machines.
The rayon
feature (disabled by default, but enabled for docs.rs) adds
the Hasher::update_rayon
method, for multithreaded hashing. However,
even if this feature is enabled, all other APIs remain single-threaded.
The neon
feature enables ARM NEON support. Currently there is no runtime
CPU feature detection for NEON, so you must only enable this feature for
targets that are known to have NEON support. In particular, some ARMv7
targets support NEON, and some don’t.
The traits-preview
feature enables implementations of traits from the
RustCrypto digest
and crypto-mac
crates, and re-exports those crates
as traits::digest
and traits::crypto_mac
. However, the traits aren’t
stable, and they’re expected to change in incompatible ways before those
crates reach 1.0. For that reason, this crate makes no SemVer guarantees for
this feature, and callers who use it should expect breaking changes between
patch versions. (The “-preview” feature name follows the conventions of the
RustCrypto signature
crate.)
Structs
An output of the default size, 32 bytes, which provides constant-time equality checking.
An incremental hash state that can accept any number of writes.
The error type for Hash::from_hex
.
An incremental reader for extended output, returned by
Hasher::finalize_xof
.
Constants
Functions
The key derivation function.
The default hash function.
The keyed hash function.