# Stream cipher

In cryptography, a**stream cipher**is a cipher in which the input data are encrypted one bit (sometimes one byte) at a time. They are sometimes called

*state ciphers*since the encryption of a bit is dependent on the current state. Stream ciphers represent a line of cipher development different from block ciphers although there are mathematical transformations that convert stream ciphers into block ciphers and vice versa. Stream ciphers typically execute at a higher speed in hardware than block ciphers.

Most stream ciphers consist of a pseudorandom number generator (PRNG) and an XOR gate. The PRNG is initialized with a key, and outputs a sequence of bits known as a *keystream*. Encryption consists of XORing the plaintext bits with the corresponding bits of the keystream; decryption consists of XORing the ciphertext bits with the corresponding keystream bits. This means that a single bit of ciphertext error results in a single bit of plaintext error; this property is useful when the transmission error rate is high. However, a stream cipher is susceptible to bit-fiddling attacks — dropping a bit will result in loss of data. Some ciphers, called *self-synchronizing stream ciphers*, use several previous ciphertext bits to compute the keystream (as opposed to *synchronous stream ciphers*, in which the keystream is generated independently of the plaintext and the ciphertext). A single-bit error then turns into a long burst of garble, but the cipher will eventually recover from a lost bit after the erroneous bit falls off the shift register.

Stream ciphers are used in applications where plaintext comes in quantities of unknowable length, for example, a secure wireless connection. If a block cipher were to be used in this type of application, considerable bandwidth would end up being wasted by padding, since block ciphers cannot work on blocks shorter than their block size. For example, if a 64-bit block cipher received separate 32-bit bursts of plaintext, half of the data transmitted would be padding. Stream ciphers eliminate this by operating on the smallest unit that can be transmitted (usually bytes).

Keystream generators are often constructed using linear feedback shift registers.

A well-known stream cipher is RC4; others include A5/1, A5/2, Chameleon, FISH, HELIX. ISAAC, Panama, Pike, SEAL, SOBER and WAKE.