Stream cipher

In cryptography, a **stream cipher** is a symmetric key cipher where plaintext bits are combined with a pseudorandom cipher bit stream (keystream) using an exclusive-or (xor) operation. In a stream cipher the Plaintext digits are encrypted one at a time, and the transformation of successive digits varies during the encryption **state**. An alternative name is a **state cipher**, as the encryption of each digit is dependent on the current state. In practice, the digits are typically single bits or bytes.

Stream ciphers represent a different approach to symmetric encryption from block ciphers. Block ciphers operate on large blocks of fixed length. Stream ciphers typically execute at a higher speed than block ciphers and have lower hardware requirements. However, stream ciphers can have serious security problems if used incorrectly; in particular, the same starting state must never be used twice.

A stream cipher makes use of a much smaller and more convenient cryptographic key, for example 128 bits keys. Based on this key, it generates a pseudorandom keystream which can be combined with the plaintext digits in a similar way to the one-time pad encryption algorithm. However,  because the keystream is pseudorandom, and not truly random, the security associated with the one-time pad cannot be applied and it is quite possible for a stream cipher to be completely insecure.

## Types of stream ciphers

A stream cipher generates successive elements of the keystream based on an internal state. This state is updated in two ways:
1. If the _state_ changes independently of the plaintext or ciphertext messages, the cipher is classified as a **synchronous** stream cipher.
1. If the _state_ is updated based on previous changes of the ciphertext digits, the cipher is classified as a **self-synchronising** stream ciphers.

### Synchronous stream ciphers

In a **synchronous stream cipher** a stream of pseudo-random digits is generated independently of the plaintext and ciphertext messages, and then combined with the plaintext (to encrypt) or with the ciphertext (to decrypt). In the most common form, binary digits(bits) are used, and the keystream is combined with the plaintext using the exclusive or operation (XOR). This is termed a **binary additive stream cipher**.

In a **synchronous stream cipher**, the sender and receiver must be synchronous for decryption to be successful. If digits are added or removed from the message during transmission, synchronisation is lost. To restore synchronisation, various offsets can be tried systematically to obtain the correct decryption. Another approach is to mark the ciphertext with markers at regular points in the output.

If, however, a digit is corrupted in transmission, rather than added or lost, only a single digit in the plaintext is affected and the error does not spread to other parts of the message. This property is useful when the transmission error rate is high; however, it makes it less likely that the error would be detected without further mechanisms. Moreover, because of this property, synchronous stream ciphers are very susceptible to active attacks — if an attacker can change a digit in the ciphertext, he might be able to make predictable changes to the corresponding plaintext bit; for example, flipping a bit in the ciphertext causes the same bit to be flipped(Toggled) in the plaintext.

### Self-synchronizing stream ciphers

**Self-synchronizing stream ciphers** is another technique that uses part of the previous _N_ ciphertext digits to compute the keystream. Such schemes are known also as **asynchronous stream ciphers** or **ciphertext autokey (CTAK)**. The idea of self-synchronization was patented in 1946, and has the advantage that the receiver will automatically synchronise with the keystream generator after receiving _N_ ciphertext digits, making it easier to recover if digits are dropped or added to the message stream. Single-digit errors are limited in their effect, affecting only up to _N_ plaintext digits. It is somewhat more difficult to perform active attacks on self-synchronising stream ciphers rather than synchronous counterparts.

An example of a self-synchronising stream cipher is a block cipher in cipher-feedback mode (CFB).

## Linear feedback shift register-based stream ciphers

Binary stream ciphers are often constructed using linear feedback shift registers (LFSRs) because they can be easily implemented in hardware and can be quickly analysed mathematically. However, the use of LFSRs only is insufficient to provide good security. Various schemes have been designed to increase the security of LFSRs.

### Non-linear combining functions

Because LFSRs are inherently linear, one technique for removing the linearity is to feed the outputs of a group of parallel LFSRs into a non-linear Boolean function to form a _combination generator_. Various properties of such a _combining function_ are important for ensuring the security of the resultant scheme, for example, in order to avoid correlation attacks.

### Clock-controlled generators

Normally LFSRs are stepped regularly. One technique to introducing non-linearity is to have the LFSR clocked irregularly, controlled by the output of a second LFSR. Such generators include the stop-and-go generator, the alternating step generator and the shrinking generator.

The stop-and-go generator (Beth and Piper, 1984) consists of two LFSRs. One LFSR is clocked if the output of a second is a "1", otherwise it repeats its previous output. This output is then (in some versions) combined with the output of a third LFSR clocked at a regular rate.

The shrinking generator uses a different technique. Two LFSRs are used, both clocked regularly in the following way:
1. If the output of the first LFSR is "1", the output of the second LFSR becomes the output of the generator.
1. If the output of the first LFSR "0", the output of the second is discarded, and no bit is output by the generator.

