CSS411 Cryptography

S-DES Book Chapter

PDF 4. Book chapter 3.1, pages 50-56: S-DES structure, key generation, encryption detail, analysis and the relationship to DES.

23 min read

Chapter overviewSearch on YouTube

Purpose of S-DESSearch on YouTube

This page follows the book section 3.1 on Simplified DES (S-DES). The book puts S-DES before full DES. A study of S-DES makes DES easier to understand.

  • S-DES is an educational algorithm. It is not a secure algorithm.
  • It has similar properties and structure to DES, but much smaller parameters.
  • Professor Edward Schaefer of Santa Clara University developed it ([SCHA96]).
  • The book tells you to work through an example by hand while you read.
  • A footnote says that you can skip S-DES on a first reading. If the details of DES confuse you, come back to S-DES.

Inputs and outputsSearch on YouTube

The S-DES encryption algorithm takes an 8-bit block of plaintext (example: 1011110110111101) and a 10-bit key. It produces an 8-bit block of ciphertext.

The decryption algorithm takes the 8-bit block of ciphertext and the same 10-bit key. It produces the original 8-bit block of plaintext.

Five functionsSearch on YouTube

The encryption algorithm has five functions:

  1. An initial permutation (IP).
  2. A complex function fKf_K. It does permutation and substitution, and it uses a key input.
  3. A simple permutation function SW. It switches the two halves of the data.
  4. The function fKf_K again, with the other subkey.
  5. A permutation function that is the inverse of IP (IP−1\text{IP}^{-1}).

The book repeats a lesson from chapter 2. Multiple stages of permutation and substitution give a more complex algorithm. This makes cryptanalysis more difficult.

Composition formSearch on YouTube

The book writes encryption as a composition of functions (Figure 3.1):

IP−1∘fK2∘SW∘fK1∘IP\text{IP}^{-1} \circ f_{K_2} \circ \text{SW} \circ f_{K_1} \circ \text{IP} ciphertext=IP−1(fK2(SW(fK1(IP(plaintext)))))\text{ciphertext} = \text{IP}^{-1} \bigl( f_{K_2} ( \text{SW} ( f_{K_1} ( \text{IP} ( \text{plaintext} ))))\bigr)

The two subkeys are:

K1=P8(Shift(P10(key))),K2=P8(Shift(Shift(P10(key))))K_1 = \text{P8}(\text{Shift}(\text{P10}(\text{key}))), \qquad K_2 = \text{P8}(\text{Shift}(\text{Shift}(\text{P10}(\text{key}))))

Decryption formSearch on YouTube

Decryption is essentially the reverse of encryption. The subkey order changes:

plaintext=IP−1(fK1(SW(fK2(IP(ciphertext)))))\text{plaintext} = \text{IP}^{-1} \bigl( f_{K_1} ( \text{SW} ( f_{K_2} ( \text{IP} ( \text{ciphertext} ))))\bigr)
StepEncryptionDecryption
1IPIP
2fKf_K with K1K_1fKf_K with K2K_2
3SWSW
4fKf_K with K2K_2fKf_K with K1K_1
5IP−1\text{IP}^{-1}IP−1\text{IP}^{-1}

fKf_K XORs F(R,SK)F(R, SK) into the left half. The right half does not change. Thus the same fKf_K with the same subkey removes the XOR again. Decryption needs no inverse of FF or of the S-boxes. Only the subkey order changes.

Key generationSearch on YouTube

Why a 10-bit keySearch on YouTube

The function fKf_K takes the data and an 8-bit key. The book gives three possible designs:

OptionBook comment
A 16-bit key, split into two 8-bit subkeysPossible design: one subkey for each fKf_K
One 8-bit key, used twicePossible design: the same key in both fKf_K stages
A 10-bit key, with two 8-bit subkeys made from itThe compromise that S-DES uses

The key first goes through the permutation P10. Then a shift operation occurs. The shift output goes through P8 and gives subkey K1K_1. The shift output also goes into a second shift and a second P8. This gives subkey K2K_2 (Figure 3.2).

P10 and P8Search on YouTube

S-DES uses a 10-bit key shared between sender and receiver. The key schedule makes two 8-bit subkeys for particular stages of encryption and decryption.

Call the 10-bit key (k1,k2,…,k10)(k_1, k_2, \dots, k_{10}). The book defines P10 as:

P10(k1,k2,…,k10)=(k3,k5,k2,k7,k4,k10,k1,k9,k8,k6)\text{P10}(k_1, k_2, \dots, k_{10}) = (k_3, k_5, k_2, k_7, k_4, k_{10}, k_1, k_9, k_8, k_6)
P1035274101986
P8637485109

