28-03 — Symmetric Encryption: DES and AES

Phase: Cryptography | Subject: 28-03 Prerequisites: 28-02-classical-ciphers.md, 28-01-modular-arithmetic-review.md Next subject: 28-04-asymmetric-encryption.md


Learning Objectives

By the end of this subject, you will be able to:

  1. Explain the Feistel network structure and how it enables encryption/decryption with the same hardware
  2. Describe the DES algorithm: key schedule, S-box substitution, and permutation
  3. Compare DES, Triple DES, and AES in terms of security and structure
  4. Distinguish block cipher modes: ECB, CBC, CTR, and GCM
  5. Understand the design principles behind AES (Rijndael)

Core Content

Block Ciphers vs Stream Ciphers

Block ciphers are the workhorses of modern symmetric encryption.

Feistel Networks

A Feistel network is a structure that makes encryption and decryption nearly identical. Given a block split into two halves $(L, R)$:

Round $i$: $$L_{i+1} = R_i$$ $$R_{i+1} = L_i \oplus F(R_i, K_i)$$

where $F$ is the round function and $K_i$ is the round key.

Decryption: just reverse the order of round keys. The XOR property means: $$R_i = L_{i+1}$$ $$L_i = R_{i+1} \oplus F(L_{i+1}, K_i)$$

Key insight: $F$ does NOT need to be invertible. The Feistel structure handles invertibility.

DES (Data Encryption Standard)

Published 1977, DES dominated for 25+ years.

Parameters: - Block size: 64 bits - Key size: 56 bits (+ 8 parity bits = 64) - Rounds: 16 - Structure: Feistel network

DES round operations: 1. Expansion: 32-bit half-block expands to 48 bits 2. Key mixing: XOR with 48-bit round key 3. Substitution: 8 S-boxes, each maps 6 bits → 4 bits (nonlinear — crucial for security!) 4. Permutation: fixed P-box shuffles 32 bits

The S-boxes are the heart of DES security. They are carefully designed to be: - Nonlinear (resists linear cryptanalysis) - Not close to linear functions (resists differential cryptanalysis) - Each output bit depends on multiple input bits (avalanche effect)

⚠️ CRITICAL: The 56-bit key space ($2^{56} \approx 7.2 \times 10^{16}$) is now too small. DES can be brute-forced in under 24 hours with specialized hardware. This is why DES was deprecated.

DES key schedule: the 56-bit key is permuted and split into two 28-bit halves. Each round, the halves are rotated left by 1 or 2 bits, then 48 bits are selected via compression permutation.

Triple DES (3DES)

To extend DES security without a new cipher:

$$C = E_{K_3}(D_{K_2}(E_{K_1}(P)))$$

AES (Advanced Encryption Standard)

Chosen in 2001 after a public competition. Rijndael (by Joan Daemen and Vincent Rijmen) was selected.

Parameters: - Block size: 128 bits - Key sizes: 128, 192, or 256 bits - Rounds: 10 (AES-128), 12 (AES-192), 14 (AES-256) - Structure: Substitution-Permutation Network (SPN), not Feistel

AES round operations (operating on a 4×4 byte state matrix):

Step Operation Description
SubBytes Nonlinear byte substitution S-box (inversion in $\mathbb{F}_{2^8}$ + affine transform)
ShiftRows Row-wise cyclic shift Rows 1,2,3 shift by 1,2,3 bytes
MixColumns Column mixing Each column multiplied by MDS matrix in $\mathbb{F}_{2^8}$
AddRoundKey XOR with round key Key material incorporated

The last round omits MixColumns (so encryption and decryption are not identical, unlike Feistel ciphers).

AES-128 key schedule: - 128-bit key → 11 round keys (one for initial AddRoundKey + 10 rounds) - Uses S-box, rotation, and round constants derived from $x^{i-1}$ in $\mathbb{F}_{2^8}$

Block Cipher Modes of Operation

Mode Description Security Properties
ECB (Electronic Codebook) Each block encrypted independently INSECURE — identical plaintext blocks → identical ciphertext blocks. Pattern visible!
CBC (Cipher Block Chaining) XOR previous ciphertext with current plaintext Hides patterns; needs random IV
CTR (Counter) Encrypt counter values, XOR with plaintext Parallelizable; turns block cipher into stream cipher
GCM (Galois/Counter Mode) CTR encryption + authentication tag Authenticated encryption (confidentiality + integrity)

⚠️ CRITICAL: ECB mode should NEVER be used for structured data. The famous "ECB penguin" shows why — the image outline remains visible because identical blocks encrypt identically.

CBC encryption: $$C_1 = E_K(P_1 \oplus IV)$$ $$C_i = E_K(P_i \oplus C_{i-1}), \quad i \geq 2$$

CTR encryption: $$C_i = P_i \oplus E_K(\text{counter} + i)$$

CTR is widely preferred for its simplicity and parallelism.


Key Terms

Worked Examples

Example 1: Feistel Round

Given $L_0 = 1010_2$, $R_0 = 0110_2$, and round function $F(R, K) = R \oplus K$ with $K_1 = 0011_2$, compute $L_1, R_1$ and then decrypt.

Solution:

$L_1 = R_0 = 0110$ $R_1 = L_0 \oplus F(R_0, K_1) = 1010 \oplus (0110 \oplus 0011) = 1010 \oplus 0101 = 1111$

Decrypt: $R_0 = L_1 = 0110$, $L_0 = R_1 \oplus F(L_1, K_1) = 1111 \oplus (0110 \oplus 0011) = 1111 \oplus 0101 = 1010$. ✓