This technique suffers from timing attacks on the second generator, since the speed of the output is variable in a manner that depends on the second generator's state.  This can be improved by buffering the output.

### Filter generator

Another approach to improving the security of an LFSR is to pass the entire state of a single LFSR into a non-linear _filtering function_.

## Other designs

Instead of a linear driving device, one may use a nonlinear update function. For example, Klimov and Shamir proposed triangular functions (T-Functions) with a single cycle on n bit words.

## Security

To be secure, the period of the keystream (the number of digits output before the stream repeats itself)  needs to be large enough. If the sequence repeats, then the overlapping ciphertexts can be aligned against each other _"in depth"_, and there are techniques which allow extraction of the plaintext form ciphertexts generated using these methods.

## Usage

Stream ciphers are often used in applications where plaintext comes in quantities of unknowable length as in secure wireless connections. If a block cipher were to be used in this type of application, the designer would need to choose either transmission efficiency or implementation complexity, since block ciphers cannot directly work on blocks shorter than their block size. For example, if a 128-bit block cipher received separate 32-bit bursts of plaintext, three quarters of the transmitted data need padding. Block ciphers must be used in ciphertext stealing or residual block termination mode to avoid padding, while stream ciphers eliminate this issue by operating on the smallest transmitted unit (usually bytes).

Another advantage of stream ciphers in military cryptography is that the cipher stream can be generated by an encryption device that is subject to strict security measures then fed to other devices, e.g. a radio set, which will perform the xor operation as part of their function.  The other device can be designed for used in less securely environments.

RC4 is the most widely used stream cipher in software; others include:
A5/1,
A5/2,
Chameleon,
FISH,
Helix,
ISAAC,
MUGI,
Panama,
Phelix,
Pike,
SEAL,
SOBER,
SOBER-128 and
WAKE.

## Comparison Of Stream Ciphers

