Esempio n. 1
0
File: aes.c Progetto: svivekv/htable
void setrcon(byte rcon[10])
{
  int i;
  byte x=1;

  for(i=0;i<10;i++)
  {
    rcon[i]=x;
    x=multx(x);
  }
}
Esempio n. 2
0
File: aes.c Progetto: svivekv/htable
// slow multiplication in GF(2^8)
byte mult(byte x,byte y)
{
  int i;
  byte z=0;
  byte a=128;
  for(i=7;i>=0;i--)
  {
    z=multx(z);
    if((y & a)!=0) z^=x;
    a=a >> 1;
  }
  return z;
}
Esempio n. 3
0
File: aes.c Progetto: svivekv/htable
void mixcolumns(byte *state)
{
  byte ns[16];
  int i,j;
  for(j=0;j<4;j++)
  {
    ns[j*4]=multx(state[j*4]) ^ multx(state[j*4+1]) ^ state[j*4+1] ^ state[j*4+2] ^ state[j*4+3];
    ns[j*4+1]=state[j*4] ^ multx(state[j*4+1]) ^ multx(state[j*4+2]) ^ state[j*4+2] ^ state[j*4+3];
    ns[j*4+2]=state[j*4] ^ state[j*4+1] ^ multx(state[j*4+2]) ^ multx(state[j*4+3]) ^ state[j*4+3];
    ns[j*4+3]=multx(state[j*4]) ^ state[j*4] ^ state[j*4+1] ^ state[j*4+2] ^ multx(state[j*4+3]) ;
  }
  for(j=0;j<4;j++)
    for(i=0;i<4;i++)
      state[j*4+i]=ns[j*4+i];
}
Esempio n. 4
0
void mixcolumns_share(byte *stateshare[16],uint8_t n)
{
  byte ns[16];
  uint8_t i,j;
  for(i=0;i<n;i++)
  {
    for(j=0;j<4;j++)
    {
      ns[j*4]=multx(stateshare[j*4][i]) ^ multx(stateshare[j*4+1][i]) ^ stateshare[j*4+1][i] ^ stateshare[j*4+2][i] ^ stateshare[j*4+3][i];
      ns[j*4+1]=stateshare[j*4][i] ^ multx(stateshare[j*4+1][i]) ^ multx(stateshare[j*4+2][i]) ^ stateshare[j*4+2][i] ^ stateshare[j*4+3][i];
      ns[j*4+2]=stateshare[j*4][i] ^ stateshare[j*4+1][i] ^ multx(stateshare[j*4+2][i]) ^ multx(stateshare[j*4+3][i]) ^ stateshare[j*4+3][i];
      ns[j*4+3]=multx(stateshare[j*4][i]) ^ stateshare[j*4][i] ^ stateshare[j*4+1][i] ^ stateshare[j*4+2][i] ^ multx(stateshare[j*4+3][i]) ;
    }
    for(j=0;j<16;j++)
      stateshare[j][i]=ns[j];
  }
}