CSS411 Cryptography

AES MixColumns

The MixColumns step worked by hand. GF(2^8) multiplication by 02 and 03, the matrix equations, a full worked column and the inverse matrix.

10 min read

MixColumns overviewSearch on YouTube

PurposeSearch on YouTube

SubBytes changes each byte on its own. MixColumns makes each output byte of a column depend on all four input bytes of that column. This gives diffusion.

MixColumns works on one column of the 4 x 4 state at a time. Each full round applies it to all four columns.

ShiftRows moves bytes into other columns. MixColumns then mixes the bytes in each column. After two rounds, a change in one byte affects all 16 bytes of the state.

The matrixSearch on YouTube

Each column [s0,s1,s2,s3][s_0, s_1, s_2, s_3] is multiplied by a fixed matrix over GF(28)GF(2^8):

(s0′s1′s2′s3′)=(02030101010203010101020303010102)(s0s1s2s3)\begin{pmatrix} s_0' \\ s_1' \\ s_2' \\ s_3' \end{pmatrix} = \begin{pmatrix} 02 & 03 & 01 & 01 \\ 01 & 02 & 03 & 01 \\ 01 & 01 & 02 & 03 \\ 03 & 01 & 01 & 02 \end{pmatrix} \begin{pmatrix} s_0 \\ s_1 \\ s_2 \\ s_3 \end{pmatrix}

Each row gives one equation:

s0′=02⋅s0⊕03⋅s1⊕01⋅s2⊕01⋅s3s1′=01⋅s0⊕02⋅s1⊕03⋅s2⊕01⋅s3s2′=01⋅s0⊕01⋅s1⊕02⋅s2⊕03⋅s3s3′=03⋅s0⊕01⋅s1⊕01⋅s2⊕02⋅s3\begin{aligned} s_0' &= 02\cdot s_0 \oplus 03\cdot s_1 \oplus 01\cdot s_2 \oplus 01\cdot s_3 \\ s_1' &= 01\cdot s_0 \oplus 02\cdot s_1 \oplus 03\cdot s_2 \oplus 01\cdot s_3 \\ s_2' &= 01\cdot s_0 \oplus 01\cdot s_1 \oplus 02\cdot s_2 \oplus 03\cdot s_3 \\ s_3' &= 03\cdot s_0 \oplus 01\cdot s_1 \oplus 01\cdot s_2 \oplus 02\cdot s_3 \end{aligned}

The "⊕\oplus" is XOR. A multiplication by 01 does not change the byte.

Matrix rows: 02 03 01 01, then move each row one place to the right. The value 02 is always on the diagonal, and 03 is always to its right.

GF(2^8) arithmeticSearch on YouTube

The fieldSearch on YouTube

All MixColumns arithmetic is in GF(28)GF(2^8) with the AES irreducible polynomial:

m(x)=x8+x4+x3+x+1=(1 0001 1011)={11B}m(x) = x^8 + x^4 + x^3 + x + 1 = (1\,0001\,1011) = \{11B\}
  • Each byte is a polynomial of degree 7 or less. Each bit is one coefficient.
  • Addition is XOR.
  • Multiplication is done modulo m(x)m(x).

Multiply by 02Search on YouTube

The byte 02 is 0000 0010=x0000\,0010 = x. To multiply by 02:

  1. Shift the byte left by one bit.
  2. If the bit that shifts out is 0, the result is complete.
  3. If the bit that shifts out is 1, XOR the result with {11B}\{11B\}.

This rule is called xtime.

Handwritten notes: {02}⋅{87}\{02\} \cdot \{87\}.

  • {87}=1000 0111=x7+x2+x+1\{87\} = 1000\,0111 = x^7 + x^2 + x + 1.
  • x⋅(x7+x2+x+1)=x8+x3+x2+x=1 0000 1110x \cdot (x^7 + x^2 + x + 1) = x^8 + x^3 + x^2 + x = 1\,0000\,1110.
  • The x8x^8 term is present, so reduce modulo m(x)m(x):
(1 0000 1110)⊕(1 0001 1011)=0001 0101=x4+x2+1={15}(1\,0000\,1110) \oplus (1\,0001\,1011) = 0001\,0101 = x^4 + x^2 + 1 = \{15\}

Multiply by 03Search on YouTube

The byte 03 is 0000 0011=x+10000\,0011 = x + 1. Thus 03⋅b=(02⋅b)⊕b03 \cdot b = (02 \cdot b) \oplus b.

