









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Figure 1. Operation of a block cipher
❄
Ciphertext block c
❄
Plaintext block m
Secret key✲ k Cipher function e
of plaintext one at a time to produce blocks of ciphertext. The main difference between a block cipher and a stream cipher is that block ciphers are stateless, whilst stream ciphers maintain an internal state which is needed to determine which part of the keystream should be generated next. We write
c = ek (m), m = dk (c)
where
The block sizes taken are usually reasonably large, 64 bits in DES and 128 bits or more in modern block ciphers. Often the output of the ciphertext produced by encrypting the first block is used to help encrypt the second block in what is called a mode of operation. These modes are used to avoid certain attacks based on deletion or insertion by giving each ciphertext block a context within the overall message. Each mode of operation offers different protection against error propagation due to transmission errors in the ciphertext. In addition, depending on the mode of operation (and the application) message/session keys may be needed. For example, many modes require a per message
123
differential and certain differentials have certain probabilities associated to them, depend- ing on what the key is. By analysing the probabilities of the differentials computed in a chosen plaintext attack one can hope to reveal the underlying structure of the key.
Surprisingly these two methods are quite successful against some ciphers. But they do not appear that successful against DES or Rijndael, two of the most important block ciphers in use today.
Since DES and Rijndael are likely to be the most important block ciphers in use for the next few years we shall study them in some detail. This is also important since they both show general design principles in their use of substitutions and permutations. Recall that the historical ciphers made use of such operations, so we see that not much has changed. Now, however, the substitutions and permutations used are far more intricate. On their own they do not produce security, but when used over a number of rounds one can obtain enough security for our applications.
We end this section by discussing which is best, a block cipher or a stream cipher? Alas there is no correct answer to this question. Both have their uses and different properties. Here are just a few general points.
L (^) i =^ Ri− 1 , Ri = L (^) i− 1 ⊕ F (Ki , Ri− 1 ).
Hence, the decryption can be performed via
R (^) i− 1 = L (^) i , L (^) i− 1 = Ri ⊕ F (Ki , L (^) i ).
This means that in a Feistel cipher we have simplified the design somewhat, since
126 8. BLOCK CIPHERS
Figure 2. Basic operation of a Feistel cipher Plaintext block (^) L 0 R 0
Iterate r times
L (^) i− 1 Ri− 1
#✠#
❄ F ✛ Ki ✲ (^) ⊕❄ ❄ L (^) i Ri
Ciphertext block (^) Rr L (^) r
Of course to obtain a secure cipher we still need to take care with
Note that a key length of 56 bits is insufficient for many modern applications, hence often one uses DES by using three keys and three iterations of the main cipher. Such a version is called Triple DES or 3DES, see Fig. 3. In 3DES the key length is equal to 168. There is another way of using DES three times, but using two keys instead of three giving rise to a key length of 112. In this two-key version of 3DES one uses the 3DES basic structure but with the first and third key being equal. However, two-key 3DES is not as secure as one might inititally think.
2.1. Overview of DES Operation. Basically DES is a Feistel cipher with 16 rounds, as depicted in Fig. 4, except that before and after the main Feistel iteration a permutation is performed. Notice how the two blocks are swapped around before being passed through the final inverse permutation. This permutation appears to produce no change to the security, and people have often wondered why it is there. One answer given by one of the original team members was that this permutation was there to make the original implementation easier to fit on the circuit board.
128 8. BLOCK CIPHERS
The overall structure of DES is explained in Fig. 5.
Figure 5. Structure of the DES function F 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 XOR with round key
S-Box 1 S-Box 2 S-Box 3 S-Box 4 S-Box 5 S-Box 6 S-Box 7 S-Box 8
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
P-Box
Expansion permutation
We now give details of each of the steps which we have not yet fully defined. 2.1.1. Initial Permutation, IP:. The DES initial permutation is defined in the following table. Here the 58 in the first position means that the first bit of the output from the IP is the 58th bit of the input, and so on.
58 50 42 34 26 18 10 2 60 52 44 36 28 20 12 4 62 54 46 38 30 22 14 6 64 56 48 40 32 24 16 8 57 49 41 33 25 17 9 1 59 51 43 35 27 19 11 3 61 53 45 37 29 21 13 5 63 55 47 39 31 23 15 7
The inverse permutation is given in a similar manner by the following table.
40 8 48 16 56 24 64 32 39 7 47 15 55 23 63 31 38 6 46 14 54 22 62 30 37 5 45 13 53 21 61 29 36 4 44 12 52 20 60 28 35 3 43 11 51 19 59 27 34 2 42 10 50 18 58 26 33 1 41 9 49 17 57 25 2.1.2. Expansion Permutation, E:. The expansion permutation is given in the following table. Each row corresponds to the bits which are input into the corresponding S-Box at the next stage. Notice how the bits which select a row of one S-Box (the first and last bit on each row) are also used to select the column of another S-Box.
32 1 2 3 4 5 4 5 6 7 8 9 8 9 10 11 12 13 12 13 14 15 16 17 16 17 18 19 20 21 20 21 22 23 24 25 24 25 26 27 28 29 28 29 30 31 32 1 2.1.3. S-Box: The details of the eight DES S-Boxes are given in the Fig. 6. Recall that each box consists of a table with four rows and sixteen columns. 2.1.4. The P-Box Permutation, P:. The P-Box permutation takes the eight lots of four-bit nibbles, output of the S-Boxes, and produces a 32-bit permutation of these values as given by the following table.
16 7 20 21 29 12 28 17 1 15 23 26 5 18 31 10 2 8 24 14 32 27 3 9 19 13 30 6 22 11 4 25
2.2. DES Key Schedule. The DES key schedule takes the 56-bit key, which is actually input as a bitstring of 64 bits comprising of the key and eight parity bits, for error detection. These parity bits are in bit positions 8, 16 ,... , 64 and ensure that each byte of the key contains an odd number of bits. We first permute the bits of the key according to the following permutation (which takes a 64-bit input and produces a 56-bit output, hence discarding the parity bits).
57 49 41 33 25 17 9 1 58 50 42 34 26 18 10 2 59 51 43 35 27 19 11 3 60 52 44 36 63 55 47 39 31 23 15 7 62 54 46 38 30 22 14 6 61 53 45 37 29 21 13 5 28 20 12 4
Finally the two portions Ci and Di are joined back together and are subject to another per- mutation, called PC-2, to produce the final 48-bit round key. The permutation PC-2 is described below. 14 17 11 24 1 5 3 28 15 6 21 10 23 19 12 4 26 8 16 7 27 20 13 2 41 52 31 37 47 55 30 40 51 45 33 48 44 49 39 56 34 53 46 42 50 36 29 32
1 , 0 , 0 , 0 , 0 , 0 , 1 , 1
since 0 x83 = 8 · 16 + 3 = 131
in decimal. One can obtain the bit pattern directly by noticing that 8 in binary is 1, 0 , 0 , 0 and 3 in 4-bit binary is 0, 0 , 1 , 1 and one simply concatenates these two bit strings together. The bit pattern itself then corresponds to the binary polynomial
x 7 + x + 1.
So we say that the hexadecimal number 0x83 represents the binary polynomial
x 7 + x + 1. Arithmetic in F 28 is performed using polynomial arithmetic modulo the irreducible polynomial m(x) = x^8 + x^4 + x^3 + x + 1.
Rijndael identifies 32-bit words with polynomials in F 28 [X] of degree less than four. This is done in a big-endian format, in that the smallest index corresponds to the least important coefficient. Hence, the word a 0 ∥a 1 ∥a 2 ∥a 3
will correspond to the polynomial
a 3 X 3 + a 2 X 2 + a 1 X + a 0.
Arithmetic is performed on polynomials in F 28 [X] modulo the reducible polynomial
M (X) = X 4 + 1.
Hence, arithmetic is done on these polynomials in a ring rather than a field, since M (X) is reducible. Rijndael is a parametrized algorithm in that it can operate on block sizes of 128, 192 or 256 bits, it can also accept keys of size 128, 192 or 256 bits. For each combination of block and key size a different number of rounds is specified. To make our discussion simpler we shall consider
134 8. BLOCK CIPHERS
Algorithm 8.2: Rijndael Decryption Outline AddRoundKey(S, K 10 ) InverseShiftRows(S) InverseSubBytes(S) for i = 9 downto 1 do AddRoundKey(S, Ki ) InverseMixColumns(S) InverseShiftRows(S) InverseSubBytes(S) end AddRoundKey(S, K 0 )
3.3. Key Schedule. The only thing left to describe is how Rijndael computes the round keys from the main key. Recall that the main key is 128 bits long, and we need to produce 11 round keys K 0 ,... , K 11 all of which consist of four 32-bit words. Each word corresponding to a column of a matrix as described above. The key schedule makes use of a round constant which we shall denote by RC (^) i = xi^ (mod x^8 + x^4 + x^3 + x + 1). We label the round keys as (W (^4) i , W (^4) i+1 , W (^4) i+2 , W (^4) i+3 ) where i is the round. The initial main key is first divided into four 32-bit words (k 0 , k 1 , k 2 , k 3 ). The round keys are then computed as in Algorithm 8.3, where RotBytes is the function which rotates a word to the left by a single byte, and SubBytes applies the Rijndael encryption S-Box to every byte in a word.
Algorithm 8.3: Rijndael Key Schedule W 0 = K 0 , W 1 = K 1 , W 2 = K 2 , W 3 = K 3 for i = 1 to 10 do T =RotBytes(W (^4) i− 1 ) T =SubBytes(T ) T = T ⊕ RC (^) i W (^4) i = W (^4) i− 4 ⊕ T W (^4) i+1 = W (^4) i− 3 ⊕ W (^4) i W (^4) i+2 = W (^4) i− 2 ⊕ W (^4) i+ W (^4) i+3 = W (^4) i− 1 ⊕ W (^4) i+ end
Figure 9. CBC encipherment
m (^1)
❄ ⊕ ❄
ek
c^ ❄ 1
✲
m (^2)
❄ ⊕ ❄
e (^) k
c^ ❄ 2
✲
m (^3)
❄ ⊕ ❄
ek
c^ ❄ 3
Figure 10. CBC decipherment
c 1
❄
dk
❄ ⊕ ❄ m (^1)
✲
c 2
❄
dk
❄ ⊕ ❄ m (^2)
✲
c 3
❄
d (^) k
❄ ⊕ ❄ m (^3)
4.3. OFB Mode. Output Feedback Mode, or OFB Mode enables a block cipher to be used as a stream cipher. We need to choose a variable j (1 ≤ j ≤ n) which will denote the number of bits output by the keystream generator on each iteration. We use the block cipher to create the keystream, j bits at a time. It is however usually recommended to take j = n as that makes the expected cycle length of the keystream generator larger. Again we divide plaintext into a series of blocks, but this time each block is j-bits, rather than n-bits long:
m 1 ,... , m (^) q.
Encryption is performed as follows, see Fig. 11 for a graphical representation. First we set X 1 = IV , then for i = 1, 2 ,... , q, we perform the following steps,
Y (^) i = ek (Xi ), Ei = j leftmost bits of Y (^) i , ci = m (^) i ⊕ Ei , Xi+1 = Y (^) i.
Decipherment in OFB Mode is performed in a similar manner as described in Fig. 12.
4.4. CFB Mode. The next mode we consider is called Cipher FeedBack Mode, or CFB Mode. This is very similar to OFB Mode in that we use the block cipher to produce a stream cipher. Recall
138 8. BLOCK CIPHERS
Figure 11. OFB encipherment Y (^) i− 1 ❄ ek ❄ Select left j bits
❄ ⊕ ✻ m (^) i (j bits of plaintext)
ci (j bits of ciphertext) ✲
✲
Y (^) i
Y (^) i
Figure 12. OFB decipherment Y (^) i− 1 ❄ ek
❄ Select left j bits
❄ ⊕ ✻ ci (j bits of ciphertext)
m (^) i (j bits of plaintext) ✲
✲
Y (^) i
Y (^) i
that in OFB Mode the keystream was generated by encrypting the IV and then iteratively encrypt- ing the output from the previous encryption. In CFB Mode the keystream output is produced by the encryption of the ciphertext, as in Fig. 13, by the following steps,
Y 0 = IV , Zi = ek (Y (^) i− 1 ), Ei = j leftmost bits of Zi , Y (^) i = m (^) i ⊕ Ei.
We do not present the decryption steps, but leave these as an exercise for the reader.
4.5. CTR Mode. The next mode we consider is called Counter Mode, or CTR Mode. This combines many of the advantages of ECB Mode, but with none of the disadvantages. We first select a public IV , or counter, which is chosen differently for each message encrypted under the fixed key k. Then encryption proceeds for the ith block, by encrypting the value of IV + i and then xor’ing this with the message block. In other words we have
ci = m (^) i ⊕ ek (IV + i).
This is explained pictorially in Figure 14 CTR Mode has a number of interesting properties. Firstly since each block can be encrypted independently, much like in ECB Mode, we can process each block at the same time. Compare this to CBC Mode, OFB Mode or CFB Mode where we cannot start encrypting the second block until the first block has been encrypted. This means that encryption, and decryption, can be performed in parallel. However, unlike ECB Mode two equal blocks will not encrypt to the same ciphertext
140 8. BLOCK CIPHERS
The Rijndael algorithm, the AES process and a detailed discussion of attacks on block ciphers and Rijndael in particular can be found in the book by Daemen and Rijmen. Stinson’s book is the best book to explain differential cryptanalysis for students.
J. Daemen and V. Rijmen. The Design of Rijndael: AES – The Advanced Encryption Standard. Springer-Verlag, 2002.
D. Stinson. Cryptography Theory and Practice. CRC Press, 1995.