Field Guide · term

Also known as: key stream

A keystream is the sequence of pseudo-random bits or bytes a stream cipher derives from its key, which is then combined with the plaintext — almost always by XOR — to produce ciphertext.1 Recovering the data requires regenerating the identical keystream, which needs the key.

key keystream plaintext ciphertext
The keystream is XORed with the data; decryption regenerates the same stream and XORs again.

How it works

A stream cipher uses the key (often together with a per-message nonce or initialisation vector) to seed a generator that emits a long, statistically random keystream. Encryption combines this stream with the plaintext bit by bit or byte by byte, typically with XOR; decryption regenerates the identical stream and XORs again, because XOR is its own inverse. Crucially the keystream depends only on the key and nonce, not on the plaintext — so the sender and receiver, holding the same secrets, produce the same stream independently and never have to transmit it.

Variants

Keystreams are generated two broadly different ways. A dedicated stream cipher such as RC4 has an internal state (RC4’s is a 256-byte permutation) that it stirs to emit each byte. Alternatively, a block cipher run in a stream mode — output feedback (OFB) or counter (CTR) — repeatedly encrypts a counter or feedback value to manufacture keystream from a block primitive like DES or AES. Either way the result is the same over the air: a pseudo-random stream XORed onto the data. The design tension is the nonce/IV. A synchronous cipher generates keystream independent of the ciphertext, so a lost bit desynchronises everything after it; a self-synchronising cipher derives each keystream symbol partly from recent ciphertext, so it recovers after an error at the cost of propagating that error briefly.

In practice

The cardinal rule is that a keystream must never be reused under the same key/nonce. If two messages are XORed with the same keystream, an attacker who XORs the two ciphertexts cancels the keystream entirely and is left with the XOR of the two plaintexts — a “two-time pad” that often unravels with simple analysis. Systems avoid this by mixing a fresh IV, frame counter, or message number into the seed for every transmission; a cipher that reuses keystream (as some early deployments of RC4 did) is broken regardless of key length. This is also why the one-time pad is unbreakable only when its keystream is truly random and used exactly once. As always, the secrecy lives in the key, not in the generator, in line with Kerckhoffs’s principle.

Relevance to SDR

DMR “Enhanced Privacy” protects voice with the RC4 keystream; P25 uses DES or DES-XL and AES in OFB, which is a block cipher used as a keystream generator; and TETRA TEA is likewise a stream construction. For GopherTrunk this draws a sharp line: a keystream produced from a secret key cannot be reproduced without that key, so the voice is unrecoverable — whereas a publicly defined scrambling or whitening sequence carries no secret and can simply be undone. Knowing which one a system uses tells you immediately whether decoding is even possible.

Sources

  1. Keystream — Wikipedia, for the key-derived pseudo-random stream XORed with plaintext and the danger of reuse. 

See also