Skip to content
uencoder

Stream Cipher

A stream cipher encrypts byte by byte or bit by bit, XORing a keystream with the plaintext; it needs no padding and suits real-time and streaming data.

Purpose

It provides efficient encryption without block alignment, fitting network streams and continuous data.

Mechanism

Encryption is C_i = P_i ⊕ S_i, where S is the keystream generated from the key and nonce/counter via a PRG; decryption is identical (XOR is self-inverse). Security relies on the pseudorandomness of the keystream and nonce uniqueness. Common constructions: ARX-based (ChaCha), LFSR-based, and AES-CTR mode.

Use cases

  • TLS 1.3 (ChaCha20-Poly1305)
  • Real-time audio/video encryption
  • WireGuard VPN
  • Low-resource embedded encryption

Examples

  • Input
    key + nonce → keystream
    Output
    C = P ⊕ S

    The nonce must never repeat

Common errors

Encrypting two messages with the same key+nonce (a two-time pad)
Use a unique nonce or counter per message

Related terms

Related tools

References