Most hash functions are a chain: each block of input is mixed into the result of the previous block, so the last block can’t be processed until every earlier one is done. However many cores your CPU has, SHA-256 uses one of them. BLAKE3, published in January 2020 by Jack O’Connor, Jean-Philippe Aumasson, Samuel Neves and Zooko Wilcox-O’Hearn, breaks that chain. It splits the input into 1 KiB chunks, hashes them independently, and joins the results in a binary Merkle tree. Independent chunks can go to different threads, and to different lanes of the CPU’s vector registers.
This article takes the design apart piece by piece. We build BLAKE3 from scratch in about 150 lines of JavaScript, a recursive version, a streaming version, and a multithreaded one, and check all of them against the official implementation. Then we measure what the tree buys in practice. Every code example was run before publishing.
The short answer#
Why a hash function needs a tree#
SHA-256 follows the Merkle–Damgård design: a 32-byte state is updated with one 64-byte block at a time. Block 2 needs the state after block 1, which needs the state after block 0. That dependency chain is the entire problem. Modern CPUs have many cores and wide vector units, and a chain can use only one core and, at best, the parallelism inside a single block.
A tree removes the chain. Leaves are hashed independently, and only the small number of parent nodes depend on their children. Ralph Merkle described hash trees in 1979, and they’re used everywhere from Git to certificate transparency logs, but usually as a structure built on top of a hash function. In BLAKE3, the tree is the hash function: there’s no other mode, so every implementation, from a microcontroller to a 64-core server, produces the same output and can use as much parallelism as it has.
BLAKE3 combines two earlier designs. Its compression function is a reduced-round version of BLAKE2s’s, which itself descends from the ChaCha stream cipher. Its tree mode comes from Bao, an earlier project by Jack O’Connor for verified streaming.
The compression function#
Everything in BLAKE3 is built from one operation: the compression function. It takes an 8-word chaining value (the key, or the result of earlier compressions), a 16-word (64-byte) message block, a 64-bit counter, the block’s length, and a set of flags, and fills a 4×4 grid of 32-bit words:
The compression state: 16 words of 32 bits
Then it runs 7 rounds. Each round applies the G function to the four columns of the grid and then to its four diagonals, mixing two message words into each call. Between rounds, the message words are shuffled with a fixed permutation, so every word meets every part of the state. If you read our deep dive on AES, ChaCha20 and RSA, G will look familiar: it’s the ChaCha20 quarter round, with message words added and rotations to the right.
// compress.mjs: the BLAKE3 compression function, from the specification. For learning only.
export const IV = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
export const CHUNK_START = 1, CHUNK_END = 2, PARENT = 4, ROOT = 8; // domain flags (keyed modes add more)
const PERMUTATION = [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8];
const rotr = (x, n) => ((x >>> n) | (x << (32 - n))) >>> 0;
// G mixes four state words and two message words with additions, XORs and rotations.
function g(v, a, b, c, d, mx, my) {
v[a] = (v[a] + v[b] + mx) >>> 0; v[d] = rotr(v[d] ^ v[a], 16);
v[c] = (v[c] + v[d]) >>> 0; v[b] = rotr(v[b] ^ v[c], 12);
v[a] = (v[a] + v[b] + my) >>> 0; v[d] = rotr(v[d] ^ v[a], 8);
v[c] = (v[c] + v[d]) >>> 0; v[b] = rotr(v[b] ^ v[c], 7);
}
// cv: 8 words (the key or a chaining value). block: 16 message words. Returns 16 words.
export function compress(cv, block, counter, blockLen, flags) {
const v = [...cv, IV[0], IV[1], IV[2], IV[3], counter >>> 0, Math.floor(counter / 2 ** 32) >>> 0, blockLen, flags];
let m = block;
for (let round = 0; round < 7; round++) {
g(v, 0, 4, 8, 12, m[0], m[1]); g(v, 1, 5, 9, 13, m[2], m[3]); // columns
g(v, 2, 6, 10, 14, m[4], m[5]); g(v, 3, 7, 11, 15, m[6], m[7]);
g(v, 0, 5, 10, 15, m[8], m[9]); g(v, 1, 6, 11, 12, m[10], m[11]); // diagonals
g(v, 2, 7, 8, 13, m[12], m[13]); g(v, 3, 4, 9, 14, m[14], m[15]);
m = PERMUTATION.map((i) => m[i]); // shuffle the message words for the next round
}
for (let i = 0; i < 8; i++) {
v[i] ^= v[i + 8]; // the first 8 words are the new chaining value
v[i + 8] ^= cv[i]; // the last 8 are only used for extended output
}
return v.map((x) => x >>> 0);
}
// Little-endian bytes <-> 32-bit words. A short final block is padded with zeros.
export function words(bytes) {
const padded = new Uint8Array(64);
padded.set(bytes);
const view = new DataView(padded.buffer);
return Array.from({ length: 16 }, (_, i) => view.getUint32(4 * i, true));
}
export function bytes(ws) {
const out = new DataView(new ArrayBuffer(4 * ws.length));
ws.forEach((w, i) => out.setUint32(4 * i, w, true));
return new Uint8Array(out.buffer);
}A few details matter for the rest of the design:
- 7 rounds, not 10. BLAKE2s uses 10. The BLAKE3 authors argue that the best-known attacks reach far fewer than 7 rounds, and that 7 still leaves a comfortable margin, while making every compression about 30% cheaper.
- The counter and flags are inside the state. Two otherwise identical blocks hashed at different positions, or as different kinds of node, give unrelated results. That’s what makes the tree safe.
- The output is 16 words, not 8. The first 8 are the new chaining value. The other 8 are only used when producing output longer than 32 bytes from the root.
Chunks and blocks#
A chunk is up to 1,024 bytes: 16 blocks of 64. Inside a chunk, BLAKE3 is a chain, exactly like SHA-256: each block is compressed with the chaining value from the block before, starting from the key (the IV, for plain hashing). Three things make each chunk distinct:
- The counter is the chunk’s index in the input: 0 for the first kilobyte, 1 for the second, and so on. Two chunks with identical contents, at different positions, get different chaining values.
- The first block of a chunk has the
CHUNK_STARTflag, and the last hasCHUNK_END. - The block length says how many bytes of the 64 are real. Only the last block of the last chunk can be short; it’s padded with zeros, and the length distinguishes the two cases.
So the 16 blocks of a chunk are sequential, but different chunks have nothing to do with each other. That’s the parallelism the rest of the design exploits.
The Merkle tree#
Once each chunk has a 32-byte chaining value, the chaining values are combined in pairs. A parent node is a single compression whose 64-byte message block is the left child’s chaining value followed by the right child’s, with the PARENT flag set. Parents are combined in turn until only one node is left: the root.
The tree’s shape is determined by a single rule. The left subtree always gets the largest power-of-two number of chunks that leaves at least one byte for the right subtree. Apply it recursively, and every left subtree is complete and perfectly balanced, while any unevenness ends up along the right edge. A 6-chunk input looks like this:
Only the root is compressed with the ROOT flag, and only the root produces output. That flag is what separates the final hash from every internal chaining value. Without it, an attacker who knows the hash of a message could treat it as a subtree and build a longer message whose hash they can predict, which is the length-extension weakness of SHA-256. With it, the root’s output can never be used as an input to another node.
Here is the whole tree as recursive code, built on the compression function above. It follows the specification directly, which makes it slow but easy to check:
// tree.mjs: BLAKE3 as a recursive tree, exactly as the specification defines its shape.
import { IV, CHUNK_START, CHUNK_END, PARENT, ROOT, compress, words, bytes } from "./compress.mjs";
const CHUNK = 1024, BLOCK = 64;
// A leaf: the chunk's 64-byte blocks are compressed in sequence. Returns the chunk's chaining value,
// or, for the root, the inputs of its last compression so the caller can produce output.
export function chunkCV(chunk, chunkIndex, isRoot = false) {
let cv = IV;
const blocks = Math.max(1, Math.ceil(chunk.length / BLOCK)); // an empty input is one empty block
for (let i = 0; i < blocks; i++) {
const block = chunk.subarray(i * BLOCK, (i + 1) * BLOCK);
let flags = (i === 0 ? CHUNK_START : 0) | (i === blocks - 1 ? CHUNK_END : 0);
if (i === blocks - 1 && isRoot) return { cv, block: words(block), counter: chunkIndex, len: block.length, flags: flags | ROOT };
cv = compress(cv, words(block), chunkIndex, block.length, flags).slice(0, 8);
}
return cv;
}
// An inner node: one compression of the two children's chaining values (32 + 32 bytes).
export function parentCV(left, right, isRoot = false) {
const node = { cv: IV, block: [...left, ...right], counter: 0, len: BLOCK, flags: PARENT };
if (isRoot) return { ...node, flags: PARENT | ROOT };
return compress(node.cv, node.block, node.counter, node.len, node.flags).slice(0, 8);
}
// The left subtree gets the largest power-of-two number of chunks that leaves something for the right.
export function leftLength(len) {
const fullChunks = Math.floor((len - 1) / CHUNK);
return CHUNK * 2 ** Math.floor(Math.log2(fullChunks));
}
// The chaining value of any subtree. Left and right halves don't depend on each other.
export function subtreeCV(input, chunkIndex = 0) {
if (input.length <= CHUNK) return chunkCV(input, chunkIndex);
const split = leftLength(input.length);
const left = subtreeCV(input.subarray(0, split), chunkIndex);
const right = subtreeCV(input.subarray(split), chunkIndex + split / CHUNK);
return parentCV(left, right);
}
// The root is compressed with the ROOT flag; its output can be as long as you like.
export function rootNode(input) {
if (input.length <= CHUNK) return chunkCV(input, 0, true);
const split = leftLength(input.length);
return parentCV(subtreeCV(input.subarray(0, split)), subtreeCV(input.subarray(split), split / CHUNK), true);
}
export function output(root, outLen = 32) {
const out = [];
for (let block = 0; out.length < outLen; block++) out.push(...bytes(compress(root.cv, root.block, block, root.len, root.flags)));
return Uint8Array.from(out.slice(0, outLen));
}
export const blake3 = (input, outLen = 32) => output(rootNode(input), outLen);And compared with the empty-string and “abc” digests, and with the audited @noble/hashes library:
// Compare the from-scratch version with an audited library (npm install @noble/hashes).
import { blake3 } from "./tree.mjs";
import { blake3 as noble } from "@noble/hashes/blake3.js";
const hex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
const text = (s) => new TextEncoder().encode(s);
console.log(hex(blake3(text("")))); // af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262
console.log(hex(blake3(text("abc")))); // 6437b3ac38465133ffb63b75273a8db548c558465d79db03fd359c6cd5bd9d85
const data = Uint8Array.from({ length: 100_000 }, (_, i) => i % 251); // 98 chunks: an uneven tree
console.log(hex(blake3(data)) === hex(noble(data))); // true
console.log(hex(blake3(data, 100)) === hex(noble(data, { dkLen: 100 }))); // true: 100 bytes of extended outputBeyond those, our test harness compared this code against the official Rust implementation (via its Python binding) across all 35 input lengths in BLAKE3’s published test vectors, ranging from 0 bytes to 100 KiB, with 131 bytes of output each. Every one matched, as did 300 random inputs checked against @noble/hashes.
The tree has uses beyond speed. Because every chunk’s position is part of its hash, you can verify part of a file without having the rest: the 32-byte chaining values along the path from a chunk to the root prove that the chunk belongs to the hash. Bao, and software built on it such as the Iroh networking library, use this to verify downloads piece by piece as they stream in.
Streaming: the chaining-value stack#
The recursive version needs the whole input up front, because it can’t split the tree without knowing the total length. Real implementations hash a stream of unknown length, keeping very little memory. The trick is that the tree is always built left to right, and every completed subtree is a power of two in size. So the hasher keeps a stack of chaining values, one for each completed subtree that’s still waiting for a sibling:
// hasher.mjs: streaming BLAKE3. Builds the same tree left to right, keeping only a stack of subtree CVs.
import { chunkCV, parentCV, output } from "./tree.mjs";
const CHUNK = 1024;
export class Hasher {
stack = []; // chaining values of complete subtrees, largest (leftmost) first
chunks = 0; // chunks completed so far
buffer = new Uint8Array(0); // the current, unfinished chunk
update(data) {
for (let pos = 0; pos < data.length; ) {
// Only finish a chunk when more input arrives: the last chunk might turn out to be the root.
if (this.buffer.length === CHUNK) {
this.#addChunk(chunkCV(this.buffer, this.chunks));
this.buffer = new Uint8Array(0);
}
const take = Math.min(CHUNK - this.buffer.length, data.length - pos);
const next = new Uint8Array(this.buffer.length + take);
next.set(this.buffer);
next.set(data.subarray(pos, pos + take), this.buffer.length);
this.buffer = next;
pos += take;
}
return this;
}
// Each trailing 0 bit of the new chunk count means two equal-sized subtrees can merge.
#addChunk(cv) {
this.chunks++;
for (let n = this.chunks; n % 2 === 0; n /= 2) cv = parentCV(this.stack.pop(), cv);
this.stack.push(cv);
}
digest(outLen = 32) {
if (this.stack.length === 0) return output(chunkCV(this.buffer, 0, true), outLen);
let cv = chunkCV(this.buffer, this.chunks); // the last chunk, then fold the stack from right to left
for (let i = this.stack.length - 1; i > 0; i--) cv = parentCV(this.stack[i], cv);
return output(parentCV(this.stack[0], cv, true), outLen);
}
}The stack follows the binary digits of the chunk count. After 7 chunks (binary 111), it holds three subtrees of 4, 2, and 1 chunks. When the 8th chunk finishes, the count becomes 1000, and the three trailing zeros mean three merges in a row, collapsing everything into one 8-chunk subtree:
import { Hasher } from "./hasher.mjs";
// Feed 1 KiB (one chunk's worth) at a time and watch the stack.
const h = new Hasher();
for (let kib = 1; kib <= 8; kib++) {
h.update(new Uint8Array(1024));
const bits = h.chunks.toString(2); // the stack mirrors the binary digits of the chunk count
const sizes = [...bits].map((b, i) => (b === "1" ? 2 ** (bits.length - 1 - i) : 0)).filter(Boolean);
console.log(`${kib} KiB in: ${h.chunks} chunks finished, stack = [${sizes.join(", ")}] (${h.stack.length} CVs)`);
}1 KiB in: 0 chunks finished, stack = [] (0 CVs) 2 KiB in: 1 chunks finished, stack = [1] (1 CVs) 3 KiB in: 2 chunks finished, stack = [2] (1 CVs) 4 KiB in: 3 chunks finished, stack = [2, 1] (2 CVs) 5 KiB in: 4 chunks finished, stack = [4] (1 CVs) 6 KiB in: 5 chunks finished, stack = [4, 1] (2 CVs) 7 KiB in: 6 chunks finished, stack = [4, 2] (2 CVs) 8 KiB in: 7 chunks finished, stack = [4, 2, 1] (3 CVs)
Two details are easy to miss:
- Merging is lazy. After exactly 1 KiB, the chunk isn’t finished yet, because if the input ends there, that chunk is the root and needs the
ROOTflag. A chunk is only closed when the next byte arrives. The same goes for the last block in a chunk, and for the top of the stack. - The stack is tiny. Its size is the number of 1 bits in the chunk count, so at most 54 entries for the largest possible input (264 bytes): under 2 KB. Our test confirmed that the stack size equals the number of 1 bits for every count up to 5,000 chunks.
At the end, the hasher folds the stack from right to left into the last chunk, and the final parent gets the ROOT flag. The result is identical to the recursive version, which our tests checked with random update sizes from 1 byte to 3 KB.
Parallelism across threads#
Since the left subtree of any node is a complete power-of-two tree that doesn’t depend on the right one, the two can be hashed at the same time. Split recursively, and you get 2, 4, 8, or more independent subtrees, each of which a thread hashes into a single 32-byte chaining value. The main thread only computes the few parent nodes above them. Here it is with Node.js worker threads:
// parallel.mjs: hash with several threads (Node.js worker_threads). Each worker hashes one whole subtree.
import { Worker, isMainThread, parentPort } from "node:worker_threads";
import { subtreeCV, parentCV, leftLength, rootNode, output } from "./tree.mjs";
if (!isMainThread) {
// Worker: receive a slice of the input and its first chunk's index, send back the subtree's CV.
parentPort.on("message", ({ data, chunkIndex }) => parentPort.postMessage(subtreeCV(data, chunkIndex)));
}
const CHUNK = 1024;
const workers = [];
const runInWorker = (data, chunkIndex) =>
new Promise((resolve) => {
const w = new Worker(new URL(import.meta.url));
workers.push(w);
w.once("message", resolve);
w.postMessage({ data: data.slice(), chunkIndex }); // slice(): send a copy of just this part
});
// Split the tree the same way the spec does, and hand each subtree at depth log2(threads) to a worker.
async function cv(input, chunkIndex, depth) {
if (depth <= 0 || input.length <= CHUNK) return runInWorker(input, chunkIndex);
const split = leftLength(input.length);
const [left, right] = await Promise.all([
cv(input.subarray(0, split), chunkIndex, depth - 1),
cv(input.subarray(split), chunkIndex + split / CHUNK, depth - 1),
]);
return parentCV(left, right);
}
// threads: a power of two, 2 or more.
export async function blake3Parallel(input, threads = 8) {
if (input.length <= CHUNK) return output(rootNode(input));
const split = leftLength(input.length);
const depth = Math.log2(threads) - 1; // the root's two children are each split depth more times
const [left, right] = await Promise.all([cv(input.subarray(0, split), 0, depth), cv(input.subarray(split), split / CHUNK, depth)]);
workers.splice(0).forEach((w) => w.terminate());
return output(parentCV(left, right, true));
}It produces the same hash for every thread count (our tests checked 2, 4, 8, and 16 threads across 9 input sizes), because the tree’s shape depends only on the input length. Here’s how it performed on 64 MiB:
| JavaScript, 64 MiB | Time | Speed |
|---|---|---|
tree.mjs, 1 thread | 3.4 s | 19 MiB/s |
parallel.mjs, 2 threads | 1.8 s | 36 MiB/s |
parallel.mjs, 4 threads | 1.3 s | 50 MiB/s |
parallel.mjs, 8 threads | 1.4 s | 47 MiB/s |
parallel.mjs, 32 threads | 2.1 s | 30 MiB/s |
@noble/hashes, 1 thread (optimized JavaScript) | 1.0 s | 64 MiB/s |
Two threads nearly doubled the speed, as the tree promises. Beyond four, our simple version got slower, and the reasons are worth knowing because they apply to any parallel hashing. Each new worker starts cold: it loads the modules and runs unoptimized code until the JavaScript engine compiles it, and that start-up cost doesn’t shrink as the worker’s share of the input does. Each worker also gets a copy of its slice of the input. Production implementations avoid both with a pool of long-lived threads that read the input in place. The official Rust implementation uses the Rayon thread pool, and its b3sum command-line tool memory-maps files, so no thread copies anything.
From Python, the official implementation’s threading is one argument:
# threads.py: the official Rust implementation from Python (pip install blake3).
import blake3, hashlib
data = bytes(i % 251 for i in range(1 << 20)) * 256 # 256 MiB
one = blake3.blake3(data).hexdigest() # one thread, but SIMD across chunks
many = blake3.blake3(data, max_threads=blake3.blake3.AUTO).hexdigest() # all CPU threads
print(one == many) # True: the tree's shape is fixed, so the thread count can't change the hash
print(hashlib.sha256(data).hexdigest()[:16]) # SHA-256 has no tree, so it can only use one coreParallelism across SIMD lanes#
Threads are the obvious kind of parallelism. The less obvious kind, and the one that makes single-threaded BLAKE3 faster than SHA-256, is SIMD: one instruction operating on several values at once. An AVX2 register holds 256 bits, which is eight 32-bit words. An AVX-512 register holds sixteen.
BLAKE3 uses those lanes in two ways. Within a single compression, the four columns (and then the four diagonals) can be mixed with one set of 4-wide vector instructions, the same technique BLAKE2 uses. That helps a little. The big gain comes from hashing several chunks at once, one per lane:
AVX2: 8 lanes, one chunk per lane, 16 blocks in step
Each column is one step: the same instructions compress block n of all eight chunks at once. The highlighted column is block 5.
To do that, the implementation transposes the data. Instead of one register holding four words of one state, register i holds word i of eight different states. Then the G function runs exactly as written above, except every addition, XOR, and rotation is a vector instruction that updates eight chunks at once. The official implementation picks the widest version the CPU supports at runtime: SSE2, SSE4.1, NEON (4 lanes), AVX2 (8 lanes), or AVX-512 (16 lanes). AVX-512 even has a vector rotate instruction, whereas AVX2 constructs rotations using shifts and byte shuffles.
The same trick works for parent nodes: all the parents on one level of the tree are independent, so they’re compressed in batches too. And it works only because chunks are independent. SHA-256 can’t do this for a single message, because block n can’t start until block n − 1 is done.
That also explains the main limit. A single 1 KiB chunk is a chain of 16 compressions, so inputs of one chunk or less get no multi-lane speed-up at all. The benefit grows with the number of chunks, and an AVX2 machine needs 8 chunks (8 KiB) to fill its lanes, as the benchmarks below show.
Benchmarks#
We measured the official implementation (the blake3 1.0.11 Python package, which wraps the Rust crate) against Python’s hashlib (OpenSSL) in Python 3.14 in Docker. The CPU was an Intel Core i9-13900K, which has AVX2 but not AVX-512, and the SHA extensions that accelerate SHA-1 and SHA-256 in hardware. Docker Desktop had 32 CPUs (the chip’s 32 hardware threads) and 32 GB of RAM. BLAKE3, SHA-256, and BLAKE2b were measured in two runs, which agreed within 6%:
| Algorithm | Speed, 1 GiB input |
|---|---|
| BLAKE3, all threads | 41–44 GiB/s |
| BLAKE3, 1 thread | 4.9 GiB/s |
| SHA-1 (hardware-accelerated) | 2.7 GiB/s |
| SHA-256 (hardware-accelerated) | 2.4 GiB/s |
| BLAKE2b | 1.2 GiB/s |
| MD5 | 1.1 GiB/s |
| SHA-512 | 1.1 GiB/s |
| BLAKE2s | 0.8 GiB/s |
| SHA3-256 | 0.7 GiB/s |
On one thread, BLAKE3 was twice as fast as SHA-256, even though SHA-256 had dedicated hardware instructions and BLAKE3 used only general vector instructions. It was six times as fast as BLAKE2s, whose compression function it shares: that’s the SIMD lanes plus the 7 rounds instead of 10.
Scaling with threads
| Threads | Speed, 1 GiB input | Speed-up |
|---|---|---|
| 1 | 4.9 GiB/s | 1× |
| 2 | 9.4 GiB/s | 1.9× |
| 4 | 18.5 GiB/s | 3.8× |
| 8 | 31.7 GiB/s | 6.5× |
| 16 | 38.6 GiB/s | 7.9× |
| 32 | 38.8 GiB/s | 8.0× |
Up to 4 threads, the speed-up is almost perfect. It then levels off at about 39 GiB/s. Other limits take over there: this CPU has 8 fast performance cores and 16 slower efficiency cores, and at these speeds reading the input from memory becomes the bottleneck. For comparison, hashing 1 GiB took SHA-256 about 0.4 seconds, and BLAKE3 with all threads about 0.025 seconds: 17 to 18 times faster.
Input size matters
| Input size | SHA-256 | BLAKE3, 1 thread | BLAKE3, all threads |
|---|---|---|---|
| 64 bytes | 169 MiB/s | 192 MiB/s | 160 MiB/s |
| 1 KiB (1 chunk) | 1,385 MiB/s | 1,051 MiB/s | 968 MiB/s |
| 8 KiB (8 chunks) | 2,243 MiB/s | 4,544 MiB/s | 4,229 MiB/s |
| 128 KiB | 2,492 MiB/s | 5,642 MiB/s | 211 MiB/s |
| 1 MiB | 2,487 MiB/s | 5,688 MiB/s | 559 MiB/s |
| 8 MiB | 2,488 MiB/s | 5,307 MiB/s | 3,899 MiB/s |
| 16 MiB | 2,481 MiB/s | 5,369 MiB/s | 8,956 MiB/s |
| 64 MiB | 2,485 MiB/s | 4,934 MiB/s | 25,316 MiB/s |
This table shows the tree’s two kinds of parallelism switching on:
- Tiny inputs are dominated by the cost of the function call itself, for every algorithm.
- At 1 KiB, SHA-256 wins. One chunk is a chain of 16 compressions with no other chunk to share the vector lanes, so BLAKE3 has nothing to parallelize, while SHA-256 has its hardware instructions.
- At 8 KiB, BLAKE3 is twice as fast. Eight chunks fill the eight AVX2 lanes. From there, it stays near 5 GiB/s on a single thread.
- Threads only pay off for large inputs. With this package, multithreading was far slower than a single thread from 16 KiB up to 8 MiB, because coordinating threads costs more than they save. It only won from 16 MiB. If you hash many small or medium inputs, use one thread per input instead, and hash different inputs on different threads.
Extendable output and the three modes#
BLAKE3’s output defaults to 32 bytes, but it’s an extendable-output function (XOF): you can ask for any length. The root node is compressed again, with the output-block counter set to 0, 1, 2, and so on, and each compression yields 64 more bytes, using all 16 words of the compression output. Shorter outputs are prefixes of longer ones, and the output blocks can also be computed in parallel.
The same tree supports three modes, separated by flags so that they can never produce each other’s outputs:
# modes.py: BLAKE3's three modes and its extendable output.
import blake3, secrets
data = b"the same input"
# 1. Plain hash, with as much output as you ask for. Shorter outputs are prefixes of longer ones.
print(blake3.blake3(data).hexdigest(length=64)[:64] == blake3.blake3(data).hexdigest()) # True
# 2. Keyed hash: a MAC. The 32-byte key replaces the IV, and the KEYED_HASH flag is set. No HMAC needed.
key = secrets.token_bytes(32)
tag = blake3.blake3(data, key=key).digest()
print(tag != blake3.blake3(data).digest()) # True
# 3. Key derivation: a hard-coded, unique context string, then the secret input material.
ctx = "example.com 2026-11-09 session keys v1"
k1 = blake3.blake3(b"shared secret", derive_key_context=ctx).digest()
k2 = blake3.blake3(b"shared secret", derive_key_context=ctx + " (other)").digest()
print(k1 != k2) # True: a different context gives an unrelated key- Keyed hashing replaces the IV with a 32-byte key. Because BLAKE3 has no length-extension weakness, it’s a secure MAC on its own, whereas SHA-256 requires the HMAC construction.
- Key derivation first hashes a context string, which should be hard-coded, globally unique, and specific to the application, into a key, and then hashes the secret material with it. Different contexts give independent keys, even from the same secret.
When not to use BLAKE3#
- Passwords. BLAKE3 is designed to be fast, which is exactly wrong for password hashing. Use Argon2id, scrypt, or bcrypt, which are slow and memory-hard on purpose.
- Compliance. BLAKE3 isn’t a NIST standard. If a regulation such as FIPS 140 applies, use SHA-2 or SHA-3.
- Compatibility. If a protocol, file format, or API specifies SHA-256 (as most certificates, JWT algorithms, and package managers do), you must use SHA-256.
- Small inputs on hardware with SHA extensions. For many tiny hashes, such as keys in a hash table or short messages, BLAKE3’s tree gives no advantage, and in our test SHA-256 was faster at 1 KiB.
Where it shines is in large data: file checksums, deduplication, content-addressed storage, build caches, and download verification. Our hash generator computes BLAKE3, SHA-256, and others for text and files in the browser.
FAQ#
Is BLAKE3 secure with only 7 rounds?
Its designers target 128-bit security, the same as SHA-256 for collisions. Published cryptanalysis of BLAKE2 and BLAKE3 reaches far fewer than 7 rounds, so the margin is considered comfortable. BLAKE3 is younger and less studied than SHA-2, which is a fair reason to prefer SHA-2 where nothing else decides.
Does the hash depend on how many threads or which CPU I use?
No. The input length fixes the tree’s shape, so every implementation, single-threaded or not, with or without SIMD, gives the same output. Our tests confirmed that for 2–16 threads.
Why is the chunk size 1 KiB?
It’s a trade-off. Bigger chunks would need fewer parent nodes but would make more inputs too small to parallelize. Smaller chunks would make parent nodes, which are pure overhead, a larger share of the work. At 1 KiB, parents add about one compression per 16.
Can I use BLAKE3 in the browser?
Not through Web Crypto, which doesn’t include it. Pure-JavaScript versions, such as @noble/hashes, work everywhere, at about 64 MiB/s in our test, and WebAssembly builds of the official implementation are faster. For parallelism, the same subtree splitting shown above works with Web Workers.
Is BLAKE3 the same as BLAKE2 with a tree?
Close. BLAKE2 had an optional tree mode that implementations rarely supported, so hashes from it weren’t interchangeable. BLAKE3 makes the tree mandatory, cuts the rounds from 10 to 7, uses only 32-bit words (BLAKE2b uses 64-bit), and adds the XOF and derive-key modes.
Try it in your browser
- Hash Generator: compute BLAKE3 next to SHA-256, SHA-3 and others for text or files of any size, in your browser.