|rowspan=2|Stream Cipher|rowspan=2|Creation Date|rowspan=2|Speed (cycles/byte)|colspan=3|(bits)|colspan=2|Attack||||||
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
||A5/1|1989|style="background:#ffdddd;"|Voice (W<sub>phone</sub>)|style="background:#ffdddd;"|54|style="background:#ff99dd;"|114|style="background:#ddffff;"|64|style="background:#ffdddd;"|Active KPA OR KPA Time-Memory Tradeoff|style="background:#ffdddd;"|~2 seconds OR 2<sup>39.91</sup>|
||A5/2|1989|style="background:#ffdddd;"|Voice (W<sub>phone</sub>)|style="background:#ffdddd;"|54|style="background:#ff99dd;"|114|style="background:#ddffff;"|64?|style="background:#ffdddd;"|Active|style="background:#ffdddd;"|4.6 milliseconds|
||FISH|1993|style="background:#ffffdd;"|Quite Fast (W<sub>soft</sub>)|style="background:#ddffdd;"|Huge|||style="background:#ffdddd;"|Known-plaintext attack|style="background:#ffdddd;"|2<sup>11</sup>|||
||Grain|Pre-2004|style="background:#ffffdd;"|Fast|style="background:#ffdddd;"|80|style="background:#ddffff;"|64|style="background:#ddffff;"|160|style="background:#ffffdd;"|Key-Derivation|style="background:#ffffdd;"|2<sup>43</sup>|
||HC-256|Pre-2004|style="background:#ffffdd;"|4 (W<sub>P4</sub>)|style="background:#ddffdd;"|256|style="background:#ff99dd;"|256|style="background:#ff99dd;"|65536|||||
||ISAAC|1996|style="background:#ffdddd;"|2.375 (W<sub>64-bit</sub>) - 4.6875 (W<sub>32-bit</sub>)|style="background:#ddffdd;"|8-8288 usually 40-256|style="background:#ddffff;"|N/A|style="background:#ff99dd;"|8288|style="background:#ffffdd;"|(2006) First-round Weak-Internal-State-Derivation|style="background:#ffffdd;"|4.67×10<sup>1240</sup> (2001)|
||MUGI|1998-2002||style="background:#ffffdd;"|128|style="background:#ff99dd;"|128|style="background:#ddffff;"|1216|style="background:#ddffdd;"|N/A (2002)|style="background:#ddffdd;"|~2<sup>82</sup>||
||PANAMA|1998|style="background:#ddffdd;"|2|style="background:#ddffdd;"|256|style="background:#ff99dd;"|128?|style="background:#ddffff;"|1216?|style="background:#ddffdd;"|Hash Collisions (2001)|style="background:#ddffdd;"|2<sup>82</sup>|
||Phelix|Pre-2004|style="background:#ffdddd;"|up to 8 (W<sub>x86</sub>)|style="background:#ddffdd;"|256 + a 128-bit Nonce|style="background:#ff99dd;"|128?||style="background:#ffdddd;"|Differential (2006)|style="background:#ffdddd;"|2<sup>37</sup>||
||Pike|1994|style="background:#ddffdd;"|0.9 x FISH (W<sub>soft</sub>)|style="background:#ddffdd;"|Huge|||style="background:#ddffdd;"|N/A (2004)|style="background:#ddffdd;"|N/A (2004)|||
||Py|Pre-2004|style="background:#ddffdd;"|2.6|style="background:#ddffdd;"|8-2048? usually 40-256?|style="background:#ddffff;"|64|style="background:#ff99dd;"|8320|style="background:#ffffdd;"|Cryptanalytic Theory (2006)|style="background:#ffffdd;"|2<sup>75</sup>|
||Rabbit|2003-Feb|style="background:#ddffdd;"|3.7(W<sub>P3</sub>)-9.7(W<sub>ARM7</sub>)|style="background:#ffffdd;"|128|style="background:#ddffff;"|64|style="background:#ddffff;"|512|style="background:#ddffdd;"|N/A (2006)|style="background:#ddffdd;"|N/A (2006)|
||RC4|1987|style="background:#ffdddd;"|Impressive|style="background:#ddffdd;"|8-2048 usually 40-256|style="background:#ddffff;"|8|style="background:#ddffff;"|2064|style="background:#ffdddd;"|Shamir Initial-Bytes Key-Derivation OR KPA|style="background:#ffdddd;"|2<sup>13</sup> OR 2<sup>33</sup>|
||Salsa20|Pre-2004|style="background:#ddffdd;"|4.24 (W<sub>G4</sub>) - 11.84 (W<sub>P4</sub>)|style="background:#ddffdd;"|128 + a 64-bit Nonce|style="background:#ff99dd;"|512|style="background:#ddffff;"|512 + 384 (key+IV+index)|style="background:#ddffdd;"|Differential (2005)|style="background:#ddffdd;"|N/A (2005)|
||Scream|2002|style="background:#ffffdd;"|4 - 5 (W<sub>soft</sub>)|style="background:#ffffdd;"|128 + a 128-bit Nonce|style="background:#ddffff;"|32?|style="background:#ddffff;"|64-bit round function|||||
||SEAL|1997|style="background:#ddffdd;"|Very Fast (W<sub>32-bit</sub>)||style="background:#ddffff;"|32?||||||||
||SNOW|Pre-2003|style="background:#ddffdd;"|Very Good (W<sub>32-bit</sub>)|style="background:#ffffdd;"|128 OR 256|style="background:#ddffff;"|32|||||||
||SOBER-128|2003||style="background:#ffdddd;"|up to 128|||style="background:#ffdddd;"|Message Forge|style="background:#ffdddd;"|2<sup>−6</sup>||||
||SOSEMANUK|Pre-2004|style="background:#ddffdd;"|Very Good (W<sub>32-bit</sub>)|style="background:#ffffdd;"|128|style="background:#ff99dd;"|128|||||||
||Trivium|Pre-2004|style="background:#ffffdd;"|4 (W<sub>x86</sub>) - 8 (W<sub>LG</sub>)|style="background:#ffdddd;"|80|style="background:#ff99dd;"|80|style="background:#ddffff;"|288|style="background:#ddffdd;"|Brute force attack (2006)|style="background:#ddffdd;"|2<sup>135</sup>|
||Turing|2000-2003|style="background:#ffdddd;"|5.5 (W<sub>x86</sub>)||style="background:#ff99dd;"|160||||||||
||VEST|2005|style="background:#ffdddd;"|42 (W<sub>ASIC</sub>) - 64 (W<sub>FPGA</sub>)|style="background:#ffffdd;"|Variable usually 80-256|style="background:#ff99dd;"|Variable usually 80-256|style="background:#ddffff;"|256 - 800|style="background:#ddffdd;"|N/A (2006)|style="background:#ddffdd;"|N/A (2006)|
||WAKE|1993|style="background:#ffffdd;"|Fast|||style="background:#ff99dd;"|8192|style="background:#ffdddd;"|CPA & CCA|style="background:#ffdddd;"|Vulnerable|||

## Related pages

- eSTREAM

## References

- Matt J. B. Robshaw, Stream Ciphers Technical Report TR-701, version 2.0, RSA Laboratories, 1995 (PDF) .
- Thomas Beth and Fred Piper, The Stop-and-Go Generator. EUROCRYPT 1984, pp 88–92.

## Other websites

- RSA technical report on stream cipher operation.
- Analysis of Lightweight Stream Ciphers (thesis by S. Fischer).