Read each table from left to right. Each position gives the input bit for that output position. Thus the first output bit is input bit 3. The second output bit is input bit 5. P8 selects and permutes 8 of the 10 bits.

Worked key scheduleSearch on YouTube

The book uses the key 10100000101010000010:

StepFirst 5 bitsSecond 5 bits
Key10100101000001000010
After P1010000100000110001100
After LS-1 (circular left shift by 1)00001000011100011000
After LS-2 (2 more positions)00100001000001100011
  1. Apply P8 to the LS-1 output 00001110000000111000. The result is K1=10100100K_1 = 10100100.
  2. Go back to the two 5-bit strings from LS-1.
  3. Do a circular left shift of 2 positions on each string.
  4. Apply P8 to 00100000110010000011. The result is K2=01000011K_2 = 01000011.
K1=P8(LS-1(P10(key))),K2=P8(LS-2(LS-1(P10(key))))K_1 = \text{P8}(\text{LS-1}(\text{P10}(\text{key}))), \qquad K_2 = \text{P8}(\text{LS-2}(\text{LS-1}(\text{P10}(\text{key}))))

P10 = 3 5 2 7 4 | 10 1 9 8 6. P8 = 6 3 7 4 | 8 5 10 9. Shifts: 1, then 2 more. P8 runs after each shift step.

Encryption detailSearch on YouTube

Initial and final permutationsSearch on YouTube

The input is an 8-bit block of plaintext. IP permutes it first:

IP26314857

IP keeps all 8 bits of the plaintext, but it mixes them. At the end of the algorithm, the inverse permutation occurs:

IP−1\text{IP}^{-1}41357286

An example shows that the second permutation is the reverse of the first: IP−1(IP(X))=X\text{IP}^{-1}(\text{IP}(X)) = X.

The function f_KSearch on YouTube

fKf_K is the most complex part of S-DES. It combines permutation and substitution functions. Let L be the leftmost 4 bits and R the rightmost 4 bits of the 8-bit input. Let F be a mapping from 4-bit strings to 4-bit strings. F is not necessarily one-to-one.

fK(L,R)=(L⊕F(R,SK),  R)f_K(L, R) = (L \oplus F(R, SK), \; R)

SK is a subkey. ⊕\oplus is the bit-by-bit exclusive-OR.

Book example: the IP output is 1011110110111101. Assume F(1101,SK)=1110F(1101, SK) = 1110 for some key SK. Then 1011⊕1110=01011011 \oplus 1110 = 0101, so:

fK(10111101)=01011101f_K(10111101) = 01011101

Expansion and permutationSearch on YouTube

The mapping FF takes a 4-bit number (n1,n2,n3,n4)(n_1, n_2, n_3, n_4). The first operation is an expansion/permutation:

E/P41232341

The book shows the 8 output bits in two rows:

RowBits
Top row (to S0)n4  ∣  n1  n2  ∣  n3n_4 \;\vert\; n_1 \; n_2 \;\vert\; n_3
Bottom row (to S1)n2  ∣  n3  n4  ∣  n1n_2 \;\vert\; n_3 \; n_4 \;\vert\; n_1

XOR with the subkeySearch on YouTube

XOR the 8-bit subkey K1=(k11,k12,…,k18)K_1 = (k_{11}, k_{12}, \dots, k_{18}) into these bits:

n4⊕k11,    n1⊕k12,    n2⊕k13,    n3⊕k14n2⊕k15,    n3⊕k16,    n4⊕k17,    n1⊕k18\begin{aligned} &n_4 \oplus k_{11}, \;\; n_1 \oplus k_{12}, \;\; n_2 \oplus k_{13}, \;\; n_3 \oplus k_{14} \\ &n_2 \oplus k_{15}, \;\; n_3 \oplus k_{16}, \;\; n_4 \oplus k_{17}, \;\; n_1 \oplus k_{18} \end{aligned}

Rename the 8 bits:

col 0col 1col 2col 3
Row 0p0,0p_{0,0}p0,1p_{0,1}p0,2p_{0,2}p0,3p_{0,3}
Row 1p1,0p_{1,0}p1,1p_{1,1}p1,2p_{1,2}p1,3p_{1,3}

The first 4 bits (row 0) go into S-box S0. S0 gives a 2-bit output. The other 4 bits (row 1) go into S1. S1 gives another 2-bit output.

The S-boxesSearch on YouTube

The entries are 2-bit values, shown in decimal:

S0S_00123
01032
13210
20213
33132
S1S_10123
00123
12013
23010
32103

