Stream cipher
Adapted from Wikipedia · Adventurer experience
A stream cipher is a special way to keep messages secret. It uses a secret key to hide the message.
It works by mixing each part of the message, called plaintext, with a changing series of numbers. These numbers are known as the keystream. The mixing happens one part at a time, using a process called exclusive-or, or XOR for short.
The keystream looks random. It starts from a seed value, which acts like the secret key. This seed helps make the numbers needed to hide the message.
Stream ciphers are different from another way of hiding messages called block ciphers. Block ciphers work on bigger chunks of data all at once.
Stream ciphers are often faster and simpler to use, especially in devices with limited power. However, they can sometimes be broken if the same starting point, or seed, is used more than once. This could let someone uncover the hidden message.
Loose inspiration from the one-time pad
Stream ciphers are based on a very strong way to hide messages called the one-time pad (OTP). The one-time pad uses a keystream of random numbers mixed with the message. This method was proven safe by Claude E. Shannon in 1949. But it is hard to use because the random numbers must be as long as the message and can only be used once.
Stream ciphers use a smaller key, like 128 bits, to make a pattern of numbers that looks random. This pattern is mixed with the message, like the one-time pad. However, because the pattern is not truly random, it might not be as safe and can sometimes be figured out.
Types
A stream cipher uses a series of secret numbers, called a keystream, to hide messages. The keystream changes based on an internal setup, called the state. There are two main types of stream ciphers.
In a synchronous stream cipher, the keystream is made separately from the message. The keystream is then mixed with the message to hide it. If small mistakes happen during sending, only that small part of the message might be affected.
In a self-synchronizing stream cipher, the keystream is partly based on earlier parts of the hidden message. This helps the receiver fix any lost or added parts of the message more easily.
Based on linear-feedback shift registers
Binary stream ciphers often use linear-feedback shift registers (LFSRs) because they are easy to build and study. But LFSRs alone do not keep information safe. Different ways have been made to help LFSRs stay secure.
One way is to connect several LFSRs to a special math rule called a Boolean function. This helps get rid of patterns that could be used to break the cipher, and it avoids correlation attacks.
Another method changes when the LFSRs update. Instead of updating at the same times, one LFSR decides when another updates. Examples are the alternating step generator and the shrinking generator. The alternating step generator uses three LFSRs where one decides which of the other two to use each time. The shrinking generator uses two LFSRs, only sharing a bit when a special condition is met.
A third method uses a special rule to change the output of a single LFSR, making it harder to guess.
Other designs
Instead of using a simple way to change numbers, some people use more complex shapes. For example, Klimov and Shamir suggested using triangle-like shapes (called T-functions) that work with numbers made of n bits.
Security
For a stream cipher to be safe, its key sequence must be very long and hard to guess. Experts want the sequence to look completely random, with no patterns that could help someone break the code. This must be true for every possible key, even if attackers know some of the secret message or the coded message.
Using a safe stream cipher correctly means never reusing the same key sequence twice. This usually means using a new starting number or key each time you encode a message. It's important to remember that while stream ciphers keep messages private, they don't always check if messages have been changed during sending.
Short key sequences can be a problem. For example, some older methods can repeat their sequences too quickly, making them easier to break. Some uses of a cipher called RC4 have been found to have weak points, so new systems should avoid RC4 or make sure every key is unique and unrelated, using strong random number generators or special encoding methods.
Stream ciphers are often easier to understand than other encoding methods, which makes it less likely they have hidden weaknesses.
Usage
Stream ciphers are often chosen because they work quickly and are easy to build, especially in small devices. They are great for secure wireless connections where the amount of data isn’t known ahead of time. Unlike block ciphers, stream ciphers don’t need extra data, which makes them simpler to use.
In military uses, the secret part of the cipher can be made in a safe place and then used in other devices, like radios. This lets the radio be used in less protected places.
ChaCha is now one of the most common stream ciphers used in software. Others include: RC4, A5/1, A5/2, FISH, Helix, ISAAC, MUGI, Panama, Phelix, Pike, Salsa20, SEAL, SOBER, SOBER-128, and WAKE.
Some stream ciphers come from specific countries or are required by standards. For example, ZUC comes from China, SNOW / SNOW 3G from Sweden (used in mobile networks), and A5/1 and A5/2 were made for mobile phones. The eSTREAM project also included ciphers from different countries, such as Grain from Sweden, Trivium from Belgium, and Rabbit from Denmark.
Comparison
Stream ciphers are a type of encryption method. They work by taking one long key and using it to change each part of the message one by one. This is different from other methods, like block ciphers, which take groups of bits together to hide the message.
Stream ciphers are good for when you need to send data quickly, like in secure communication systems. Because they work on each part of the message separately, they can start protecting the data right away, without waiting to see the whole message first. This makes them fast and easy to use for things like online chats or live video.
However, stream ciphers can be tricky if the same key is used more than once. If this happens, someone might be able to read the hidden message. So it’s important to use a new key each time you send a message to keep it safe.
Related articles
This article is a child-friendly adaptation of the Wikipedia article on Stream cipher, available under CC BY-SA 4.0.
Images from Wikimedia Commons. Tap any image to view credits and license.
Safekipedia