Click for answer $(L_1, R_1) = (0110, 1111)$. Decryption reverses perfectly.

Example 2: ECB vs CBC

Encrypt "AB AB AB AB" (4 identical blocks) with a hypothetical block cipher. Show ECB and CBC output.

Solution:

ECB: $C = E_K(A) | E_K(A) | E_K(A) | E_K(A)$. Four identical ciphertext blocks! An observer knows the plaintext repeats.

CBC: $C_1 = E_K(A \oplus IV)$, $C_2 = E_K(A \oplus C_1)$, $C_3 = E_K(A \oplus C_2)$, $C_4 = E_K(A \oplus C_3)$. All four ciphertext blocks differ (with high probability), hiding the repetition.

Click for answer ECB reveals structure; CBC hides it. Never use ECB for real data.

Example 3: AES S-box in $\mathbb{F}_{2^8}$

The AES S-box computes $y = A(x^{-1}) + b$ in $\mathbb{F}_{2^8}$, where $x^{-1}$ is the multiplicative inverse (with $0^{-1} = 0$), $A$ is an affine transformation, and $b$ is the constant $0x63$. For input $0x53$:

Solution:

In $\mathbb{F}_{2^8}$ with irreducible polynomial $m(x) = x^8 + x^4 + x^3 + x + 1$: $0x53$ corresponds to polynomial $x^6 + x^4 + x + 1$.

Use Extended Euclidean in $\mathbb{F}_{2^8}$: inverse of $x^6 + x^4 + x + 1$ mod $m(x)$ is $x^7 + x^6 + x^3 + x$ ($0xCA$).

Apply affine transform $A$ (matrix multiplication + $0x63$): result is $0xED$.

So S-box$(0x53) = 0xED$.

Click for answer AES S-box$(0x53) = 0xED$. The S-box inversion provides nonlinearity, and the affine transform prevents algebraic attacks based on the simple inversion.


Quiz

Q1: What does the concept of Feistel network primarily refer to in this subject?

A) A historical anecdote about Feistel network B) A visual representation of Feistel network C) A computational error related to Feistel network D) The definition and application of Feistel network

Correct: D)

Q2: Which of the following is the key formula discussed in this subject?

A) A simplified version of L_{i+1} = R_i... B) The inverse operation of the formula in question C) An unrelated formula from a different topic D) L_{i+1} = R_i

Correct: D)

Q3: What is the primary purpose of AES round operations?

A) It is primarily a historical notation system B) It is used only in advanced research contexts C) It replaces all other methods in this domain D) It is used to aes round operations in mathematical analysis

Correct: D)

Q4: Which statement about The last round omits MixColumns is TRUE?

A) The last round omits MixColumns is an advanced topic beyond this subject's scope B) The last round omits MixColumns is a fundamental concept covered in this subject C) The last round omits MixColumns is mentioned only as a historical footnote D) The last round omits MixColumns is not related to this subject

Correct: B)

Q5: Based on the worked examples in this subject, what is the correct result?

A) The inverse of the correct answer B) ECB vs CBC C) An unrelated numerical value D) A different result from a common mistake

Correct: B)

Q6: How are The last round omits MixColumns and INSECURE related?

A) The last round omits MixColumns is the inverse of INSECURE B) The last round omits MixColumns is a special case of INSECURE C) The last round omits MixColumns and INSECURE are closely related concepts D) The last round omits MixColumns and INSECURE are completely unrelated topics

Correct: C)

Q7: What is a common pitfall when working with S-box?

A) The main error with S-box is using it when it is not needed B) A common mistake is confusing S-box with a similar concept C) S-box is always computed the same way in all contexts D) S-box has no common misconceptions

Correct: B)

Q8: When should you apply AES (Rijndael)?

A) Apply AES (Rijndael) to solve problems in this subject's domain B) Use AES (Rijndael) only in pure mathematics contexts C) AES (Rijndael) is not practically useful D) Avoid AES (Rijndael) unless explicitly instructed

Correct: A)

Practice Problems

  1. In a Feistel network, if $F$ is a constant function (always returns 0), what does encryption do?

    Click for answer $L_1 = R_0$, $R_1 = L_0 \oplus 0 = L_0$. After two rounds: $L_2 = L_0$, $R_2 = R_0$ — the original block! This demonstrates why the round function must be nontrivial.

  2. How many possible DES keys are there? How long to brute force at $10^{12}$ keys/second?

    Click for answer $2^{56} \approx 7.2 \times 10^{16}$ keys. At $10^{12}$ keys/sec: $7.2 \times 10^{16} / 10^{12} = 72000$ seconds ≈ 20 hours. This is why DES is considered broken.

  3. AES-256 uses how many rounds?

    Click for answer 14 rounds (plus initial AddRoundKey). AES-128: 10 rounds. AES-192: 12 rounds. More rounds for longer keys.

  4. Why does AES omit MixColumns in the last round?

    Click for answer It makes encryption and decryption symmetric (with different round keys in reverse order). Without this, decryption would need an additional step. It doesn't affect security since there's no next round to diffuse into.

  5. In CBC mode, what happens if the IV is predictable?

    Click for answer If an attacker can predict the IV, they can potentially mount chosen-plaintext attacks. The BEAST attack on TLS 1.0 exploited predictable CBC IVs. IV must be unpredictable (random).


Summary

Key takeaways:


Pitfalls



Next Steps

Next up: 28-04-asymmetric-encryption.md — public-key cryptography and the RSA revolution.