To use an S-box:

  1. Use the first and fourth input bits as a 2-bit row number.
  2. Use the second and third input bits as a 2-bit column number.
  3. Write the entry at that row and column in base 2. This is the 2-bit output.

Book example: (p0,0,p0,3)=(00)(p_{0,0}, p_{0,3}) = (00) and (p0,1,p0,2)=(10)(p_{0,1}, p_{0,2}) = (10). Read row 0, column 2 of S0. The entry is 3, or 1111 in binary. (p1,0,p1,3)(p_{1,0}, p_{1,3}) and (p1,1,p1,2)(p_{1,1}, p_{1,2}) select a row and column of S1 in the same way.

P4 permutationSearch on YouTube

The 4 bits from S0 and S1 go through one more permutation:

P42431

The output of P4 is the output of the function FF.

The switch functionSearch on YouTube

fKf_K changes only the leftmost 4 bits of its input. The switch function SW interchanges the left 4 bits and the right 4 bits. Thus the second fKf_K operates on a different 4 bits.

Instance of fKf_KBits that go into FKey
FirstRight 4 bits of the IP outputK1K_1
SecondRight 4 bits after SW (the old left half)K2K_2

In the second instance, the E/P, S0, S1 and P4 functions do not change. Only the key input changes to K2K_2.

Analysis of S-DESSearch on YouTube

Brute-force attackSearch on YouTube

A brute-force attack on S-DES is certainly feasible. A 10-bit key gives only 210=10242^{10} = 1024 possible keys. The attacker tries each key on the ciphertext. Then the attacker checks if the result is reasonable plaintext.

Known-plaintext equationsSearch on YouTube

The book considers a known-plaintext attack:

  • The attacker knows one plaintext (p1,…,p8)(p_1, \dots, p_8) and its ciphertext (c1,…,c8)(c_1, \dots, c_8).
  • The key (k1,…,k10)(k_1, \dots, k_{10}) is unknown.

Each cic_i is a polynomial function gig_i of the pjp_j and kjk_j bits. Thus the algorithm becomes 8 nonlinear equations in 10 unknowns. There are a number of possible solutions. The attacker can calculate and analyze each solution.

Source of nonlinearitySearch on YouTube

  • All the permutations and additions are linear maps.
  • The S-boxes give the nonlinearity.

Rename the S0 input (p0,0,p0,1,p0,2,p0,3)=(a,b,c,d)(p_{0,0}, p_{0,1}, p_{0,2}, p_{0,3}) = (a, b, c, d). Rename the S1 input (p1,0,p1,1,p1,2,p1,3)=(w,x,y,z)(p_{1,0}, p_{1,1}, p_{1,2}, p_{1,3}) = (w, x, y, z). Let the 4-bit output be (q,r,s,t)(q, r, s, t). These equations define S0:

q=abcd+ab+ac+b+dq = abcd + ab + ac + b + d r=abcd+abd+ab+ac+ad+a+c+1r = abcd + abd + ab + ac + ad + a + c + 1

All additions are modulo 2. Similar equations define S1. The algorithm alternates linear maps and these nonlinear maps. This gives complex polynomial expressions for the ciphertext bits. Thus cryptanalysis is difficult.

Scale of the problemSearch on YouTube

QuantityValue
Unknowns (key bits)10
Equations (ciphertext bits)8
Possible terms in one binary polynomial of 10 unknowns2102^{10}
Average expected terms in each equation292^9

The book says that a reader can try to find these equations with a symbolic processor. Either the reader or the software stops before much progress occurs.

Exam figures: brute force needs at most 210=10242^{10} = 1024 trials. A known-plaintext attack gives 8 nonlinear equations in 10 unknowns.

Relationship to DESSearch on YouTube

DES compositionSearch on YouTube

DES operates on 64-bit blocks of input. The book writes the DES encryption scheme as:

IP−1∘fK16∘SW∘fK15∘SW∘⋯∘SW∘fK1∘IP\text{IP}^{-1} \circ f_{K_{16}} \circ \text{SW} \circ f_{K_{15}} \circ \text{SW} \circ \dots \circ \text{SW} \circ f_{K_1} \circ \text{IP}

DES uses a 56-bit key. The key schedule calculates sixteen 48-bit subkeys. It starts with an initial permutation of 56 bits. A sequence of shifts and permutations of 48 bits follows.

Scaled-up partsSearch on YouTube

