The MixColumns operation performed by the Rijndael cipher or Advanced Encryption Standard is, along with the ShiftRows step, its primary source of diffusion. Each column of bytes is treated as a four-term polynomial b(x)=b3x3+b2x2+b1x+b0, each byte representing an element in the Galois field GF(28). The coefficients are elements within the prime sub-field GF(2). Each column is multiplied with the fixed polynomial a(x)=3x3+x2+x+2 modulo x4+1; the inverse function is a−1(x)=11x3+13x2+9x+14.
Demonstration The MixColumns operation will use the fixed polynomial a(x)=3x3+x2+x+2, which will be expressed as a(x)=a3x3+a2x2+a1x+a0. We note that in a(x), there are the corresponding constants [3112]. From there, there are multiple ways to execute the function. Here, the operation can be expressed in terms of polynomial multiplication and matrix multiplication. Regardless, the function always uses the exclusive or ⊕.
Polynomial multiplication For the fixed polynomial a(x) and the column of bytes b(x), we can multiply these two together to result in the following:
a(x)∙b(x)=c(x)=(a3x3+a2x2+a1x+a0)∙(b3x3+b2x2+b1x+b0)=c6x6+c5x5+c4x4+c3x3+c2x2+c1x+c0 We see that c(x) is a seven-term polynomial, where its constants c0 to c6 should satisfy the following:
c0=a0∙b0c1=a1∙b0⊕a0∙b1c2=a2∙b0⊕a1∙b1⊕a0∙b2c3=a3∙b0⊕a2∙b1⊕a1∙b2⊕a0∙b3c4=a3∙b1⊕a2∙b2⊕a1∙b3c5=a3∙b2⊕a2∙b3c6=a3∙b3
Modular reduction As AES operates on four-byte "words", and that any overflow can break the algorithm, c(x) must be reduced to a four-byte word, which is done by performing a modulo multiplication with x4+1. Another method to prevent overflow is its treatment of each byte as an element in the Galois field GF(28). All arithmetic functions in this finite field - addition, subtraction, multiplication, division - always result in an 8-bit number. If we do some basic polynomial modular operations we can see that:
x6mod(x4+1)=−x2=x2 over GF(28)x5mod(x4+1)=−x=x over GF(28)x4mod(x4+1)=−1=1 over GF(28) In general, we can say that for any i≤6, then ximod(x4+1)=ximod4. From here, we calculate the polynomial multiplication modulo of a(x) and b(x) to result in the output:
d(x)=a(x)⊗b(x)=c(x)mod(x4+1)=(c6x6+c5x5+c4x4+c3x3+c2x2+c1x+c0)mod(x4+1)=c6x6mod4+c5x5mod4+c4x4mod4+c3x3mod4+c2x2mod4+c1x1mod4+c0x0mod4=c6x2+c5x+c4+c3x3+c2x2+c1x+c0=c3x3+(c2⊕c6)x2+(c1⊕c5)x+c0⊕c4=d3x3+d2x2+d1x+d0 where
d0=c0⊕c4 d1=c1⊕c5 d2=c2⊕c6 d3=c3
Matrix representation Here, let dn be the outputting bytes of the operation. The coefficient d3, d2, d1 and d0 can be expressed as follows:
d0=a0∙b0⊕a3∙b1⊕a2∙b2⊕a1∙b3 d1=a1∙b0⊕a0∙b1⊕a3∙b2⊕a2∙b3 d2=a2∙b0⊕a1∙b1⊕a0∙b2⊕a3∙b3 d3=a3∙b0⊕a2∙b1⊕a1∙b2⊕a0∙b3 And when we replace the coefficients of a(x) with the constants [3112] used in the cipher, we obtain the following:
d0=2∙b0⊕3∙b1⊕1∙b2⊕1∙b3 d1=1∙b0⊕2∙b1⊕3∙b2⊕1∙b3 d2=1∙b0⊕1∙b1⊕2∙b2⊕3∙b3 d3=3∙b0⊕1∙b1⊕1∙b2⊕2∙b3 This demonstrates that the operation itself is similar to a Hill cipher. It can be performed by multiplying a coordinate vector of four numbers in Rijndael's Galois field by the following circulant MDS matrix:
[d0d1d2d3]=[2311123111233112][b0b1b2b3]
Implementation example This can be simplified somewhat in actual implementation by replacing the multiply by 2 with a single shift and conditional exclusive or, and replacing a multiply by 3 with a multiply by 2 combined with an exclusive or. A C example of such an implementation follows:
A C# example
Test vectors for MixColumn()
InverseMixColumns
The MixColumns operation has the following inverse (numbers are decimal):
[b0b1b2b3]=[1411139914111313914111113914][d0d1d2d3] Or:
b0=14∙d0⊕11∙d1⊕13∙d2⊕9∙d3b1=9∙d0⊕14∙d1⊕11∙d2⊕13∙d3b2=13∙d0⊕9∙d1⊕14∙d2⊕11∙d3b3=11∙d0⊕13∙d1⊕9∙d2⊕14∙d3
Galois Multiplication lookup tables Commonly, rather than implementing Galois multiplication, Rijndael implementations simply use pre-calculated lookup tables to perform the byte multiplication by 2, 3, 9, 11, 13, and 14. For instance, in C# these tables can be stored in Byte[256] arrays. In order to compute
p * 3 The result is obtained this way:
result = table_3[(int)p] Some of the most common instances of these lookup tables are as follows: Multiply by 2:
0x00,0x02,0x04,0x06,0x08,0x0a,0x0c,0x0e,0x10,0x12,0x14,0x16,0x18,0x1a,0x1c,0x1e, 0x20,0x22,0x24,0x26,0x28,0x2a,0x2c,0x2e,0x30,0x32,0x34,0x36,0x38,0x3a,0x3c,0x3e, 0x40,0x42,0x44,0x46,0x48,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c,0x5e, 0x60,0x62,0x64,0x66,0x68,0x6a,0x6c,0x6e,0x70,0x72,0x74,0x76,0x78,0x7a,0x7c,0x7e, 0x80,0x82,0x84,0x86,0x88,0x8a,0x8c,0x8e,0x90,0x92,0x94,0x96,0x98,0x9a,0x9c,0x9e, 0xa0,0xa2,0xa4,0xa6,0xa8,0xaa,0xac,0xae,0xb0,0xb2,0xb4,0xb6,0xb8,0xba,0xbc,0xbe, 0xc0,0xc2,0xc4,0xc6,0xc8,0xca,0xcc,0xce,0xd0,0xd2,0xd4,0xd6,0xd8,0xda,0xdc,0xde, 0xe0,0xe2,0xe4,0xe6,0xe8,0xea,0xec,0xee,0xf0,0xf2,0xf4,0xf6,0xf8,0xfa,0xfc,0xfe, 0x1b,0x19,0x1f,0x1d,0x13,0x11,0x17,0x15,0x0b,0x09,0x0f,0x0d,0x03,0x01,0x07,0x05, 0x3b,0x39,0x3f,0x3d,0x33,0x31,0x37,0x35,0x2b,0x29,0x2f,0x2d,0x23,0x21,0x27,0x25, 0x5b,0x59,0x5f,0x5d,0x53,0x51,0x57,0x55,0x4b,0x49,0x4f,0x4d,0x43,0x41,0x47,0x45, 0x7b,0x79,0x7f,0x7d,0x73,0x71,0x77,0x75,0x6b,0x69,0x6f,0x6d,0x63,0x61,0x67,0x65, 0x9b,0x99,0x9f,0x9d,0x93,0x91,0x97,0x95,0x8b,0x89,0x8f,0x8d,0x83,0x81,0x87,0x85, 0xbb,0xb9,0xbf,0xbd,0xb3,0xb1,0xb7,0xb5,0xab,0xa9,0xaf,0xad,0xa3,0xa1,0xa7,0xa5, 0xdb,0xd9,0xdf,0xdd,0xd3,0xd1,0xd7,0xd5,0xcb,0xc9,0xcf,0xcd,0xc3,0xc1,0xc7,0xc5, 0xfb,0xf9,0xff,0xfd,0xf3,0xf1,0xf7,0xf5,0xeb,0xe9,0xef,0xed,0xe3,0xe1,0xe7,0xe5 Multiply by 3:
… excerpt ends here. Continue reading the full article.