Fifth
Fifth
Dhananjoy Dey
1
All the pictures used in this presentation are taken from freely available
websites.
2
If there is a reference on a slide all of the information on that slide is
attributable to that source whether quotation marks are used or not.
1 Introduction
2 Statistical Tests
Golomb’s Postulates
Five Basic Tests
3 LFSR
4 RC4
5 Trivium
6 Salsa20/20
Outline
1 Introduction
2 Statistical Tests
Golomb’s Postulates
Five Basic Tests
3 LFSR
4 RC4
5 Trivium
6 Salsa20/20
1
Adding a small amount of memory to a block cipher results in a stream cipher with large
blocks.
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 5 / 77
Introduction
Block Cipher
It processes plaintext in relatively large blocks (e.g., n ≥ 64 bits).
The same function is used to encrypt successive blocks; thus
(pure) block ciphers are memoryless1 .
Stream Ciphers
It processes plaintext in blocks as small as a single bit.
The encryption function may vary as plaintext is processed.
Thus it is said to have memory.
It is also called state ciphers since encryption depends on not only
the key and plaintext, but also on the current state.
1
Adding a small amount of memory to a block cipher results in a stream cipher with large
blocks.
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 5 / 77
Introduction
One-Time Pad
Encryption
e=000 h=001 i=010 k=011 l=100 r=101 s=110 t=111
One-Time Pad
Encryption
e=000 h=001 i=010 k=011 l=100 r=101 s=110 t=111
One-Time Pad
Encryption
e=000 h=001 i=010 k=011 l=100 r=101 s=110 t=111
One-Time Pad
Decryption
e=000 h=001 i=010 k=011 l=100 r=101 s=110 t=111
One-Time Pad
Decryption
e=000 h=001 i=010 k=011 l=100 r=101 s=110 t=111
One-Time Pad
Provably secure · · ·
Ciphertext provides no info about plaintext
All plaintexts are equally likely
· · · but, only when be used correctly
Key must be random, used only once
Key is known only to sender and receiver
Note: Key is same size as message
Stream Cipher
Stream Cipher
Stream Cipher
Stream Cipher
Main Characteristics
where f is the feedback function of the cipher, g is the key stream extractor and h
combines the key stream with the message stream.
x0 is called the initial state and may depend on the key.
https://www.ecrypt.eu.org/stream/
Timeline
Submission Requirements
Profile 2 80 32 or 64 32 or 64
(HW)
eSTREAM Portfolio
in 2008
Profile 1 Profile 2
HC-128 F-FCSR-H v2
Rabbit Grain v1
Salsa20/12 MICKEY v2
Sosemanuk Trivium
in 2012
Profile 1 Profile 2
HC-128
Rabbit Grain v1
Salsa20/12 MICKEY 2.0
Sosemanuk Trivium
Recommendation
Primitive Legacy Future
HC-128 X X
Salsa20/20 X X
ChaCha X X
SNOW 2.0 X X
SNOW 3G X X
SOSEMANUK X X
Recommendation
Primitive Legacy Future
HC-128 X X
Salsa20/20 X X
ChaCha X X
SNOW 2.0 X X
SNOW 3G X X
SOSEMANUK X X
Grain X ×
Mickey 2.0 X ×
Trivium X ×
Rabbit X ×
Recommendation
Primitive Legacy Future
HC-128 X X
Salsa20/20 X X
ChaCha X X
SNOW 2.0 X X
SNOW 3G X X
SOSEMANUK X X
Grain X ×
Mickey 2.0 X ×
Trivium X ×
Rabbit X ×
A5/1 × ×
A5/2 × ×
E0 × ×
RC4 × ×
https://www.enisa.europa.eu/publications/
algorithms-key-size-and-parameters-report-2014
Stream Ciphers
Once upon a time, not so very long ago, stream ciphers were the
king of crypto
Stream Ciphers
Once upon a time, not so very long ago, stream ciphers were the
king of crypto
Definition
A random bit generator is a device or algorithm which outputs a
sequence of statistically independent and unbiased binary digits.
Definition
A random bit generator is a device or algorithm which outputs a
sequence of statistically independent and unbiased binary digits.
Definition
A pseudo-random bit generator (PRBG) is a deterministic algorithm
which, given a truly random binary sequence of length k, outputs a
binary sequence of length ` much larger than k which “appears" to be
random. The input to the PRBG is called seed, while the output of the
PRBG is called a pseudo-random bit sequence.
Definition
We say that a PRBG passes all poly-time statistical tests if no poly-time algorithm
can correctly distinguish between an output sequence of the generator and a TRBG of
the same length with prob significantly > 21 .
Definition
We say that a PRBG passes all poly-time statistical tests if no poly-time algorithm
can correctly distinguish between an output sequence of the generator and a TRBG of
the same length with prob significantly > 21 .
Definition
We say that a PRBG passes the next-bit test if there is no poly-time algo which, on
input of the first ` bits of an output sequence s, can predict the (` + 1)th bit of s with
prob significantly > 12 .
Definition
We say that a PRBG passes all poly-time statistical tests if no poly-time algorithm
can correctly distinguish between an output sequence of the generator and a TRBG of
the same length with prob significantly > 21 .
Definition
We say that a PRBG passes the next-bit test if there is no poly-time algo which, on
input of the first ` bits of an output sequence s, can predict the (` + 1)th bit of s with
prob significantly > 12 .
Definition
A PRBG that passes the next-bit test is called a cryptographically secure PRBG.
Theorem
If b , 0, LCG generates a sequence of length m iff
(i) gcd(b, m) = 1,
(ii) if p | m, then p | (a − 1) for all prime factor p of m,
(iii) if 4 | m, then 4 | (a − 1).
Theorem
If b , 0, LCG generates a sequence of length m iff
(i) gcd(b, m) = 1,
(ii) if p | m, then p | (a − 1) for all prime factor p of m,
(iii) if 4 | m, then 4 | (a − 1).
RSA CSPRBG
e
xi ≡ xi−1 mod n.
RSA CSPRBG
e
xi ≡ xi−1 mod n.
2
xi ≡ xi−1 mod n
Outline
1 Introduction
2 Statistical Tests
Golomb’s Postulates
Five Basic Tests
3 LFSR
4 RC4
5 Trivium
6 Salsa20/20
Golomb’s Postulates
Golomb’s Postulates
Golomb’s Postulates
Definition
Let s = s0 , s1 , s2 , . . . be a periodic sequence of period N. The autocorrelation function of s is the
integer-valued function C(t) defined as
N−1
1 X
C(t) = (2.si − 1).(2si+t − 1), for 0 ≤ t ≤ N − 1.
N i=0
Golomb’s Postulates
Definition
Let s = s0 , s1 , s2 , . . . be a periodic sequence of period N. The autocorrelation function of s is the
integer-valued function C(t) defined as
N−1
1 X
C(t) = (2.si − 1).(2si+t − 1), for 0 ≤ t ≤ N − 1.
N i=0
C(t) measures the amount of similarity between the sequence s and a shift of s by t positions. If s
is a random periodic sequence of period N, then |N.C(t)| can be expected to be quite small for all
values of t, 0 < t < N.
Golomb’s Postulates
Golomb’s Postulates
Golomb’s Postulates
N−1
i f t = 0,
(
X N,
N × C(t) = (2.si − 1).(2si+t − 1) =
K, i f 1 ≤ t ≤ N − 1.
i=0
Golomb’s Postulates
N−1
i f t = 0,
(
X N,
N × C(t) = (2.si − 1).(2si+t − 1) =
K, i f 1 ≤ t ≤ N − 1.
i=0
(n0 − n1 )2
X1 =
n
2
n00 + n01 + n10 + n11 = (n − 1) since the subsequences are allowed to overlap.
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 31 / 77
Statistical Tests Five Basic Tests
2
n00 + n01 + n10 + n11 = (n − 1) since the subsequences are allowed to overlap.
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 31 / 77
Statistical Tests Five Basic Tests
Poker test
3
Note that the poker test is a generalization of the frequency test: setting m = 1 in the poker
test yields the frequency test.
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 32 / 77
Statistical Tests Five Basic Tests
Poker test
3
Note that the poker test is a generalization of the frequency test: setting m = 1 in the poker
test yields the frequency test.
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 32 / 77
Statistical Tests Five Basic Tests
Runs test
The purpose of the runs test is to determine whether the number of runs of
various lengths in the sequence s is as expected for a random sequence.
Runs test
The purpose of the runs test is to determine whether the number of runs of
various lengths in the sequence s is as expected for a random sequence.
The expected number of gaps (or blocks) of length i in a random sequence of
length n is ei = (n − i + 3)/2i+2 .
Let k be equal to the largest integer i for which ei ≥ 5.
Let Bi , Gi be the number of blocks and gaps, respectively, of length i in s for each
i, 1 ≤ i ≤ k.
The statistic used is
k k
X (Bi − ei )2 X (Gi − ei )2
X4 = +
i
ei i
ei
Autocorrelation test
2(A(d) − n−d
2 )
X5 = √
n−d
Outline
1 Introduction
2 Statistical Tests
Golomb’s Postulates
Five Basic Tests
3 LFSR
4 RC4
5 Trivium
6 Salsa20/20
C(D) = 1 + c1 D + c2 D2 + · · · + cL DL ∈ GF(2)[D]
Definition
A LFSR of degree / length L is defined by feedback coefficients
c1 , . . . , cL ∈ GF(2).
Example (LFSR)
Example (LFSR)
Connection polynomial:
Example (LFSR)
1101 → 1
0110 → 0
0011 → 1
1001 → 1
0100 → 0
0010 → 0
0001 → 1
1000 → 0
1100 → 0
1110 → 0
1111 → 1
0111 → 1
1011 → 1
0101 → 1
1010 → 0
1101 → 1
0110 → 0
0011 → 1
1001 → 1
0100 → 0
0010 → 0
0001 → 1
1000 → 0
1100 → 0
1110 → 0
1111 → 1
0111 → 1
1011 → 1
0101 → 1
1010 → 0
1101
Definition
Let s0 , s1 , s2 , . . . be a linear recurring sequence. The period of the
sequence is the smallest integer N ≥ 1 s/t
s j+N = s j
for all sufficiently large values of j.
Definition
Let s0 , s1 , s2 , . . . be a linear recurring sequence. The period of the
sequence is the smallest integer N ≥ 1 s/t
s j+N = s j
for all sufficiently large values of j.
Proposition
The period of a sequence generated by an LFSR of degree n is at
most 2n − 1.
Linear Complexity
Definition
The linear complexity of an infinite binary sequence s, denoted L(s),
is defined as follows:
(i) if s is the zero sequence s = 0, 0, 0, . . . , then L(s) = 0 ;
(ii) if no LFSR generates s, then L(s) = ∞;
(iii) otherwise, L(s) is the length of the shortest LFSR that generates s.
Linear Complexity
Definition
The linear complexity of an infinite binary sequence s, denoted L(s),
is defined as follows:
(i) if s is the zero sequence s = 0, 0, 0, . . . , then L(s) = 0 ;
(ii) if no LFSR generates s, then L(s) = ∞;
(iii) otherwise, L(s) is the length of the shortest LFSR that generates s.
Definition
The linear complexity of a finite binary sequence sn , denoted L(sn ), is
the length of the shortest LFSR that generates a sequence having sn
as its first n terms.
f (x0 , x1 , x2 , x3 ) = 1 + x0 + x1 + x1 x2 x3
f (x0 , x1 , x2 , x3 ) = 1 + x0 + x1 + x1 x2 x3
0001 → 1
0000 → 0
1000 → 0
1100 → 0
1110 → 0
1111 → 1
0111 → 1
1011 → 1
1101 → 1
0110 → 0
0011 → 1
1001 → 1
0100 → 0
1010 → 0
0101 → 1
0010 → 0
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 46 / 77
LFSR
Filter generator
Shrinking generator
f (x1 , x2 , x3 ) = x1 x2 ⊕ (1 + x2 )x3 = x1 x2 ⊕ x2 x3 ⊕ x3 .
f (x1 , x2 , x3 ) = x1 x2 ⊕ (1 + x2 )x3 = x1 x2 ⊕ x2 x3 ⊕ x3 .
The keystream generated has period (2L1 − 1)(2L2 − 1)(2L3 − 1) and linear complexity
L = L1 L2 + L2 L3 + L3 .
Filter Generator
A filter generator is a running-key generator for stream cipher
applications.
It consists of a single LFSR which is filtered by a nonlinear
function f .
Filter Generator
A filter generator is a running-key generator for stream cipher
applications.
It consists of a single LFSR which is filtered by a nonlinear
function f .
Shrinking Generator
Shrinking Generator
Outline
1 Introduction
2 Statistical Tests
Golomb’s Postulates
Five Basic Tests
3 LFSR
4 RC4
5 Trivium
6 Salsa20/20
RC4
RC4
RC4
RC4
Outline
1 Introduction
2 Statistical Tests
Golomb’s Postulates
Five Basic Tests
3 LFSR
4 RC4
5 Trivium
6 Salsa20/20
Trivium
Designed by De Canniére and Preneel in 2006 as part of eSTREAM competition
Intended to be simple and efficient (especially in hardware)
Trivium
Designed by De Canniére and Preneel in 2006 as part of eSTREAM competition
Intended to be simple and efficient (especially in hardware)
Trivium Hardware
Trivium
Parameters:
Key size: 80 bit, IV size: 80 bit, Internal state: 288 bit
Trivium
Parameters:
Key size: 80 bit, IV size: 80 bit, Internal state: 288 bit
Three coupled FSR of degree 93, 84, and 111.
Initialization:
80-bit key in left-most registers of first FSR
80-bit IV in left-most registers of second FSR
Remaining registers set to 0, except for three right-most (all 1s)
registers of third FSR
run for 4 × 288 clock ticks to finish initialization
https://www.ecrypt.eu.org/stream/p3ciphers/trivium/trivium_p3.pdf
Trivium-Initialization
For i = 1 to 4 × 288 do
1 t1 ← s66 + s91 s92 + s93 + s171
2 t2 ← s162 + s175 s176 + s177 + s264
3 t3 ← s243 + s286 s287 + s288 + s69
Trivium-Initialization
For i = 1 to 4 × 288 do
1 t1 ← s66 + s91 s92 + s93 + s171
2 t2 ← s162 + s175 s176 + s177 + s264
3 t3 ← s243 + s286 s287 + s288 + s69
4 (s1 , s2 , . . . , s93 ) ← (t3 , s1 , . . . , s92 )
5 (s94 , s95 , . . . , s177 ) ← (t1 , s94 , ..., s176 )
6 (s178 , s279 , . . . , s288 ) ← (t2 , s178 , . . . , s287 )
Trivium-Initialization
For i = 1 to 4 × 288 do
1 t1 ← s66 + s91 s92 + s93 + s171
2 t2 ← s162 + s175 s176 + s177 + s264
3 t3 ← s243 + s286 s287 + s288 + s69
4 (s1 , s2 , . . . , s93 ) ← (t3 , s1 , . . . , s92 )
5 (s94 , s95 , . . . , s177 ) ← (t1 , s94 , ..., s176 )
6 (s178 , s279 , . . . , s288 ) ← (t2 , s178 , . . . , s287 )
Trivium-Iteration
Trivium-Iteration
Outline
1 Introduction
2 Statistical Tests
Golomb’s Postulates
Five Basic Tests
3 LFSR
4 RC4
5 Trivium
6 Salsa20/20
Salsa20/20
4
Strings are interpreted in little-endian notation
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 63 / 77
Salsa20/20
Salsa20/20
4
Strings are interpreted in little-endian notation
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 63 / 77
Salsa20/20
Salsa20/20
4
Strings are interpreted in little-endian notation
Dhananjoy Dey (IIITL) Stream Ciphers September 10, 2024 63 / 77
Salsa20/20
Salsa20/20
y0 y1 y2 y3
y y5 y6 y7
S = 4
y8 y9 y10 y11
y12 y13 y14 y15
Salsa20/20
y0 y1 y2 y3
y y5 y6 y7
S = 4
y8 y9 y10 y11
y12 y13 y14 y15
Salsa20/20: Quarter-round
Salsa20/20: Row-round
z0 z1 z2 z3
z z5 z6 z7
row-round(S ) = 4 ,
8 z9 z10 z11
z
z12 z13 z14 z15
where
(z0 , z1 , z2 , z3 ) = quarter-round (y0 , y1 , y2 , y3 ),
(z5 , z6 , z7 , z4 ) = quarter-round (y5 , y6 , y7 , y4 ),
(z10 , z11 , z8 , z9 ) = quarter-round (y10 , y11 , y8 , y9 ),
(z15 , z12 , z13 , z14 ) = quarter-round (y15 , y12 , y13 , y14 ).
Salsa20/20: Column-round
Salsa20/20: Double-round
Salsa20/20: Double-round
Salsa20/20
Salsa20/20
Salsa20/20
The state array S :
y0 k1 k2 k3
k y5 n1 n2
S = 4
b1 b2 y10 k5
k6 k7 k8 y15
Salsa20/20
The state array S :
y0 k1 k2 k3
k y5 n1 n2
S = 4
b1 b2 y10 k5
k6 k7 k8 y15
ChaCha20
ChaCha20
ChaCha20 Quarter-round
ChaCha20 Double-round
ChaCha20 also runs 10 double-rounds.
However, a ChaCha double-round consists of a column-round and
a diagonal-round
A ChaCha double-round is defined by the 8 ChaCha
quarter-rounds
column-round quarter-round (y0 , y4 , y8 , y12 )
quarter-round (y1 , y5 , y9 , y13 )
quarter-round (y2 , y6 , y10 , y14) )
quarter-round (y3 , y7 , y11 , y15 )
ChaCha20
The state array S :
y0 y1 y2 y3
k k2 k3 k4
S = 1
k5 k6 k7 k8
b n1 n2 n3
The ChaCha20 stream cipher takes a 256-bit key k = (k1 , . . . , k8 ) and a unique 96-bit
message number n = (n1 , n2 , n3 ) (nonce) as input.
A 32-bit block counter b is initially set to zero and the four 32-bit constants
S. W. Golomb,
Shift Register Sequences, Aegean Park Press, 1982.
Andreas Klein,
Stream Ciphers, Springer, 2013.
R. A. Rueppel,
Analysis and Design of Stream Ciphers, Springer, 1986.
Mark Stamp
Information Security - Principles and Practice, John Wiley & Sons, Inc., 2011.