Handwritten notes: {03}⋅{6E}\{03\} \cdot \{6E\}.

  • {6E}=0110 1110=x6+x5+x3+x2+x\{6E\} = 0110\,1110 = x^6 + x^5 + x^3 + x^2 + x.
  • (x+1)(x6+x5+x3+x2+x)=x7+x6+x4+x3+x2+x6+x5+x3+x2+x(x + 1)(x^6 + x^5 + x^3 + x^2 + x) = x^7 + x^6 + x^4 + x^3 + x^2 + x^6 + x^5 + x^3 + x^2 + x.
  • Equal terms cancel in pairs: x7+x5+x4+x=1011 0010={B2}x^7 + x^5 + x^4 + x = 1011\,0010 = \{B2\}.

Byte method: 02⋅{6E}={DC}02 \cdot \{6E\} = \{DC\} (no overflow). Then {DC}⊕{6E}={B2}\{DC\} \oplus \{6E\} = \{B2\}.

02⋅b={b≪1top bit of b=0(b≪1)⊕{1B}top bit of b=103⋅b=(02⋅b)⊕b02 \cdot b = \begin{cases} b \ll 1 & \text{top bit of } b = 0 \\ (b \ll 1) \oplus \{1B\} & \text{top bit of } b = 1 \end{cases} \qquad 03 \cdot b = (02 \cdot b) \oplus b

{1B}\{1B\} is the low 8 bits of {11B}\{11B\}.

Worked columnSearch on YouTube

Input stateSearch on YouTube

The handwritten notes use the state after ShiftRows from the AES deck:

(87F24D976E4C90EC46E74AC3A68CD895)\begin{pmatrix} 87 & F2 & 4D & 97 \\ 6E & 4C & 90 & EC \\ 46 & E7 & 4A & C3 \\ A6 & 8C & D8 & 95 \end{pmatrix}

The first column is {87},{6E},{46},{A6}\{87\}, \{6E\}, \{46\}, \{A6\}.

First byteSearch on YouTube

s0′=(02⋅{87})⊕(03⋅{6E})⊕(01⋅{46})⊕(01⋅{A6})s_0' = (02 \cdot \{87\}) \oplus (03 \cdot \{6E\}) \oplus (01 \cdot \{46\}) \oplus (01 \cdot \{A6\})
TermBinary
02⋅{87}02 \cdot \{87\}0001 0101
03⋅{6E}03 \cdot \{6E\}1011 0010
01⋅{46}01 \cdot \{46\}0100 0110
01⋅{A6}01 \cdot \{A6\}1010 0110
XOR of all four0100 0111 ={47}= \{47\}

Other bytesSearch on YouTube

Use the same method for the other three rows:

ByteTermsResult
s1′s_1'{87}⊕{DC}⊕{CA}⊕{A6}\{87\} \oplus \{DC\} \oplus \{CA\} \oplus \{A6\}{37}\{37\}
s2′s_2'{87}⊕{6E}⊕{8C}⊕{F1}\{87\} \oplus \{6E\} \oplus \{8C\} \oplus \{F1\}{94}\{94\}
s3′s_3'{92}⊕{6E}⊕{46}⊕{57}\{92\} \oplus \{6E\} \oplus \{46\} \oplus \{57\}{ED}\{ED\}

The intermediate products are:

  • 02⋅{6E}={DC}02 \cdot \{6E\} = \{DC\} and 03⋅{46}={8C}⊕{46}={CA}03 \cdot \{46\} = \{8C\} \oplus \{46\} = \{CA\}.
  • 02⋅{46}={8C}02 \cdot \{46\} = \{8C\} and 03⋅{A6}={57}⊕{A6}={F1}03 \cdot \{A6\} = \{57\} \oplus \{A6\} = \{F1\}.
  • 03⋅{87}={15}⊕{87}={92}03 \cdot \{87\} = \{15\} \oplus \{87\} = \{92\} and 02⋅{A6}={57}02 \cdot \{A6\} = \{57\}.

The full column changes from {87},{6E},{46},{A6}\{87\}, \{6E\}, \{46\}, \{A6\} to {47},{37},{94},{ED}\{47\}, \{37\}, \{94\}, \{ED\}. This is the first column of the MixColumns output in the AES deck.

The handwritten notes write "GF(2^3)" next to the reduction. The correct field is GF(28)GF(2^8). Also, {02}⋅{A6}\{02\} \cdot \{A6\} has an overflow bit: {A6}≪1=1 0100 1100\{A6\} \ll 1 = 1\,0100\,1100, and the XOR with {11B}\{11B\} gives {57}\{57\}. Do not forget this reduction.

Other viewsSearch on YouTube

Polynomial viewSearch on YouTube

The AES deck gives an alternative view of MixColumns. Each column is a 4-term polynomial with coefficients in GF(28)GF(2^8):

a(x)=a3x3+a2x2+a1x+a0a(x) = a_3x^3 + a_2x^2 + a_1x + a_0

This polynomial is multiplied by a fixed polynomial modulo x4+1x^4 + 1:

c(x)={03}x3+{01}x2+{01}x+{02}c(x) = \{03\}x^3 + \{01\}x^2 + \{01\}x + \{02\}

The result is the same as the matrix multiplication.

Inverse MixColumnsSearch on YouTube

Decryption uses the inverse matrix:

(0E0B0D09090E0B0D0D090E0B0B0D090E)\begin{pmatrix} 0E & 0B & 0D & 09 \\ 09 & 0E & 0B & 0D \\ 0D & 09 & 0E & 0B \\ 0B & 0D & 09 & 0E \end{pmatrix}

The coefficients are larger. Each multiplication needs more xtime and XOR steps. Thus decryption is a little harder.

Coefficient choiceSearch on YouTube

The AES deck says that the coefficients come from a linear code with maximal distance between codewords. The forward coefficients 01, 02 and 03 are small, so encryption is fast. A multiplication by 02 needs one xtime. A multiplication by 03 needs one xtime and one XOR.

Quick self-testSearch on YouTube

What does MixColumns do, and why does AES need it?

It multiplies each state column by a fixed matrix over GF(28)GF(2^8). Each output byte then depends on all four input bytes of the column. This gives diffusion.

Write the first row of the MixColumns matrix and the s0′s_0' equation.

The row is 02 03 01 01. Thus s0′=02⋅s0⊕03⋅s1⊕s2⊕s3s_0' = 02\cdot s_0 \oplus 03\cdot s_1 \oplus s_2 \oplus s_3.

What is xtime?

It is multiplication by 02. Shift the byte left by one bit. If the bit that shifts out is 1, XOR the result with {1B}\{1B\}.

Calculate {02}⋅{87}\{02\} \cdot \{87\}.

The shift gives 1 0000 11101\,0000\,1110. XOR with 1 0001 10111\,0001\,1011 gives 0001 0101={15}0001\,0101 = \{15\}.

Calculate {03}⋅{6E}\{03\} \cdot \{6E\}.

02⋅{6E}={DC}02 \cdot \{6E\} = \{DC\}. Then {DC}⊕{6E}={B2}\{DC\} \oplus \{6E\} = \{B2\}.

Calculate s0′s_0' for the column 87, 6E, 46, A6.

{15}⊕{B2}⊕{46}⊕{A6}={47}\{15\} \oplus \{B2\} \oplus \{46\} \oplus \{A6\} = \{47\}.

Give the full output column for the input 87, 6E, 46, A6.

{47},{37},{94},{ED}\{47\}, \{37\}, \{94\}, \{ED\}.

Which polynomial and modulus give the polynomial view of MixColumns?

Multiply the column polynomial by c(x)={03}x3+{01}x2+{01}x+{02}c(x) = \{03\}x^3 + \{01\}x^2 + \{01\}x + \{02\}, modulo x4+1x^4 + 1.

Give the inverse matrix coefficients. Why is decryption harder?

The coefficients are {0E}\{0E\}, {0B}\{0B\}, {0D}\{0D\} and {09}\{09\}. They are larger, so each multiplication needs more xtime and XOR steps.

  • MixColumns multiplies each column by the matrix with rows 02 03 01 01 (rotated). It gives diffusion.
  • The arithmetic is in GF(28)GF(2^8) modulo {11B}\{11B\}. Addition is XOR.
  • Multiply by 02: shift left, and XOR with {1B}\{1B\} if the top bit was 1. Multiply by 03: (02⋅b)⊕b(02 \cdot b) \oplus b.
  • Worked example: {02}⋅{87}={15}\{02\} \cdot \{87\} = \{15\} and {03}⋅{6E}={B2}\{03\} \cdot \{6E\} = \{B2\}.
  • The column 87, 6E, 46, A6 becomes 47, 37, 94, ED.
  • Polynomial view: multiply by c(x)c(x) modulo x4+1x^4 + 1. Decryption uses the inverse matrix with 0E, 0B, 0D, 09.