Stream Ciphers

Work in progress. This note is still being written and incomplete.

Models plaintext as a bit stream, combined with a random keystream via a reversible operation, bitwise XOR.

ci=miki,mi=cikic_i = m_i \oplus k_i, \quad m_i = c_i \oplus k_i

Both encryption and decryption must generate the identical keystream kik_i.

  • No error propagation
    A bit error in a transmitted ciphertext bit corrupts only the corresponding decrypted plaintext bit.
  • Efficient for real-time data (audio, video streaming) when the keystream generation algorithm is fast.

Stream Encryption Scheme

A stream cipher is already a complete encryption scheme. It needs no mode of operation.

  • Arbitrary length
    The keystream is generated to any length and XORed with the plaintext bit by bit. No padding, and ciphertext length equals plaintext length.
  • Randomisation
    The keystream generator takes an initialization vector alongside the key, so the same plaintext under the same key gives different ciphertext for different IVs.

Keystream Generator

A function that generates a stream of pseudorandom bits k0,k1,k2,k_0, k_1, k_2, \dots from a short secret key. Used in practical stream ciphers.

A secure keystream generator must satisfy:

  • Long period
    The period NN of the repetition of the sequence, where ki=ki+Nk_i = k_{i+N}, must be large for all ii.
  • Pseudo-randomness
    The sequence must pass statistical random number tests.
  • Unpredictability
    Computationally infeasible to determine the full keystream from any part of it, of any length.

Malleability

An encryption scheme is malleable iff an attacker can transform a ciphertext of an unknown message mm into a ciphertext of a related message f(m)f(m), without knowing mm or the key.

The XOR-combiner stream cipher is malleable. Given c=mkc = m \oplus k, the attacker chooses a mask Δ\Delta and sends c=cΔc' = c \oplus \Delta.

ck=(mkΔ)k=mΔc' \oplus k = (m \oplus k \oplus \Delta) \oplus k = m \oplus \Delta

The plaintext changes by exactly Δ\Delta, an attacker-chosen relation, with no other change. Flipping bit ii of cc flips bit ii of the plaintext.

Malleability here follows from 2 properties together, not from the keystream being random or pseudorandom.

  • The combiner is XOR, which is linear and known to the attacker.
  • No integrity check covers the ciphertext.

Removing either property breaks the attack. A self-synchronising stream cipher feeds past ciphertext bits into the keystream, so a flipped bit garbles a run of following plaintext instead of one clean bit.

A scheme is non-malleable iff any tampering with the ciphertext makes it decrypt to a value unrelated to mm, or makes decryption reject.

Breaking the Cipher

Reusing a keystream kk across 2 messages m1m_1 and m2m_2 produces ciphertexts c1=m1kc_1 = m_1 \oplus k and c2=m2kc_2 = m_2 \oplus k.

c1c2=(m1k)(m2k)=m1m2c_1 \oplus c_2 = (m_1 \oplus k) \oplus (m_2 \oplus k) = m_1 \oplus m_2

The keystream cancels. An attacker holding c1c_1 and c2c_2 recovers m1m2m_1 \oplus m_2 without kk. Plaintext redundancy separates it into m1m_1 and m2m_2. Knowing one plaintext gives the other directly.

Knowing one plaintext also recovers the keystream, k=c1m1k = c_1 \oplus m_1. Any further message under the same kk can then be forged. The attacker picks mm' and sends c=mkc' = m' \oplus k, which decrypts to mm', an existential forgery.

Examples

One-Time Pad

To encrypt a message mm (of length nn), a keystream kk (of length nn) is generated that is random and never reused. The message bits are XORed with the keystream bits to produce the ciphertext.

Impractical as it requires a key as long as the message and never reused, but applications need a short key and reuse it across many messages.

Written by September 16, 2026 3 min read
Was this helpful?