I am attempting to calculate the round constants used in AES. Using the formula found on Wikipedia's Rijndael Key Schedule page results in answers that the same page says are correct, but the primary source for my current project gives a different formula, so I feel like I might be missing something.
The formula given is: $r(i) = x^{(i-4)/4} mod (x^8+x^4+x^3+x+1)$ where $i$ is the current round. It seems to me that this formula and the one listed on the Wikipedia page for Rcon, which I'm assuming is short for "round constant," have the same purpose, but one uses values four times as high. For reference, the Wikipedia function is $Rcon(i) = b^{i-1}$ in $GF(2^8)$.
The project requires that I calculate the value of r for all i divisible by 4 from 4 to 40. My solutions for 4 to 32 match the values given for Rcon(1) to Rcon(8) (01 to 80) in the linked article.
My understanding is that the modulus operator is here applied in a manner equivalent to an XOR operator, which seems to hold if the above is correct, as it results in r(36) = 0x1B, which is given as the value of Rcon(9) in the linked article.
What is the use of the two functions given in paragraph 2, and why would two separate functions be necessary in this application?
GF(2) polynomials represent rings of numbers. As an example, the mapping of coefficients to numbers for $\mathtt{x^2+x+1}$ is given by the following table:
\begin{array} {|r|r|r|} dec & bin & polynomial\\ \hline 0 & 000 & 0 \\ 1 & 001 & 1 \\ 2 & 010 & x \\ 3 & 011 & x+1 \\ 4 & 100 & x^2 \\ 5 & 101 & x^2+1\\ 6 & 110 & x^2+x\\ 7 & 111 & x^2+x+1 \\ \end{array}
AES uses the same irreducible polynomial for everything, which is $\mathtt{x^8+x^4+x^3+x+1}$. This polynomial results in 9 bits, and is 0x11B in hexadecimal, or 100011011 in binary. You will notice that the 9 bits are one bit more than you have in an 8-bit byte, and this allows the modulus to be the XOR of 0x1B, instead of 0x11B. The prefix of the RCON value is actually just 0x01 starting at round 1, which is just shifted left.
To create the AES round constants in C, see the following program that I hastily made:
You will notice in the program that you check the value of the high bit of the byte x before the shift via
(x & 0x80), and then calculate the XOR if true. This program results in the following output:Where the first column is the round count, the second column is the XOR mask (ie: the modular division via subtraction because you can never get larger than the AES polynomial) and the final column is the AES round constant.