I not understand how why the EK is having an array size 44, but each round the function is only modify the data of rkexp[0], rkexp[1], rkexp[2], and rkexp[3]. There are total 10 round and i am showing two of the round.
I also not understand that how the rkexp is added by 4 each round, how that array is added by 4 and what has been change?
Below is the code in C language
int main(){
unsigned char k[16] = "1234567890123456";
unsigned int EK[44];
AESKeySteup(k, EK);
}
void AESKeySteup(const unsigned char* rk, unsigned int* rkexp)
{
// round key 0
memcpy(rkexp, rk, 16);
print('K', rkexp, 44);
// round key 1
rkexp += 4;
print('K', rkexp, 44);
rkexp[0] = ((unsigned int *)rk)[0] ^
(TE4[((rkexp-4)[3] >> 8) & 0xff] & 0x000000ff) ^
(TE4[((rkexp-4)[3] >> 16) & 0xff] & 0x0000ff00) ^
(TE4[(rkexp-4)[3] >> 24] & 0x00ff0000) ^
(TE4[(rkexp-4)[3] & 0xff] & 0xff000000) ^
rcon[0];
print('K', rkexp, 44);
rkexp[1] = rkexp[0] ^ (rkexp-4)[1];
rkexp[2] = rkexp[1] ^ (rkexp-4)[2];
rkexp[3] = rkexp[2] ^ (rkexp-4)[3];
// round key 2
rkexp += 4;
rkexp[0] = (rkexp-4)[0] ^
(TE4[((rkexp-4)[3] >> 8) & 0xff] & 0x000000ff) ^
(TE4[((rkexp-4)[3] >> 16) & 0xff] & 0x0000ff00) ^
(TE4[(rkexp-4)[3] >> 24] & 0x00ff0000) ^
(TE4[(rkexp-4)[3] & 0xff] & 0xff000000) ^
rcon[1];
rkexp[1] = rkexp[0] ^ (rkexp-4)[1];
rkexp[2] = rkexp[1] ^ (rkexp-4)[2];
rkexp[3] = rkexp[2] ^ (rkexp-4)[3];
...
and so on
}
User contributions licensed under CC BY-SA 3.0