The Grain 128a stream cipher was first purposed at Symmetric Key Encryption Workshop (SKEW) in 2011[1] as an improvement of the predecessor Grain 128, which added security enhancements and optional message authentication using the Encrypt & MAC approach. One of the important features of the Grain family is that the throughput can be increased at the expense of additional hardware. Grain 128a is designed by Martin Ågren,[1] Martin Hell, Thomas Johansson and Willi Meier.
Grain 128a consists of two large parts: Pre-output function and MAC. The pre-output function has an internal state size of 256 bits, consisting of two registers of size 128 bit: NLFSR and LFSR. The MAC supports variable tag lengths w such that
0<w\leq32
The cipher supports two modes of operation: with or without authentication, which is configured via the supplied
IV0
IV0=1
IV0=0
The pre-output function consists of two registers of size 128 bit: NLFSR (
b
s
f
g
h
f(x)=1+x32+x47+x58+x90+x121+x128
g(x)=1+x32+x37+x72+x102+x128+x44x60+x61x125+x63x67x69x101+x80x88+x110x111+x115x117+x46x50x58+x103x104x106+x33x35x36x40
h(x)=bi+12si+8+si+13si+20+bi+95si+42+si+60si+79+bi+12bi+95si+94
In addition to the feedback polynomials, the update functions for the NLFSR and the LFSR are:
bi+128=si+bi+bi+26+bi+56+bi+91+bi+96+bi+3bi+67+bi+11bi+13+bi+17bi+18+bi+27bi+59+bi+40bi+48+bi+61bi+65+bi+68bi+84+bi+88bi+92bi+93bi+95+bi+22bi+24bi+25+bi+70bi+78bi+82
si+128=si+si+7+si+38+si+70+si+81+si+96
The pre-output stream (
y
yi=h(x)+si+93+bi+2+bi+15+bi+36+bi+45+bi+64+bi+73+bi+89
Upon initialisation we define an
IV
IV0
The LFSR is initialised as:
si=IVi
0\leqi\leq95
si=1
96\leqi\leq126
s127=0
The last 0 bit ensures that similar key-IV pairs do not produce shifted versions of each other.
The NLFSR is initialised by copying the entire 128 bit key (
k
bi=ki
0\leqi\leq127
Before the pre-output function can begin to output its pre-output stream it has to be clocked 256 times to warm up, during this stage the pre-output stream is fed into the feedback polynomials
g
f
The key stream (
z
y
IV0
When authentication is enabled, the MAC functionality uses the first
2w
w
If authentication is enabled:
zi=y2w+2i
If authentication is disabled:
zi=yi
Grain 128a supports tags of size
w
w
r
a
m
L
m+1
mL=1
m1=1
m2=10
For each bit
0\leqj\leq31
0\leqi\leqL
j | |
a | |
i |
When authentication is enabled Grain 128a uses the first
2w
y
Shift register:
ri=yi+31
0\leqi\leq31
Accumulator:
j | |
a | |
0 |
=yj
0\leqj\leq31
Shift register:
The shift register is fed all the odd bits of the pre-output stream(
y
ri+31=y64+2i+1
Accumulator:
j | |
a | |
i+1 |
=
j | |
a | |
i |
+miri+j
0\leqi\leqL
When the cipher has completed the L iterations the final tag(
t
ti=
i | |
a | |
L+1 |
0\leqi\leq31