Expand description
The throughput API: the core’s, and the calls that use other cores.
Structs§
- Batch
- Messages of one length in
Blocks, the batch calls’ input: each message starts a block, and every byte past each message’s end is zero, since aBatchlets the program write only the messages’ own bytes (so the bytes the batch kernels read in place, past a message, can never be wrong). It owns its blocks (Batch::new), or borrows blocks already in place whose messages fill them, with no bytes past their ends (Batch::from_blocks: a Merkle layer’s 64-byte nodes, a mapped file’s records). - Block
- 64 bytes on a 64-byte boundary: the unit the calls read, so every
message starts on a cache line. A
Batchholds its messages in blocks, each message starting a block and taking whole blocks (one for an empty message). - Cv
- The chaining value of a whole subtree, with its place: 2^level
chunks (1024 bytes each), the
index-th subtree of that size in the message. It is the only kind a left child can be. - LastCv
- The chaining value of a message’s last subtree, with its place and length: the right child at some level of the tree’s right edge. It may be shorter than its left sibling, and is never a left child: no call takes one on the left, so a tree with a short subtree inside it does not compile.
- Lent
- Guard for a message hashed in place on loan (
Pipeline::lent). - Limits
- Fixed memory bounds for a
Pipeline. - Message
- An open message on a
Pipeline. - Packed
countmessages ofNbytes each, packed end to end with nothing between them, on a 128-byte boundary: a compact layout for many short messages of one length (a Merkle layer’s leaves or digests) without per-message block padding in caller memory (Nis 16, 32, or 48; backing storage isNbytes per message rounded up once to a 128-byte line). It reads and writes as a[[u8; N]](leaves[i] = digest), and the batch calls take it as they take aBatch. ForPacked<32>with an even count, the digests can also be borrowed directly as 64-byte parent pairs viaPacked::as_blocks(carry or pad an odd last digest according to your tree).- Part
- Some of a batch’s messages, in place:
Prepared::partmakes it. - Pipeline
- Streaming multithreaded hasher with bounded memory and pull-based
Eventdelivery. - Room
- Reusable
ROOM_LEN-byte buffer for arriving message bytes. - Tree
Hasher - A
Modeprepared for a program that builds or verifies a BLAKE3 tree itself (verified streaming, an outboard, a tree hashed in parts on other machines): the subtrees’ chaining values, their parents, and the root. The mode’s key is derived once, here; each call then costs its hashing alone.
Enums§
Constants§
- ROOM_
LEN - Bytes in each
Room: sixty-four chunks (64 KiB), a whole BLAKE3 subtree on a 64-byte boundary. Chosen by empirical measurement across x86-64 (AVX2 and AVX-512) and ARM64 (NEON and SME2), where 64 KiB reaches both the 32-lane AVX-512 chunk kernel and SME2’s flat subtree walk with one mechanism (1 whole Room == 1 worker piece).
Traits§
- Prepared
- The batch calls’ input: messages of one length, prepared so that a
call reads them as they are.
Batchholds them in blocks, any length;Packed, ownedVec<[u8; N]>/Box<[[u8; N]]>and borrowed&[[u8; N]]slices (N= 16, 32, or 48) hold fixed-width messages end to end. Sealed: the crate’s types and fixed-width byte-array collections/slices alone.
Functions§
- block_
on - Drive
futureto completion on the current thread, parking between polls. - context_
key - Hash a key-derivation context string and return a
ContextKey. - finalize_
each - The hash of each message
whichnames:out[k]is whathashers[which[k]].finalize()would give, and that hasher is then reset for its next message (no length hint). Requiresout.len() == which.len(), each index< hashers.len(), and distinct indices: it panics on an index named twice, in every build. A call that is refused hashes nothing and leaves every hasher as it was. Messages that finish in one call hash side by side where the CPU has the lanes (with at least two eligible hashers in a 128-hasher window): on x86-64, staged plain 1 KiB chunks viahash_many_rounded(ceiling 32 lanes on Zen 5 / 16 on AVX-512 / 8 on AVX2 / 4 on SSE4.1), staged plain multi-block65..=1023 Bmessages on AVX2/AVX-512 viahash_by_blocks(equal-prefix-length blocks batched in SIMD, and on Linux x86-64 AVX-512/AVX2 their final blocks compressed inoutput16/output8SIMD lanes for chunks of four or more; SSE4.1 finishes staged< 1 KiBmessages individually), andoutput16/output8for every 4+ eligible counter-zero final blocks packed from remaining hashers on Linux AVX-512/AVX2; on AArch64, staged plain messages of up to 1024 bytes viahash_by_blocksand counter-zero final blocks via NEONoutput8. - find_
counter_ range - Search
countconsecutive single-block messages derived fromtemplate(4..=64bytes) inmode, replacing the 4-byte little-endian word at byte offsetcounter_word * 4withstart.wrapping_add(off as u32)foroff in 0..count, for digests whose first little-endian 32-bit wordword0 = u32::from_le_bytes(digest[..4])satisfies(word0 & mask) == target. - hash
- The hash in
modeof the message oflenbytes that startsinput: a batch of one. The message starts a block, so on a cache line; the bytes past its end, in its last block and any after, are ignored. Tuned for call after call: for a hash now and then amid other work,convenience::hashis the faster call. - hash_
chains_ 32_ trunc16 - Evaluate
init.len()independent 32-byte iterated hash chains inmode, advancing each chain bystepsiterations and writing its final 16-byte state toout[i](#584). - hash_
chains_ varlen_ 32_ trunc16 - Variable-step counterpart to
hash_chains_32_trunc16that advances chainibysteps[i]iterations inmodeand writes its final 16-byte state toout[i](uses stack storage up to 128 nonzero chains; allocates a call-localVec<usize>above 128; #584). - hash_
counter_ range - Hash
out.len()single-block messages derived fromtemplate(4..=64bytes) inmode, replacing the 4-byte little-endian word at byte offsetcounter_word * 4withstart.wrapping_add(i)(modulo 2^32) fori in 0..out.len(). - hash_
counter_ range_ trunc16 - Hash
out.len()single-block messages derived fromtemplate(4..=64bytes) inmode, replacing the 4-byte little-endian word at byte offsetcounter_word * 4withstart.wrapping_add(i)(modulo 2^32) fori in 0..out.len(), writing the first 16 bytes of each BLAKE3 digest. - hash_
each - The hash of each message, of any lengths, on the calling thread:
out[i]ishash(mode, items[i].0, items[i].1), each item a message ofitems[i].1bytes starting its blocks (the bytes past its end ignored). Short messages hash together, so a collection of small items (a directory’s files, a repository’s objects) takes less time than one call each. Requiresout.len() == items.len(). - hash_
each_ multithreaded hash_each, using other CPU cores for collections whose small items total 512 KiB or more (and for individual items of 512 KiB or more, ashash_multithreadeddoes), returning the same digests. Requiresout.len() == items.len().- hash_
many - The hashes of a
Batch’s messages, inmode, on the calling thread:out[i]becomes thehashof messagei, one digest a message. This is the shape of a Merkle tree’s layer: leaves of one size, or nodes of two 32-byte children, which the layer below writes straight into the next layer’s batch (Batch::digests_mut). - hash_
many_ multithreaded hash_many, eligible to use other CPU cores above the split threshold: always the same digests as single-threadedhash_many.- hash_
multithreaded hash, eligible to use other CPU cores above the split threshold: always the sameHashas single-threadedhash. For a message whose bytes are not in blocks (a mapped file, say),update_multithreadedinto aHashertakes any slice, at the same speed on the i7-12700K from 512 KiB to 1 GiB (about 1% slower at 1 MiB).- left_
len - The bytes of the left subtree of a message, or of a subtree, of
lenbytes: the largest power of two of chunks below its chunk count. The right subtree holds the rest. - level_
of - The level of whole subtrees of
lenbytes:lenis1024 << level. - update_
each - Feed each piece to its hasher:
(i, bytes)doeshashers[i].update(bytes), each hasher’s pieces in their order inpieces. Call it once with all the pieces your program has in hand (one turn of its event loop): never slower than oneupdateeach: many messages arriving at once, such as a server’s uploads, each with its ownHasher. Requires eachi < hashers.len(): a turn that panics on one that is not leaves its hashers as after a panic. Finish the messages withfinalize_each: plain messages of up to 1024 bytes wait whole in their stage (on both x86-64 and AArch64), so those that finish together hash side by side there. Because a staged plain first chunk has not yet compressed intoChunkState, calling a non-consumingHasher::finalize()mid-chunk rehashes that staged prefix afresh; callers that finish each message once viafinalize_eachavoid that cost. - update_
multithreaded Hasher::update, eligible to use other CPU cores above the split threshold (512 KiB per eligible aligned subtree, an implementation heuristic): always the same digest as single-threadedupdate. Shorter updates hash on the calling thread. OneHashermay take both calls. The program callsinitialize_multithreadedfirst.