Exemplo n.º 1
0
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]) );
	}
	
}
Exemplo n.º 2
0
Arquivo: aes.c Projeto: SamuelXu/clibs
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