liveBook · Manning

Keystream

As explained in Real-World Cryptography

A keystream is the sequence of pseudorandom bytes generated by a stream-encryption construction and XORed with plaintext or ciphertext.

A keystream is a sequence of pseudorandom bytes used like a one-time masking stream: XOR it with plaintext to produce ciphertext, or with ciphertext to recover plaintext. Encryption preserves length, so no padding is required. section 4.5.3 section 4.5.2

A typical keystream-based encryption flow is:

The dangerous shortcut

Reusing a nonce under the same key recreates the same keystream. XORing the two resulting ciphertexts cancels that stream and reveals the XOR of the two plaintexts, creating a serious confidentiality failure. section 4.5.2 section 4.5.3

Figure 4.18 ChaCha20 works by taking a symmetric key and a unique nonce. It then generates a keystream that is XORed with the plaintext (or ciphertext) to produce the ciphertext (or plaintext). The encryption is length-preserving as the ciphertext and the plaintext are of the same length.

Trace how a symmetric key and unique nonce generate a keystream, and how XOR reversibly connects plaintext and ciphertext. section 4.5.3

Figure 4.19 ChaCha20’s keystream is created by calling an internal block function until enough bytes are produced. One block function call creates 64 bytes of random keystream.

Inspect how ChaCha20 builds a longer keystream from repeated 64-byte block-function outputs. section 4.5.3

How Real-World Cryptography covers it

How deep it goes
Details generation, truncation, XOR, and nonce-reuse failure, while stopping short of formal security proofs.
Examples
Uses AES-CTR and ChaCha20 flows, including nonce-and-counter inputs, repeated block generation, truncation, and XOR.
What you can do after
Understand how to trace keystream encryption and diagnose nonce reuse as a confidentiality failure.
How it connects
Connects stream ciphers, XOR, nonces, counters, AES-CTR, ChaCha20, AES-GCM, and authenticated encryption.

Also explained in

Compare how 2 books explain keystream →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Real-World Cryptography. The section links point to the parts of the book it draws on.