Stream Ciphers

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

ci=mi⊕ki,mi=ci⊕kic_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.

Key Space

The key space is determined by the keystream generator, not by the message length. A generator with a uniformly selected bb-bit secret key has 2b2^b candidate keys. The initialization vector is public and does not enlarge this space.

For a one-time pad protecting an nn-bit message, the key is an independently random nn-bit string. Its key space has 2n2^n members. Each key may encrypt only 1 message.

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=m⊕kc = m \oplus k, the attacker chooses a mask Δ\Delta and sends c′=c⊕Δc' = c \oplus \Delta.

c′⊕k=(m⊕k⊕Δ)⊕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=m1⊕kc_1 = m_1 \oplus k and c2=m2⊕kc_2 = m_2 \oplus k.

c1⊕c2=(m1⊕k)⊕(m2⊕k)=m1⊕m2c_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 m1⊕m2m_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=c1⊕m1k = c_1 \oplus m_1. Any further message under the same kk can then be forged. The attacker picks m′m' and sends c′=m′⊕kc' = m' \oplus k, which decrypts to m′m', 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 October 27, 2026 3 min read
Was this helpful?