I’ve managed successfully to write my own AES implementation using a 128bit key. However I’m still dangled how to interpret the AddRoundKey function using 192bit and 256bit keys.
Some facts:
- Block is 128 bits (State)
- Rounds 128bit = 10, 192bit = 12, 256bit = 14
- Nk 128bit = 4 (equal to Block size), 192bit = 6, 256bit = 8 (units are words)
If Nk = 8 and i-4 is a multiple of Nk,
then SubWord() is applied to w[i-1]
prior to the XOR.
Does anyone know how 192bit and 256bit keys are applied? Any replies are appreciated.
I think you’ve got things slightly confused. From FIPS-197:
So the AddRoundKey() function xor’s the state with the appropriate word from the key schedule. Now again from FIPS-197:
This is actually fairly straightforward. The first
NKwords of the key schedule are the key. From then on, you create each word byxorwith the previous word unless this particular word is an exact multiple ofNk, in which case you apply the Subword function as described in FIPS-197 on the output of the rotated word xor’d by the round constant number for that particular round (i/Nk will be a whole number since i%Nk==0).Then, the bit you’re confused with: If
Nk > 6, so if we’re using 256-bit keys, andi mod Nk == 4i.e.(q*Nk)+4isifor some q, then you do your pre-xor Subword.Finally, whatever happens, prior, the contents of the previous word are still xor’d with temp.
The difference in the key schedule is with 256-bit keys.
If it helps, the way to know you’ve done this right is to use the test vectors available in FIPS-197 or the NIST AES package. There are test vectors for key schedules at all bit levels; give them a go, they’ll tell you when you’ve got things wrong.