Grain explained in plain terms means understanding a stream cipher built from two shift registers, one linear and one nonlinear, working together to protect devices too small for ordinary cryptography. The central question is why a cipher needs two registers when one would be simpler, and the answer is that the pairing is what makes Grain both small and strong.
Grain is a stream cipher designed by Martin Hell, Thomas Johansson, and Willi Meier, submitted to the eSTREAM project in 2004 and chosen for its hardware portfolio in 2008. It takes an 80-bit key and a 64-bit initialisation vector, mixes them through 160 bits of state, and produces a keystream one bit at a time for the smallest hardware that needs encryption.
This article gives you five ways Grain guards small devices, explains what it is, how it works, and where it already runs.
Key takeaways
- Grain is a stream cipher built from two 80-bit shift registers.
- It uses an 80-bit key and a 64-bit initialisation vector.
- It was selected for the eSTREAM hardware portfolio in 2008.
- It needs 160 warm-up rounds before it outputs any keystream.
- It is built for tiny hardware, not for general-purpose software.
What Grain is
Grain is a cipher that encrypts data as a continuous stream rather than in fixed-size blocks, generating a long sequence of pseudo-random bits from a short key and combining that sequence with the message. The keystream must never be reused with the same key and initialisation vector, because reusing it would let an attacker recover the plaintext by combining two ciphertexts, which is the one rule every stream cipher shares.
Its signature feature is the pairing of two registers. The first is a linear feedback shift register, which is fast and predictable on its own, and the second is a nonlinear feedback shift register, which is harder to predict, and Grain combines their outputs through a nonlinear function that takes bits from both, which means the keystream depends on the two registers in a way that is difficult to untangle.
The design was a reaction to the needs of tiny hardware. Radio tags, sensor nodes, and embedded controllers have almost no spare logic, and a cipher for them must be measured in hundreds of gates rather than thousands, so Grain’s designers built the smallest stream cipher they could that still resisted the attacks they knew about, and the two-register design was their answer.
It became one of the best-known results of the eSTREAM contest, the European project that searched for new stream ciphers after the early 2000s. eSTREAM split its winners into software and hardware portfolios, and Grain was chosen for the hardware side alongside Trivium, which gave it the scrutiny that a cipher needs before anyone trusts it with real data.
Its most famous property is the later version with authentication. Grain-128a, published in 2011, adds a 128-bit key and a message authentication code, which means it can prove that a message has not been tampered with as well as keeping it secret, and that upgrade kept Grain relevant long after the original version was published.
Our guide to stream ciphers explains the family Grain belongs to, and our guide to RC5 explains another compact cipher that values simplicity.
How Grain works
Everything starts with the two registers, each 80 bits long, which together hold 160 bits of state. The key fills the nonlinear register, the initialisation vector fills the linear register, and the remaining bits of the linear register are filled with ones, a fixed pattern that stops the state from ever being all zeroes, which would produce a useless stream of nothing.
Each round shifts both registers by one position and feeds new bits back into them. The linear register’s feedback is a simple combination of its own bits, which is fast and easy to build in hardware, while the nonlinear register’s feedback mixes its bits through AND gates, which makes its behaviour much harder to predict, and the two registers also exchange influence through the output function.
The warm-up runs this process 160 times with the output discarded, which is the cipher’s way of making sure the keystream depends on every bit of the key and the initialisation vector. Cryptographers call this diffusion, and Grain’s designers chose a warm-up equal to the size of the state, so that the key and the initialisation vector are thoroughly tangled before anything leaks out.
Once the warm-up finishes, each round produces one bit of keystream, taken from a nonlinear function that combines bits from both registers. That bit is XORed with one bit of plaintext to make one bit of ciphertext, and the receiver, running the same cipher with the same key and initialisation vector, generates the same keystream and reverses the process to recover the message.
The security of the design rests on the nonlinear register and the output function, which together stop an attacker from treating Grain as a linear system. A purely linear cipher could be solved with algebra, but the AND gates in the nonlinear register and in the output function make the relationship between the key and the keystream a puzzle that has resisted nearly twenty years of analysis.
Decryption is identical to encryption, because XORing twice with the same keystream returns the original bits. That symmetry is typical of stream ciphers, and it means Grain needs no separate decryption routine, which saves even more space on the tiny hardware it was built for.

