Path: blob/main/foundations/03-galois-fields-aes/sage/03e-aes-mixcolumns-as-field-ops.ipynb
483 views
AES MixColumns as Field Operations
Module 03e | Galois Fields and AES
Matrix multiplication over GF(256), the diffusion layer of AES.
Question: SubBytes provides confusion (nonlinearity). But confusion alone isn't enough, an attacker could analyze each byte independently. AES needs diffusion: changing one input byte should affect many output bytes. How?
MixColumns achieves this by treating each 4-byte column as a vector over GF(256) and multiplying by a carefully chosen matrix. One changed input byte cascades through the entire column.
Objectives
By the end of this notebook you will be able to:
Describe the AES state as a 4×4 matrix of GF(256) elements
Perform the MixColumns matrix-vector multiplication over GF(256)
Verify the MDS (Maximum Distance Separable) property of the MixColumns matrix
Implement InvMixColumns using the inverse matrix
Explain why MixColumns provides optimal diffusion
Bridge from 03d
In 03d you built the S-box, AES's nonlinear byte substitution. Now we add the linear mixing step. Together, SubBytes (nonlinear, per-byte) and MixColumns (linear, per-column) create the confusion-diffusion architecture that Shannon identified as essential for strong ciphers.
MixColumns operates on 4-byte columns using matrix multiplication over GF(256), the same field you've been working with since 03c.
Setup
The AES State Matrix
AES processes 16 bytes (128 bits) at a time, arranged as a 4×4 matrix of GF(256) elements. Bytes fill column-by-column:
MixColumns operates on each column independently.
The MixColumns Matrix
Each column is left-multiplied by the fixed matrix:
where the entries are GF(256) elements. This is a circulant matrix, each row is a cyclic shift of the first.
MixColumns in Action
Checkpoint: Before running the next cell, compute the first output byte by hand. Given column , the first output byte is:
The Diffusion Property
Why this specific matrix? Because it is MDS (Maximum Distance Separable). This means: if you change input bytes, at least output bytes change. The minimum number of active bytes (input + output) is always .
Common mistake: "MixColumns is just matrix multiplication, so it's linear and therefore weak." MixColumns IS linear over GF(256), that's by design. The nonlinearity comes from SubBytes. AES's security comes from alternating nonlinear (SubBytes) and linear (MixColumns) layers. Neither alone is secure; together they create an avalanche effect.
InvMixColumns
Checkpoint: The inverse MixColumns matrix uses the constants 0x0E, 0x0B, 0x0D, 0x09. These are larger because has more complex GF(256) entries. This is why AES decryption is slightly slower than encryption, InvMixColumns requires more multiplications.
MixColumns as Polynomial Multiplication
There's an elegant alternative view: MixColumns is polynomial multiplication modulo in the ring GF(256).
Exercises
Exercise 1 (Worked)
Apply MixColumns to the column , showing the GF(256) multiplications for each output byte.
Exercise 2 (Guided)
Verify the MDS property: show that every square submatrix of (of any size 1×1, 2×2, 3×3, 4×4) has a nonzero determinant over GF(256).
Exercise 3 (Independent)
Apply MixColumns to the column . What do you get? (Hint: this extracts a column of , which one?)
Apply MixColumns twice to any column. Is also MDS? Compute over GF(256) and check.
The polynomial must be invertible modulo for InvMixColumns to exist. Verify this and find the inverse polynomial.
Summary
| Concept | Key idea |
|---|---|
| MixColumns | Multiplies each 4-byte column by a fixed matrix over GF(256) |
| Efficient constants | The matrix uses only 0x01, 0x02, and 0x03, so multiplication needs just XOR and xtime |
| MDS property | Changing input bytes forces at least output bytes to change, giving optimal diffusion |
| InvMixColumns | Uses the inverse matrix with constants 0x09, 0x0B, 0x0D, 0x0E, making decryption slightly more expensive |
| Linear by design | MixColumns is linear over GF(256). The nonlinearity comes from SubBytes, and the combination of both provides security |
| Polynomial view | Equivalently, MixColumns is multiplication by a fixed polynomial mod in GF(256) |
Crypto foreshadowing: In notebook 03f, we assemble all four AES round operations, SubBytes, ShiftRows, MixColumns, and AddRoundKey, into a complete AES round. You'll see how confusion (SubBytes) and diffusion (ShiftRows + MixColumns) combine with key mixing (AddRoundKey) to create a cipher that has resisted attack for over 25 years.
Next: Full AES Round, putting SubBytes, ShiftRows, MixColumns, and AddRoundKey together.