3.4 - Stream Ciphers
3.4 - Stream Ciphers
5.1
5.2 Continued
Figure 5.20 Stream cipher
Note
In a modern stream cipher, each r-bit word in the
plaintext stream is enciphered using an r-bit word
in the key stream to create the corresponding r-bit
word in the ciphertext stream.
5.2
Design Considerations
◼ The encryption sequence should have a large period.
◼ A pseudorandom number generator uses a function that produces a
deterministic stream of bits that eventually repeats.
◼ The longer the period of repeat, the more difficult it will be to do
cryptanalysis.
◼ The keystream should approximate the properties of a
true random number stream as close as possible.
◼ There should be an approximately equal number of 1s and 0s.
◼ If the keystream is treated as a stream of bytes, then all of the 256
possible byte values should appear approximately equally often.
◼ As the output of the pseudorandom number generator is
conditioned on the value of the input key, to guard
against brute-force attacks, the key needs to be
sufficiently long.
◼ With the current technology, a key length of at least 128 bits is
desirable.
◼ The primary advantage of a stream cipher is that stream ciphers are
5.3 almost always faster and use far less code than do block ciphers.
5.2.1 Synchronous Stream Ciphers
Note
In a synchronous stream cipher the key is
independent of the plaintext or ciphertext.
5.4
5.2.1 Continued
Example 5.17
What is the pattern in the ciphertext of a one-time pad cipher
in each of the following cases?
a. The plaintext is made of n 0’s.
b. The plaintext is made of n 1’s.
c. The plaintext is made of alternating 0’s and 1’s.
d. The plaintext is a random string of bits.
Solution
a. Because 0 ki = ki , the ciphertext stream is the same as
the key stream. If the key stream is random, the
ciphertext is also random. The patterns in the plaintext
are not preserved in the ciphertext.
5.5
5.2.1 Continued
Example 5.7 (Continued)
5.6
5.2.1 Continued
5.7
5.2.1 Continued
Example 5.18
Solution
If ci = 0, bi has no role in calculation of bm. This means that bi
is not connected to the feedback function. If ci = 1, bi is
involved in calculation of bm. In this example, c1 and c3 are
0’s, which means that we have only three connections. Figure
5.24 shows the design.
5.8
5.2.1 Confidentiality
Figure 5.24 LSFR for Example 5.18
5.9
5.2.1 Continued
Example 5.19
Create a linear feedback shift register with 4 cells in which
b4 = b1 b0. Show the value of output for 20 transitions
(shifts) if the seed is (0001)2.
Solution
Figure 5.25 LFSR for Example 5.19
5.10
5.2.1 Continued
Example 5.19 (Continued)
Table 4.6 Cell values and key sequence for Example 5.19
5.11
5.2.1 Continued
Example 5.19 (Continued)
5.12
5.2.1 Continued
Example 5.19 (Continued)
Note that the key stream is 100010011010111 10001…. This
looks like a random sequence at first glance, but if we go
through more transitions, we see that the sequence is
periodic. It is a repetition of 15 bits as shown below:
Note
5.13
5.2.2 Nonsynchronous Stream Ciphers
Note
In a nonsynchronous stream cipher, the key
depends on either the plaintext or ciphertext.
5.14
A5/1: Shift Registers
Part 1 ⎯ Cryptography
15
A5/1: Keystream
◼ At each step: m = maj(x8, y10, z10)
◼ Examples: maj(0,1,0) = 0 and maj(1,1,0) = 1
◼ If x8 = m then X steps
◼ t = x13 x16 x17 x18
◼ xi = xi−1 for i = 18,17,…,1 and x0 = t
◼ If y10 = m then Y steps
◼ t = y20 y21
◼ yi = yi−1 for i = 21,20,…,1 and y0 = t
◼ If z10 = m then Z steps
◼ t = z7 z20 z21 z22
◼ zi = zi−1 for i = 22,21,…,1 and z0 = t
◼ Keystream bit is x18 y21 z22
Part 1 ⎯ Cryptography
16
A5/1
X
x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18
Y
y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 y10 y11 y12 y13 y14 y15 y16 y17 y18 y19 y20 y21
Z
z0 z1 z2 z3 z4 z5 z6 z7 z8 z9 z10 z11 z12 z13 z14 z15 z16 z17 z18 z19 z20 z21 z22
Y
1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1
Z
1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1
Part 1 ⎯ Cryptography
19
RC4
◼ A self-modifying lookup table
◼ Table always contains a permutation of the
byte values 0,1,…,255
◼ Initialize the permutation using key
◼ At each step, RC4 does the following
◼ Swaps elements in current lookup table
◼ Selects a keystream byte from table
◼ Each step of RC4 produces a byte
◼ Efficient in software
◼ Each step of A5/1 produces only a bit
◼ Efficient in hardware
Part 1 ⎯ Cryptography
20
RC4 Initialization
◼ S[] is permutation of 0,1,...,255
◼ key[] contains N bytes of key
for i = 0 to 255
S[i] = i
K[i] = key[i (mod N)]
next i
j = 0
for i = 0 to 255
j = (j + S[i] + K[i]) mod 256
swap(S[i], S[j])
next i
i = j = 0
Part 1 ⎯ Cryptography
21
RC4 Keystream
◼ For each keystream byte, swap elements in
table and select byte
i = (i + 1) mod 256
j = (j + S[i]) mod 256
swap(S[i], S[j])
t = (S[i] + S[j]) mod 256
keystreamByte = S[t]
◼ Use keystream bytes like a one-time pad
◼ Note: first 256 bytes should be discarded
◼ Otherwise, related key attack exists
Part 1 ⎯ Cryptography
22
Stream Ciphers
Part 1 ⎯ Cryptography
23