Key Expansion Function and Key Schedule of DES(Data Encryption Standard) Algorithm

Ritul
4 min readApr 4, 2019

--

Introduction

DES is a symmetric key algorithm for encryption. DES is a block cipher — meaning it operates on plaintext blocks of a given size (64-bits) and returns ciphertext blocks of the same size. It implements Feistel block cipher. In this story, I will discuss the Key Expansion Function and Key Schedule of DES.

You should be quite familiar with the Feistel block cipher and some jargons of cryptography( as symmetric, encryption, cipher, plain text, etc), but don’t worry I will try to keep it as simple as possible.

Key Expansion function :

It is the way through which we get 16 subkeys of 48 bits from the initial 64 bit key for each round of DES. The generated keys will be used during the encryption of plaintext.

Initial Key( 64 bits)

Suppose K is the initial key,

K = 00010011 00110100 01010111 01111001 10011011 10111100 11011111 11110001

Permuted Key (56 bits)

Now we will reduce our key size from 64 bits to 56 bits through permutation box pc1. Since the first entry in the table is “57”, this means that the 57th bit of the original key K becomes the first bit of the permuted key K+. The 49th bit of the original key becomes the second bit of the permuted key. The 4th bit of the original key is the last bit of the permuted key.


PC-1

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
K+ = 1111000 0110011 0010101 0101111 0101010 1011001 1001111 0001111

Next, we will split the permuted key(56 bits) into left and right halves C0, D0 each of 28 bits,i.e.

From the permuted key K+, we getC0 = 1111000 0110011 0010101 0101111 
D0 = 0101010 1011001 1001111 0001111

Now we will get 16 blocks of Cn, Dn( 1≤n≤16) by applying the number of cyclic left shifts as per the table below.


iteration number of
Number Left Shifts

1 1
2 1
3 2
4 2
5 2
6 2
7 2
8 2
9 1
10 2
11 2
12 2
13 2
14 2
15 2
16 1

This means, for example, C3 and D3 are obtained from C2 and D2, respectively, by two left shifts, and C16 and D16 are obtained from C15 and D15, respectively, by one left shift.

From original pair C0 and D0 we obtain:C0 = 1111000011001100101010101111
D0 = 0101010101100110011110001111
C1 = 1110000110011001010101011111
D1 = 1010101011001100111100011110
C2 = 1100001100110010101010111111
D2 = 0101010110011001111000111101
C3 = 0000110011001010101011111111
D3 = 0101011001100111100011110101
C4 = 0011001100101010101111111100
D4 = 0101100110011110001111010101
C5 = 1100110010101010111111110000
D5 = 0110011001111000111101010101
C6 = 0011001010101011111111000011
D6 = 1001100111100011110101010101
C7 = 1100101010101111111100001100
D7 = 0110011110001111010101010110
C8 = 0010101010111111110000110011
D8 = 1001111000111101010101011001
C9 = 0101010101111111100001100110
D9 = 0011110001111010101010110011
C10 = 0101010111111110000110011001
D10 = 1111000111101010101011001100
C11 = 0101011111111000011001100101
D11 = 1100011110101010101100110011
C12 = 0101111111100001100110010101
D12 = 0001111010101010110011001111
C13 = 0111111110000110011001010101
D13 = 0111101010101011001100111100
C14 = 1111111000011001100101010101
D14 = 1110101010101100110011110001
C15 = 1111100001100110010101010111
D15 = 1010101010110011001111000111
C16 = 1111000011001100101010101111
D16 = 0101010101100110011110001111

Reduce the number of bits from 56 to 48 bits

Next, we will combine CnDn and apply permutation on combination to reduce the number of bits from 56 to 48.

Example: For the first key we have

C1D1 = 1110000 1100110 0101010 1011111 1010101 0110011 0011110 0011110

PC-2

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

which, after we apply the permutation PC-2, becomes

K1 = 000110 110000 001011 101111 111111 000111 000001 110010

similarly, all 15 keys would be generated. Hence our key schedule is ready.

Key Schedule:

The key schedule is nothing but the collection of all the subkeys that would be used during various rounds. The required keys are generated through the expansion function from the initial key as we have seen above.

K1 = 000110 110000 001011 101111 111111 000111 000001 110010
K2
= 011110 011010 111011 011001 110110 111100 100111 100101
K3 = 010101 011111 110010 001010 010000 101100 111110 011001
K4 = 011100 101010 110111 010110 110110 110011 010100 011101
K5 = 011111 001110 110000 000111 111010 110101 001110 101000
K6 = 011000 111010 010100 111110 010100 000111 101100 101111
K7 = 111011 001000 010010 110111 111101 100001 100010 111100
K8 = 111101 111000 101000 111010 110000 010011 101111 111011
K9 = 111000 001101 101111 101011 111011 011110 011110 000001
K10 = 101100 011111 001101 000111 101110 100100 011001 001111
K11 = 001000 010101 111111 010011 110111 101101 001110 000110
K12 = 011101 010111 000111 110101 100101 000110 011111 101001
K13 = 100101 111100 010111 010001 111110 101011 101001 000001
K14 = 010111 110100 001110 110111 111100 101110 011100 111010
K15 = 101111 111001 000110 001101 001111 010011 111100 001010
K16 = 110010 110011 110110 001011 000011 100001 011111 110101

Half of the job for encryption is done, cheers :))))))))

References:

  1. Lecture notes

--

--

Ritul
Ritul

Written by Ritul

Data Science Enthusiast | Advanced Analytics Intern at EY