A full ChaCha20 block operates on a 4×4 matrix of 32-bit words, 512 bits of state. The matrix is initialized with four constants, an eight-word key, a counter, and a three-word nonce:
"expa" "nd 3" "2-by" "te k" ← constants
key[0] key[1] key[2] key[3]
key[4] key[5] key[6] key[7]
counter nonce[0] nonce[1] nonce[2]
Each double-round applies the quarter-round to four columns, then four diagonals:
// Column round
QR(0, 4, 8, 12) QR(1, 5, 9, 13)
QR(2, 6, 10, 14) QR(3, 7, 11, 15)
// Diagonal round
QR(0, 5, 10, 15) QR(1, 6, 11, 12)
QR(2, 7, 8, 13) QR(3, 4, 9, 14)
Ten double-rounds (20 rounds total, 80 quarter-rounds) produce the final state. The original input is added back word-by-word, which makes the function non-invertible, a critical property for a stream cipher.
The quarter-round you built above is the only non-trivial building block. The rest is just wiring: choosing which four words from the matrix to feed into each QR call. In an ASIC or FPGA, you’d instantiate 4 quarter-round blocks and pipeline them across 20 cycles, or unroll all 80 for single-cycle throughput at the cost of area.
Designed to Avoid Hardware, Elegant in Hardware Anyway
Daniel Bernstein designed ChaCha20 in 2008 with a specific goal: a cipher that would be fast without dedicated hardware support. AES had just been blessed with AES-NI instructions on x86, but most of the world’s devices (mobile phones, IoT chips, older ARM cores) had no such luxury. ChaCha20’s ARX primitives (add, rotate, XOR) map to cheap, universally available instructions on any architecture, with no lookup tables and no timing side channels. That’s why Cloudflare and others adopted ChaCha20-Poly1305 for TLS: it’s the cipher that works fast in software on anything.
The interesting irony is what happens when you do put it in hardware anyway. The same simplicity that makes ChaCha20 fast in software, just three operations repeated 80 times, turns out to make it unusually elegant in gates. Four adders, four XOR trees, four barrel shifters: that’s the entire datapath. A cipher designed to escape the need for specialized hardware turns out to synthesize into some of the cleanest silicon you can build.
For comparison, AES was built for hardware from day one, and one round of AES requires a 256-entry lookup table (the S-box), Galois field multiplication, and multiple XOR trees just for the MixColumns step. That complexity is exactly why Intel had to build AES-NI into the CPU: without dedicated silicon, AES is slow and vulnerable to cache-timing attacks. ChaCha20 has no such baggage.