void MixColumns(BYTE State[4][4]) { BYTE temp[4*4]; DWORD i,j; for(j=0;j<4;j++) //2 3 1 1 Page107 { //1 2 3 1 for(i=0;i<4;i++) //1 1 2 3 { //3 1 1 2 temp[4*i+j]=State[i][j]; } } for(j=0;j<4;j++) { State[0][j] = (BYTE) ( (DWORD)gfmultby02(temp[0+j]) ^ (DWORD)gfmultby03(temp[4*1+j]) ^ (DWORD)gfmultby01(temp[4*2+j]) ^ (DWORD)gfmultby01(temp[4*3+j]) ); State[1][j] = (BYTE) ( (DWORD)gfmultby01(temp[0+j]) ^ (DWORD)gfmultby02(temp[4*1+j]) ^ (DWORD)gfmultby03(temp[4*2+j]) ^ (DWORD)gfmultby01(temp[4*3+j]) ); State[2][j] = (BYTE) ( (DWORD)gfmultby01(temp[0+j]) ^ (DWORD)gfmultby01(temp[4*1+j]) ^ (DWORD)gfmultby02(temp[4*2+j]) ^ (DWORD)gfmultby03(temp[4*3+j]) ); State[3][j] = (BYTE) ( (DWORD)gfmultby03(temp[0+j]) ^ (DWORD)gfmultby01(temp[4*1+j]) ^ (DWORD)gfmultby01(temp[4*2+j]) ^ (DWORD)gfmultby02(temp[4*3+j]) ); } }
void MixColumns(ctx_aes* aes) { unsigned char temp[4*4]; int r,c; for (r = 0; r < 4; r++) // copy State into temp[] { for (c = 0; c < 4; c++) { temp[4*r+c] = aes->State[r][c]; } } for (c = 0; c < 4; c++) { aes->State[0][c] = (unsigned char) ( (int)gfmultby02(temp[0+c]) ^ (int)gfmultby03(temp[4*1+c]) ^ (int)gfmultby01(temp[4*2+c]) ^ (int)gfmultby01(temp[4*3+c]) ); aes->State[1][c] = (unsigned char) ( (int)gfmultby01(temp[0+c]) ^ (int)gfmultby02(temp[4*1+c]) ^ (int)gfmultby03(temp[4*2+c]) ^ (int)gfmultby01(temp[4*3+c]) ); aes->State[2][c] = (unsigned char) ( (int)gfmultby01(temp[0+c]) ^ (int)gfmultby01(temp[4*1+c]) ^ (int)gfmultby02(temp[4*2+c]) ^ (int)gfmultby03(temp[4*3+c]) ); aes->State[3][c] = (unsigned char) ( (int)gfmultby03(temp[0+c]) ^ (int)gfmultby01(temp[4*1+c]) ^ (int)gfmultby01(temp[4*2+c]) ^ (int)gfmultby02(temp[4*3+c]) ); } } // MixColumns
BYTE gfmultby0e(BYTE b) { return (BYTE)( (DWORD)gfmultby02(gfmultby02(gfmultby02(b))) ^ (DWORD)gfmultby02(gfmultby02(b)) ^(DWORD)gfmultby02(b) ); }
BYTE gfmultby03(BYTE b) { return (BYTE) ( (DWORD)gfmultby02(b) ^ (DWORD)b ); }
unsigned char gfmultby0e(unsigned char b) { return (unsigned char)( (int)gfmultby02(gfmultby02(gfmultby02(b))) ^ (int)gfmultby02(gfmultby02(b)) ^ (int)gfmultby02(b) ); }
unsigned char gfmultby03(unsigned char b) { return (unsigned char) ( (int)gfmultby02(b) ^ (int)b ); }
uint8_t gfmultby03(uint8_t b) { return (uint8_t) ( (int32_t)gfmultby02(b) ^ (int32_t)b ); }