Lecture 3
Lecture 3
Lecture 3
Standard
Lecture Notes on Computer and Network Security
by Avi Kak (kak@purdue.edu)
January 15, 2016
12:28am
c
2016
Avinash Kak, Purdue University
Goals:
To introduce the notion of a block cipher in the modern context.
To talk about the infeasibility of ideal block ciphers
To introduce the notion of the Feistel Cipher Structure
To go over DES, the Data Encryption Standard
CONTENTS
Section Title
3.1
Page
3.2
6
7
3.2.1
10
3.2.2
12
3.3
16
3.3.1
18
3.3.2
22
3.3.3
26
3.3.4
28
3.3.5
30
3.3.6
33
3.3.7
35
3.4
37
3.5
Homework Problems
39
Lecture 3
Lecture 3
Lecture 3
b
Plaintext bit block:
b1
b2
Figure 1: The ideal block cipher when the block size equals
4 bits. (This figure is from Lecture 3 of Lecture Notes on Computer and Network Security by
Avi Kak)
Lecture 3
The size of the encryption key would make the ideal block cipher
an impractical idea. Think of the logistical issues related to the
transmission, storage, and processing of such large keys.
Lecture 3
Named after the IBM cryptographer Horst Feistel and first implemented in the Lucifer cipher by Horst Feistel and Don Coppersmith.
A cryptographic system based on Feistel structure uses the same
basic algorithm for both encryption and decryption.
As shown in Figure 2, the Feistel structure consists of multiple
rounds of processing of the plaintext, with each round consisting
of a substitution step followed by a permutation step.
The input block to each round is divided into two halves that we
can denote L and R for the left half and the right half.
7
Lecture 3
In each round, the right half of the block, R, goes through unchanged. But the left half, L, goes through an operation that
depends on R and the encryption key.
The permutation step at the end of each round consists of swapping the modified L and R. Therefore, the L for the next round
would be R of the current round. And R for the next round
be the output L of the current round.
Lecture 3
Plaintext block
(Divide into two halves, L and R)
Round Keys
K
1
Round1
F(K,R)
R
K
2
Round
F(K,R)
L
Round n
R
K
n
F(K,R)
Ciphertext block
Figure 2: The Feistel Structure for symmetric key cryptography (This figure is from Lecture 3 of Lecture Notes on Computer and Network Security
by Avi Kak)
9
Lecture 3
Let LEi and REi denote the output half-blocks at the end of the
ith round of processing. The letter E denotes encryption.
In the Feistel structure, the relationship between the output of
the ith round and the output of the previous round, that is, the
(i 1)th round, is given by
LEi
REi
=
=
REi1
LEi1 F (REi1, Ki)
LE16
RE16
Lecture 3
=
=
RE15
LE15 F (RE15, K16)
11
Lecture 3
12
Lecture 3
LD0
RD0
=
=
RE16
LE16
We can write the following equations for the output of the first
decryption round
LD1
=
=
=
RD0
LE16
RE15
RD1
=
=
=
=
This shows that, except for the left-right switch, the output of
the first round of decryption is the same as the input to the last
stage of the encryption round since we have LD1 = RE15 and
RD1 = LE15
The following equalities are used in the above derivation. Assume
that A, B, and C are bit arrays.
[A B] C
=
13
A [B C ]
Lecture 3
A A
A 0
=
=
0
A
14
Lecture 3
Encryption
Decryption
Round Keys
Plaintext block
(Divide into two halves, L and R)
Plaintext block
(Divide into two halves, L and R)
K
1
LE
RE
LD
=
16
RE
RD
LE
0
16
F(K,R)
Round1
F(K,R)
LE
1
RE
K
2
LD
RD =
15
RE
1
15
LE
F(K,R)
Round
F(K,R)
LE
RE
15
15
K
16
LD
Round 16
RE
RD
1
15
LE
15
F(K,R)
F(K,R)
LE
16
RE
16
LD
Ciphertext block
RE
RD
16
Ciphertext block
15
LE
16
Lecture 3
Lecture 3
17
Lecture 3
Lecture 3
reason for why we expand each 4-bit block into a 6-bit block in
the manner explained will become clear shortly.
The 56-bit key is divided into two halves, each half shifted separately, and the combined 56-bit key permuted/contracted
to yield a 48-bit round key. How this is done will be explained
later.
The 48 bits of the expanded output produced by the E-step are
XORed with the round key. This is referred to as key mixing.
The output produced by the previous step is broken into eight
six-bit words. Each six-bit word goes through a substitution step;
its replacement is a 4-bit word. The substitution is carried out
with an S-box, as explained in greater detail in Section 3.3.2.
[The name S-Box stands for Substitution Box.]
So after all the substitutions, we again end up with a 32-bit word.
The 32-bits of the previous step then go through a P-box based
permutation, as shown in Figure 4.
What comes out of the P-box is then XORed with the left half
of the 64-bit block that we started out with. The output of this
19
Lecture 3
XORing operation gives us the right half block for the next round.
Note that the goal of the substitution step implemented by the
S-box is to introduce diffusion in the generation of the output
from the input. Diffusion means that each plaintext bit must
affect as many ciphertext bits as possible.
The strategy used for creating the different round keys from the
main key is meant to introduce confusion into the encryption
process. Confusion in this context means that the relationship between the encryption key and the ciphertext must be
as complex as possible. Another way of describing confusion
would be that each bit of the key must affect as many bits as
possible of the output ciphertext block.
Diffusion and confusion are the two cornerstones of block cipher
design.
20
LE i1
Lecture 3
RE i1
32 bits
32 bits
Expansion Permutation
48 bits
Round Key K
48 bits
Substitution with 8 Sboxes
32 bits
Permutation with PBox
LE
RE
21
Lecture 3
Lecture 3
S-box.
In the design of the DES, the S-boxes were tuned to enhance the
resistance of DES to what is known as the differential cryptanalysis attack, or, sometimes more briefly as differential attack. [As will be explained in much greater detail (and also demonstrated) in Section 8.9 of Lecture
8, differential cryptanalysis of block ciphers consists of presenting to the encryption algorithm pairs of
plaintext bit patterns with known differences between them and examining the differences between the
corresponding cyphertext outputs. The outputs are usually recorded at the input to the last round of
the cipher. Lets represent one plaintext bit block by X = [X1 , X2 , ...., Xn ] where Xi denotes the ith bit
in the block, and lets represent the corresponding output bit block by Y = [Y1 , Y2 , ..., Yn ]. By the difference between two plaintext bit blocks X and X we mean X = X X . The difference between
the corresponding outputs Y and Y is given by Y = Y Y . The pair (X, Y ) is known as a
differential. In an ideally randomizing block cipher, the probability of Y being a particular value for
a given X is 1/2n for an n-bit block cipher. What is interesting is that the probabilities of Y taking
on different values for a given X can be shown to be independent of the encryption key because of the
properties of the XOR operator, but these probabilities are strongly dependent on the S-box tables. By
feeding into a cipher several pairs of plaintext blocks with known X and observing the corresponding
Y , it is possible to establish constraints on the round key bits encountered along the different paths
in the encryption processing chain. (By constraints I mean the following: Speaking hypothetically for
the purpose of illustrating a point and focusing on just one round of DES, suppose we can show that
the following condition can be expected to be obeyed with high probability: Xi Yi Ki = 0
for some bit Ki of the encryption key, then it must be the case that Ki = X Y .) Note that
differential cryptanalysis is a chosen plaintext attack, meaning that the attacker will feed known
plaintext bit patterns into the cipher and analyze the corresponding outputs in order to figure out the
encryption key. In a theoretical analysis of an attack based on differential cryptanalysis, it was shown
by Eli Biham and Adi Shamir in 1990 that the DESs encryption key could be figured out provided one
23
Lecture 3
could feed known 247 plaintext blocks into the cipher. For a tutorial by Howard Heys on differential
cryptanalysis, see http://www.engr.mun.ca/~howard/PAPERS/ldc_tutorial.pdf. The title of the
tutorial is A Tutorial on Linear and Differential Cryptanalysis.
24
Lecture 3
Shown on the next page are the eight S-boxes, S1 through S8,
each S-box being a 416 substitution table that is used to convert
6 incoming bits into 4 outgoing bits.
As mentioned earlier, each row of a substitution table is indexed
by the two outermost bits of a six-bit block and each column by
the remaining inner 4 bit.
25
Lecture 3
48 bits
S1
S2
S3
S4
S5
S6
S7
S8
32 bits
Figure 5: The 48 bits coming out of the expansion permutation are first XORed with the round key and then, as
shown, fed into the 8 S-boxes of DES. (This figure is from Lecture 3 of
Lecture Notes on Computer and Network Security by Avi Kak)
26
14
0
4
15
4 13
15 7
1 14
12 8
15
3
0
13
1 8
13 4
14 7
8 10
10
13
13
1
0 9
7 0
6 4
10 13
7
13
10
3
13 14
8 11
6 9
15 0
2
14
4
11
12 4
11 2
2 1
8 12
12
10
9
4
1 10
15 4
14 15
3 2
4
13
1
6
11 2
0 11
4 11
11 13
13
1
7
2
2 8
15 13
11 4
1 14
Lecture 3
27
for S-box S1
6 12 5 9
12 11 9 5
9 7 3 10
3 14 10 0
0
9
3
5
0 7
3 8
5 0
6 13
2 13
1 10
12 6
7 12
12
6
9
0
12 7
5 14
2 12
14 3
11 4 2 8
12 11 15 1
5 10 14 7
11 5 2 12
8 5
2 12
3 14
5 11
11 12 4 15
1 10 14 9
5 2 8 4
12 7 2 14
3 15
15 10
12 5
0 9
13
3
6
10
3 4
13 14
4 10
1 7
14 7 5 11
0 11 3 8
1 13 11 6
6 0 8 13
9 7
5 12
6 8
0 15
3 14
6 11
10 13
9 0
0
9
3
4
5 10
11 5
2 15
14 9
5 10
2 15
0 5
14 2
14 9
8 6
0 14
5 3
6 1
8 6
9 2
3 12
5 0 12 7
0 14 9 2
15 3 5 8
3 5 6 11
Lecture 3
15
0
1
18
P-Box Permutation
6 19 20 28 11 27 16
14 22 25 4 17 30 9
7 23 13 31 26 2 8
12 29 5 21 10 3 24
This permutation table says that the 0th output bit will be the
15th bit of the input, the 1st output bit the 6th bit of the input,
and so on, for all of the 32 bits of the output that are obtained
from the 32 bits of the input.
Do NOT associate any meaning with the row-organization of the
table except for the following: Each row of the table tells us
how to select the input bits for the output byte corresponding to
the row. For example, for the second output byte, the first entry
in the second row means that the 0th bit of the second output
byte meaning the 8th bit of the output will be the 0th bit
28
Lecture 3
29
Lecture 3
The initial 56-bit key may be represented as 8 bytes, with the last
bit (the least significant bit) of each byte used as a parity bit.
The relevant 56 bits are subject to a permutation at the beginning before any round keys are generated. This is referred to as
Permutation Choice 1 that is shown in Section 3.3.6.
At the beginning of each round, we divide the 56 relevant key bits
into two 28 bit halves and circularly shift to the left each half by
one or two bits, depending on the round, as shown in the table
on the next page.
For generating the round key, we join together the two halves and
apply a 56 bit to 48 bit contracting permutation (this is referred
to as Permutation Choice 2, as shown in Section 3.3.7) to the
joined bit pattern. The resulting 48 bits constitute our round
key.
The contraction permutation shown in Permutation Choice 2,
along with the one-bit or two-bit rotation of the two key halves
30
Lecture 3
prior to each round, is meant to ensure that each bit of the original
encryption key is used in roughly 14 of the 16 rounds.
The two halves of the encryption key generated in each round are
fed as the two halves going into the next round.
The table shown below tells us how many positions to use for
the left circular shift that is applied to the two key halves at the
beginning of each round:
Round Number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Lecture 3
32
Lecture 3
Permutation
56 48 40 32
0 57 49 41
9 1 58 50
18 10 2 59
62 54 46 38
6 61 53 45
13 5 60 52
20 12 4 27
Choice 1
24 16 8
33 25 17
42 34 26
51 43 35
30 22 14
37 29 21
44 36 28
19 11 3
The bit indexing is based on using the range 0-63 for addressing
the bit positions in an 8-byte bit pattern in which the last bit of
each byte is used as a parity bit. [Note that each row shown above has has
only 7 positions the positions corresponding to the parity bit are NOT included above.
That is, you will NOT see the positions 7, 15, etc., listed in the permutations shown.
Nevertheless, the bit addressing spans the full 0-63 range.]
The permutations
shown above do not constitute a table, in the sense that the
rows and the columns do NOT carry any special and separate
meanings. The permutation order for the bits is given by reading
the entries shown from the upper left corner to the lower right
corner.
This permutation tells us that the 0th bit of the output will be
33
Lecture 3
the 56th bit of the input (in a 64 bit representation of the 56-bit
encryption key), the 1st bit of the output the 48th bit of the input,
and so on, until finally we have for the 55th bit of the output the
3rd bit of the input.
When programming in Python using the BitVector module, or in
Perl using the Algorithm::BitVector module, the permutations
shown on the previous page can be carried out trivially by calling the permute() method of the modules. Using Python to
illustrate, you could call
user_key_bv = BitVector( textstring = user-supplied_key )
key_bv = user_key_bv.permute( initial_permutation )
34
Lecture 3
13
14
25
40
50
33
Permutation Choice 2
16 10 23 0 4 2
5 20 9 22 18 11
7 15 6 26 19 12
51 30 36 46 54 29
44 32 47 43 48 38
52 45 41 49 35 28
27
3
1
39
55
31
As on the previous page, bit addressing shown above uses the full
0-63 range in an 8-byte pattern. Since the last bit of each byte is
used as a parity bit, you will not see the bit positions 7, 15, 23,
etc., in the permutation shown above.
As with permutation shown on the previous page, what is shown
above is NOT a table, in the sense that the rows and the columns
do not carry any special and separate meanings. The permutation
order for the bits is given by reading the entries shown from the
upper left corner to the lower right corner.
Since there are only six rows and there are 8 positions in each
35
Lecture 3
36
Lecture 3
The substitution step is very effective as far as diffusion is concerned. It has been shown that if you change just one bit of the
64-bit input data block, on the average that alters 34 bits of the
ciphertext block.
The manner in which the round keys are generated from the
encryption key is also very effective as far as confusion is concerned. It has been shown that if you change just one bit of
the encryption key, on the average that changes 35 bits of the
ciphertext.
Both effects mentioned above are referred to as the avalanche
effect.
And, of course, the 56-bit encryption key means a key space of
size 256 7.2 1016.
37
Lecture 3
Assuming that, on the average, youd need to try half the keys
in a brute-force attack, a machine able to process 1000 keys per
microsecond would need roughly 13 months to break the code.
However, a parallel-processing machine trying 1 million keys simultaneously would need only about 10 hours. (EFF took
three days on a specially architectured machine to
break the code.)
The official document that presents the DES standard can be
found at:
http://www.itl.nist.gov/fipspubs/fip46-2.htm
38
Lecture 3
1. A text file named myfile.txt that you created with a run-ofthe-mill editor contains just the following word:
hello
If you examine this file with a command like
hexdump
-C
myfile.txt
you are likely to see the following bytes (in hex) in the file:
68
65
6C
6C
6F
0A
Lets now try to encrypt the contents of this text file with a 4-bit
block cipher whose codebook contains the following entries:
6, 0, 13, 4, 3, 1, 14, 8, 7, 12, 9, 15, 5, 2, 11, 10
Lets say that I write the encrypted output into a different file and
then examine this new file with the hexdump -C command.
What will I see in the encrypted file?
2. In general, in a block cipher, we replace N bits from the plaintext
with N bits of ciphertext. What defines an ideal block cipher?
39
Lecture 3
Lecture 3
11. DES encryption was broken in 1999. Why do you think that
happened?
12. Since DES was cracked, does that make this an unimportant
cipher?
Lecture 3
42