Stream Cipher
A stream cipher encrypts byte by byte or bit by bit, XORing a keystream with the plaintext; it needs no padding and suits real-time and streaming data.
Purpose
It provides efficient encryption without block alignment, fitting network streams and continuous data.
Mechanism
Encryption is C_i = P_i ⊕ S_i, where S is the keystream generated from the key and nonce/counter via a PRG; decryption is identical (XOR is self-inverse). Security relies on the pseudorandomness of the keystream and nonce uniqueness. Common constructions: ARX-based (ChaCha), LFSR-based, and AES-CTR mode.
Use cases
- TLS 1.3 (ChaCha20-Poly1305)
- Real-time audio/video encryption
- WireGuard VPN
- Low-resource embedded encryption
Examples
- Input
key + nonce → keystreamOutputC = P ⊕ SThe nonce must never repeat
Common errors
- Encrypting two messages with the same key+nonce (a two-time pad)
- Use a unique nonce or counter per message
Related terms
Block Cipher
A block cipher is a symmetric cipher that encrypts and decrypts fixed-length blocks (e.g., 128 bits) and requires a mode of operation to handle arbitrary-length data. GLOSSARY
ChaCha20
ChaCha20 is a stream cipher designed by Daniel Bernstein, built on ARX (add-rotate-XOR) operations, and is commonly paired with Poly1305 as an AEAD — a high-performance alternative to AES-GCM. GLOSSARY
RC4
RC4 is a stream cipher designed by Ron Rivest in 1987 — simple and fast, but with serious biases; it has been banned from TLS and other protocols. GLOSSARY
Nonce
A nonce (number used once) is a value used only once in encryption; similar to an IV but emphasizing uniqueness over randomness, it is common in stream ciphers and AEAD. GLOSSARY