- 8

- 0

## Main Question or Discussion Point

I'm trying to implement AES as practice for my C++ skills, but I've come across a confusing problem that I think belongs here rather than in programming.

Rijndael's finite field is GF(2

There is a step in the algorithm that takes a polynomial a(x)=a

and reduces it modulo x

This operation is equivalent, if a is a constant polynomial, according to the text, to the matrix multiplication:

[tex]\left( \begin{array}{c}

d_0 \\

d_1 \\

d_2 \\

d_3 \end{array} \right)=

\left( \begin{array}{cccc}

a_0 & a_3 & a_2 & a_1 \\

a_1 & a_0 & a_3 & a_2 \\

a_2 & a_1 & a_0 & a_3 \\

a_3 & a_2 & a_1 & a_0 \end{array} \right)

\left( \begin{array}{c}

b_0 \\

b_1 \\

b_2 \\

b_3 \end{array} \right)[/tex]

it gives the constant polynomial a(x) as [tex]a(x)=\{03\}x^3+\{01\}x^2+\{01\}x+\{02\}[/tex], and the inverse polynomial [tex]a^{-1}(x)=\{0b\}x^3+\{0d\}x^2+\{09\}x+\{0e\}[/tex] (all numbers in curly braces are hexadecimal).

Now, being as I'm using a computer to do this, and proper polynomial handling is hard to do, I'm using the matrix multiplication to do the calculation. Now, if I'm thinking about this properly, then the matrix representations of [tex]a(x)[/tex] and [tex]a^{-1}(x)[/tex] should have a product that is a unit matrix. But, if my calculations (done by my program) are correct, then:

[tex]

\left( \begin{array}{cccc}

\{02\} & \{03\} & \{01\} & \{01\} \\

\{01\} & \{02\} & \{03\} & \{01\} \\

\{01\} & \{01\} & \{02\} & \{03\} \\

\{03\} & \{01\} & \{01\} & \{02\} \end{array} \right)

\left( \begin{array}{cccc}

\{0e\} & \{0b\} & \{0d\} & \{09\} \\

\{09\} & \{0e\} & \{0b\} & \{0d\} \\

\{0d\} & \{09\} & \{0e\} & \{0b\} \\

\{0b\} & \{0d\} & \{09\} & \{0e\} \end{array} \right)=

\left( \begin{array}{cccc}

\{01\} & \{00\} & \{e5\} & \{00\} \\

\{00\} & \{01\} & \{00\} & \{e5\} \\

\{e5\} & \{00\} & \{01\} & \{00\} \\

\{00\} & \{e5\} & \{00\} & \{01\} \end{array} \right)

[/tex]

Which is almost a unit matrix, but not quite. And, when I use these polynomials to calculate the function, and then the inverse, I get a different polynomial to my input. I checked my matrix multiplication algorithm, it seems to be working fine.

Two other matrices that should have a unit matrix product (for another step in the algorithm) do. I'm definitely doing finite field arithmetic. I'm using a logarithm table for my multiplication, base three, which I know for a fact is a generator. I can't find anything wrong with the procedure, so I'm asking you guys if you could please tell me why it doesn't work.

Rijndael's finite field is GF(2

^{8}), with reducing polynomial x^{8}+x^{4}+x^{3}+x+1There is a step in the algorithm that takes a polynomial a(x)=a

_{3}x^{3}+ a_{2}x^{2}+a_{1}x+a_{0}with coefficients in GF(2^{8}), and multiplies it by a polynomial b(x)=b_{3}x^{3}+ b_{2}x^{2}+b_{1}x+b_{0}and reduces it modulo x

^{4}+1, to get d(x)=d_{3}x^{3}+ d_{2}x^{2}+d_{1}x+d_{0}This operation is equivalent, if a is a constant polynomial, according to the text, to the matrix multiplication:

[tex]\left( \begin{array}{c}

d_0 \\

d_1 \\

d_2 \\

d_3 \end{array} \right)=

\left( \begin{array}{cccc}

a_0 & a_3 & a_2 & a_1 \\

a_1 & a_0 & a_3 & a_2 \\

a_2 & a_1 & a_0 & a_3 \\

a_3 & a_2 & a_1 & a_0 \end{array} \right)

\left( \begin{array}{c}

b_0 \\

b_1 \\

b_2 \\

b_3 \end{array} \right)[/tex]

it gives the constant polynomial a(x) as [tex]a(x)=\{03\}x^3+\{01\}x^2+\{01\}x+\{02\}[/tex], and the inverse polynomial [tex]a^{-1}(x)=\{0b\}x^3+\{0d\}x^2+\{09\}x+\{0e\}[/tex] (all numbers in curly braces are hexadecimal).

Now, being as I'm using a computer to do this, and proper polynomial handling is hard to do, I'm using the matrix multiplication to do the calculation. Now, if I'm thinking about this properly, then the matrix representations of [tex]a(x)[/tex] and [tex]a^{-1}(x)[/tex] should have a product that is a unit matrix. But, if my calculations (done by my program) are correct, then:

[tex]

\left( \begin{array}{cccc}

\{02\} & \{03\} & \{01\} & \{01\} \\

\{01\} & \{02\} & \{03\} & \{01\} \\

\{01\} & \{01\} & \{02\} & \{03\} \\

\{03\} & \{01\} & \{01\} & \{02\} \end{array} \right)

\left( \begin{array}{cccc}

\{0e\} & \{0b\} & \{0d\} & \{09\} \\

\{09\} & \{0e\} & \{0b\} & \{0d\} \\

\{0d\} & \{09\} & \{0e\} & \{0b\} \\

\{0b\} & \{0d\} & \{09\} & \{0e\} \end{array} \right)=

\left( \begin{array}{cccc}

\{01\} & \{00\} & \{e5\} & \{00\} \\

\{00\} & \{01\} & \{00\} & \{e5\} \\

\{e5\} & \{00\} & \{01\} & \{00\} \\

\{00\} & \{e5\} & \{00\} & \{01\} \end{array} \right)

[/tex]

Which is almost a unit matrix, but not quite. And, when I use these polynomials to calculate the function, and then the inverse, I get a different polynomial to my input. I checked my matrix multiplication algorithm, it seems to be working fine.

Two other matrices that should have a unit matrix product (for another step in the algorithm) do. I'm definitely doing finite field arithmetic. I'm using a logarithm table for my multiplication, base three, which I know for a fact is a generator. I can't find anything wrong with the procedure, so I'm asking you guys if you could please tell me why it doesn't work.