ItemS-DESDES
Input block8 bits64 bits
Key10 bits56 bits
SubkeysTwo 8-bit subkeysSixteen 48-bit subkeys
FF input4 bits (n1,…,n4)(n_1, \dots, n_4)32 bits (n1,…,n32)(n_1, \dots, n_{32})
Expansion output8 bits in 2 rows48 bits in 8 rows
Subkey XOR8-bit subkey48-bit subkey
S-boxes2 boxes, 4 rows × 4 columns8 boxes, 4 rows × 16 columns
S-box rowFirst and fourth bitsFirst and last bits of the row
S-box columnMiddle 2 bitsMiddle 4 bits

The book draws the DES expansion as a matrix of 8 rows. Each row has 6 bits:

n32 | n1  n2  n3  n4  | n5
n4  | n5  n6  n7  n8  | n9
 .  |       .         |  .
n28 | n29 n30 n31 n32 | n1

XOR this matrix with a 48-bit subkey. Each of the 8 rows then goes into one S-box.

For "explain S-DES", write the five functions, the key schedule and the FF steps. For "S-DES versus DES", use the table above.

Quick self-testSearch on YouTube

What sizes does S-DES use, and why does the key have 10 bits?

The plaintext block is 8 bits. The key is 10 bits. The ciphertext block is 8 bits. The two fKf_K stages each need an 8-bit subkey. A 16-bit key or one 8-bit key used twice were possible. The 10-bit key is the compromise: P10, shifts and P8 make both subkeys.

Who developed S-DES and what is its purpose?

Professor Edward Schaefer of Santa Clara University. It is an educational algorithm, not a secure one. It has a structure like DES with much smaller parameters. A study of S-DES helps you understand DES.

Compute K1 and K2 for the key 1010000010.

P10 gives 10000  0110010000\;01100. LS-1 gives 00001  1100000001\;11000. P8 gives K1=10100100K_1 = 10100100. LS-2 gives 00100  0001100100\;00011. P8 gives K2=01000011K_2 = 01000011.

Write the decryption composition.

plaintext=IP−1(fK1(SW(fK2(IP(ciphertext)))))\text{plaintext} = \text{IP}^{-1}(f_{K_1}(\text{SW}(f_{K_2}(\text{IP}(\text{ciphertext}))))). The functions are the same as in encryption. K2K_2 is used first and K1K_1 second.

Define f_K with the book example.

fK(L,R)=(L⊕F(R,SK),R)f_K(L, R) = (L \oplus F(R, SK), R). The IP output is 1011110110111101 and F(1101,SK)=1110F(1101, SK) = 1110. Then 1011⊕1110=01011011 \oplus 1110 = 0101, so fK(10111101)=01011101f_K(10111101) = 01011101.

Give the S-box lookup rule with the book example.

The first and fourth bits give the row. The second and third bits give the column. The entry in base 2 is the output. Row 0, column 2 of S0 is 3, so the output is 1111.

Why is SW necessary?

fKf_K changes only the leftmost 4 bits. SW interchanges the halves. Thus the second fKf_K operates on different bits. It uses the same E/P, S0, S1 and P4, with key K2K_2.

What does the analysis say about breaking S-DES?

Brute force needs only 210=10242^{10} = 1024 trials. A known-plaintext attack gives 8 nonlinear equations in 10 unknowns. Permutations and additions are linear. Only the S-boxes are nonlinear. Each equation has about 292^9 terms on average.

State the relationship between S-DES and DES.

DES has 64-bit blocks and a 56-bit key, with sixteen 48-bit subkeys. FF acts on 32 bits, and the expansion gives 48 bits. DES has 8 S-boxes with 4 rows and 16 columns. The outer bits select the row and the middle 4 bits select the column.

  • S-DES (Schaefer) is an educational cipher: 8-bit block, 10-bit key, five functions, two 8-bit subkeys.
  • Encryption: IP−1∘fK2∘SW∘fK1∘IP\text{IP}^{-1} \circ f_{K_2} \circ \text{SW} \circ f_{K_1} \circ \text{IP}. Decryption uses K2K_2 first, then K1K_1.
  • Key schedule: P10, LS-1, P8 gives K1K_1. LS-2 and P8 give K2K_2. Key 10100000101010000010 gives K1=10100100K_1 = 10100100 and K2=01000011K_2 = 01000011.
  • fK(L,R)=(L⊕F(R,SK),R)f_K(L,R) = (L \oplus F(R, SK), R). FF is E/P, XOR with the subkey, S0 and S1, then P4.
  • Brute force needs 210=10242^{10} = 1024 trials. Cryptanalysis gives 8 nonlinear equations in 10 unknowns. Only the S-boxes are nonlinear.
  • DES scales every part: 64-bit block, 56-bit key, sixteen 48-bit subkeys, 32-bit FF input, 8 S-boxes of 4 × 16.