← Back to section · Foundations of Cryptography

Stream Ciphers and ChaCha20: Encryption Without Blocks

A stream cipher does not cut data into blocks; it generates a keystream as long as the plaintext and masks it byte by byte. ChaCha20 weaves that stream from additions, rotations, and XORs, becoming the best software answer where AES hardware acceleration is absent.

Published 22 November 2026 · 5 min read · PQ Frontier

Stream Ciphers and ChaCha20: Encryption Without Blocks
AI-generated site artwork
Video explainer · Symmetric encryption: blocks and modes

A block cipher cuts the world into 128-bit squares; a stream cipher sees only a river of bytes. Its idea descends from the oldest and most perfect cipher of all — the one-time pad: given a keystream as long as the plaintext, perfectly random and used exactly once, XORing it with the plaintext gives a ciphertext that is unbreakable in the information-theoretic sense. The one-time pad’s problem is that the key is as long as the message and cannot be distributed. The stream cipher’s compromise: seed a deterministic generator with a short key and let it produce a keystream that merely looks random. Security retreats from information-theoretic to computational, but practicality is won.

The keystream generator: the whole of a stream cipher

A stream cipher is almost nothing but its keystream generator. The generator takes a key and a public nonce; its internal state evolves step by step, continuously emitting keystream bytes. Encryption is XOR, decryption is XOR again — the two directions are perfectly symmetric and no separate “decryption circuit” is needed. The state’s evolution must be one-way and unpredictable: from any stretch of keystream, one must be able neither to work back to the internal state nor to predict the next byte.

This design route has historical detours. Early stream ciphers were mostly built on linear feedback shift registers (LFSRs); a single LFSR’s output is linear, and given enough keystream the Berlekamp–Massey algorithm recovers the entire state — the fall of mobile-telephony ciphers such as A5/1 is tied to this linear structure. Modern designs therefore moved to nonlinear combinations, feedback with carry, or a different road altogether: producing the keystream with a block cipher or permutation in counter mode. ChaCha20 is a variant of the latter idea — at bottom it is a function taking key, nonce, and counter as input and “washing” the input block into a full block of keystream.

The usage discipline of stream ciphers causes more incidents than the algorithms themselves. The same key and nonce must never be used twice: encrypt two messages under the same keystream, XOR the two ciphertexts, and the keystream cancels, leaving exactly the XOR of the two plaintexts — if one plaintext is known or guessable (protocol headers often are), the other falls with it. This is not a theoretical warning but an accident pattern that has erupted repeatedly in real systems. Managing nonce uniqueness is lesson one of stream cipher engineering.

ChaCha20: three operations weave a stream

ChaCha20, designed by Daniel J. Bernstein, is the refined successor of Salsa20. It arranges a 512-bit state as a 4×4 matrix of 32-bit words: eight words hold the key, four hold fixed constants (the ASCII of an English phrase — public “nothing-up-my-sleeve” constants), and the rest hold a counter and nonce. The core operation, the quarter round, uses only three operations: 32-bit addition, word-wise XOR, and rotation by fixed distances — collectively the ARX structure.

The ARX choice is deliberate. Addition supplies nonlinearity (carries make bit relationships nonlinear), rotation diffuses influence within a word, and XOR does the mixing. A quarter round acts on the four words of a column or a diagonal; column rounds and diagonal rounds alternate for 20 rounds (ten double rounds). Finally the iterated state is added word-wise to the initial state, yielding a 64-byte keystream block; the counter increments and the next block follows. That closing addition is not decoration: it makes the transformation irreversible, so a keystream block alone does not let an attacker run the state backwards.

ChaCha20 rose on two legs: performance and implementation safety. Early TLS relied on AES and RC4; after RC4 was broken and retired, phones and embedded devices without AES hardware acceleration paid for software AES in speed, and table-based implementations leaked timing side channels. ChaCha20 uses only register-friendly primitive operations, runs fast in software on ordinary CPUs, is naturally constant-time, and needs no secret-indexed table lookups — hence its place as a standard TLS 1.3 suite, usually paired with Poly1305 as the authenticated encryption ChaCha20-Poly1305. It proves the stream cipher idea is not obsolete: with modern design discipline, an old concept still delivers top-tier security and performance.

State size and rekeying: two more engineering lines

Beyond nonce discipline, stream ciphers have two easily overlooked engineering lines. One is the size of the internal state. A keystream generator’s security ultimately rests on its internal state space: too small a state invites time–data–memory trade-offs, where an attacker collects enough output and guesses the state offline; the rule of thumb is an internal state at least twice the key length, making such trade-offs unprofitable. ChaCha’s 512-bit state, and the several-hundred-bit states of many modern designs, are premiums paid for exactly this. The other line is rekeying and resynchronization: over a long connection one key cannot serve forever — keystream output under a single key has a cap (ChaCha20’s counter space, for instance, bounds the data under one key and nonce), so protocols must design key-update or nonce-rotation mechanisms giving every stretch of keystream a definite lifetime. These “lifecycle clauses” sit in inconspicuous corners of standards documents, yet they are the boundary where a stream cipher stops being an algorithm and becomes a system.

The boundary with block ciphers is dissolving

In practice the line between stream and block has long blurred: a block cipher in counter mode is a stream cipher, and ChaCha’s internals are a permutation-like block function. The real difference is not in shape but in usage semantics — a stream cipher writes “unique nonces, never reuse a keystream” into its own security definition, and protocol designers must honor it. Grasping this matters more than memorizing any particular algorithm’s parameters. A selection intuition, in passing: with AES hardware instructions, AES-GCM is usually faster; without them, ChaCha20-Poly1305 is the sound software default — their security goals are identical, and all that differs is which operations the computation is spent on.

Tags: Stream CipherChaCha20Keystream