Comparing Grain with other stream ciphers
Grain is one of several stream ciphers, and each was built with a different emphasis. Trivium aims for tiny hardware with three linear registers and nonlinear feedback, Salsa20 aims for speed in software with a large state, and the RC4 cipher that once ruled the web was fast but turned out to be fragile, while Grain trades speed for a two-register design, and each approach trades something for something else.
The table below sets out the main contrasts between the leading approaches.
| Aspect | Grain | Trivium | Salsa20 |
|---|---|---|---|
| Designed for | Tiny hardware | Tiny hardware | Fast software |
| Key size | 80 bits | 80 bits | 256 bits |
| Internal state | 160 bits | 288 bits | 512 bits |
| Warm-up rounds | 160 | 1,152 | 20 |
| Best for | Tags and sensors | Tags and sensors | General software |
The practical result is that Grain is the right choice for tiny hardware with a small state, Trivium suits the same niche with a larger state, and Salsa20 fits general software where size does not matter.
Where Grain is used
Radio tags use it where they use cryptography at all. RFID tags carry tiny chips with almost no spare logic, and a cipher that fits in a few hundred gates can protect the data on the tag without changing its cost or its power budget, which is why Grain was designed for tags in the first place.
Sensor networks use it in devices that measure and report. A temperature sensor on a pipeline or a soil sensor on a farm has a small battery and a small processor, and it still needs to send its readings without letting anyone nearby listen in or forge false data, which is exactly the job a tiny stream cipher is built for.
Embedded controllers use it to protect firmware updates. A device that receives new software over the air needs to check that the update is genuine, and a small cipher can encrypt the channel or authenticate the payload without demanding a bigger chip, which keeps the device cheap and the update safe.
Researchers use it as a benchmark for new designs. When someone proposes a new lightweight cipher, Grain is one of the first comparisons they make, because its size and speed are well understood and its security has been tested in public for years, which makes it a useful yardstick for the whole field.
Teaching uses it to show how stream ciphers work. Students can read the whole specification in an afternoon and implement it in a weekend, which is rare for a serious cipher, and that accessibility has made Grain a favourite example in cryptography courses and in textbooks about lightweight design.
Strengths and limits
The greatest strength of Grain is its size. A cipher that needs so little hardware can go where other ciphers cannot, and its two-register design is easy to understand, easy to build, and easy to test, which is worth more than cleverness in a field where hidden complexity usually means hidden flaws.
It is also a strength that the design has survived so much scrutiny. Nearly twenty years of published attacks have found only theoretical weaknesses that need unrealistic amounts of data, and the authenticated Grain-128a version keeps the design current for applications that need more than encryption alone.
The limits are real, though, and the biggest is that Grain is slow in software. Producing one bit per round means encrypting a megabyte takes millions of rounds, which is fine on dedicated hardware but wasteful on a general-purpose processor, and that is why nobody uses Grain to encrypt a hard drive or a video stream.
Grain checklist
- Never reuse a key and initialisation vector pair for two messages.
- Always run the full 160 warm-up rounds before using the keystream.
- Use Grain on hardware where size matters, not on general software.
- Generate the initialisation vector randomly for every message.
- Consider Grain-128a if you need authentication as well as encryption.
- Remember the original Grain encrypts but does not authenticate on its own.
- Test the implementation against published test vectors first.
- Keep the key secret and as random as the 80 bits allow.
- Consider a modern authenticated cipher if you need more than encryption.
Frequently asked questions
What is Grain in simple terms?
It is a stream cipher that makes a long pseudo-random keystream from a short key, using two shift registers, one linear and one nonlinear, that are small enough to fit on the tiniest chips.
Why does Grain use two registers?
The linear register is fast and cheap, the nonlinear register is hard to predict, and combining them gives Grain a keystream that is both efficient to produce and difficult to attack.
What is Grain-128a?
It is a later version of Grain with a 128-bit key that also produces a message authentication code, so it can prove a message has not been tampered with as well as keeping it secret.
How is Grain different from Trivium?
Both are tiny hardware stream ciphers from the eSTREAM contest, but Grain uses a linear register paired with a nonlinear one, while Trivium uses three linear registers with nonlinear feedback.
Can Grain run in software?
It can, but it is slow there, producing one bit per round, so software usually chooses a cipher designed for processors instead.
When should I use Grain?
When your hardware is tiny, your power budget is small, and you need encryption on a chip where a bigger cipher simply will not fit.
The bottom line
Grain explained in one line is this: a stream cipher that proves two small registers can do the work of a much larger design, by pairing a predictable one with an unpredictable one until the result cannot be predicted at all.
It is the quiet partner of Trivium in lightweight cryptography, and the reason it still matters is that the world keeps adding tiny connected devices, and every one of them needs security that fits.
This article is general information about how Grain works, not advice about choosing encryption for a particular device or system.







