Stream cipher

A symmetric cipher that combines plaintext with a pseudorandom keystream one bit or byte at a time, usually by XOR, so it needs no padding and suits data of unpredictable length.

A stream cipher is a symmetric cipher that generates a pseudorandom keystream from a key and a nonce or initialisation vector, then combines it with the plaintext one bit or byte at a time, usually with the exclusive-or (XOR) operation. It needs no padding and suits real-time traffic. ChaCha20, specified in RFC 8439, is a current example. RC4, once used in WEP and TLS, is prohibited in TLS by RFC 7465 because of keystream biases.

The contrast is with a block cipher, which encrypts fixed-size blocks, although counter mode turns a block cipher into a keystream generator. The one-time pad is the ideal that stream ciphers approximate: a truly random keystream as long as the message, used once. The rule that follows is that a keystream must not be reused. If two messages are encrypted with the same key and nonce, combining the two ciphertexts cancels the keystream and leaves the two plaintexts combined with each other. Keystream reuse was one of the flaws in WEP.

Exam relevance: questions in this area tend to turn on bit-by-bit or byte-by-byte operation, on XOR with a keystream, and on the danger of reusing a key and nonce. Candidates are expected to link stream ciphers to the one-time pad and to recognise RC4 as a deprecated example.