Ejemplo n.º 1
0
Archivo: gf2_8.c Proyecto: imace/mbgapp
inline gf2_8
gf2_8_multiply(gf2_8 x, gf2_8 y) {
  gf2_8 z = 0;

  if (y &   1) z ^= x; x = gf2_8_shift(x);
  if (y &   2) z ^= x; x = gf2_8_shift(x);
  if (y &   4) z ^= x; x = gf2_8_shift(x);
  if (y &   8) z ^= x; x = gf2_8_shift(x);
  if (y &  16) z ^= x; x = gf2_8_shift(x);
  if (y &  32) z ^= x; x = gf2_8_shift(x);
  if (y &  64) z ^= x; x = gf2_8_shift(x);
  if (y & 128) z ^= x; 
  
  return z;
}
Ejemplo n.º 2
0
void
aes_compute_tables(void) {
  int i;
  uint32_t x1, x2, x3;
  v32_t tmp;

  /* initialize substitution table */
  aes_init_sbox();

  /* combine sbox with linear operations to form 8-bit to 32-bit tables */
  for (i=0; i < 256; i++) {
    x1 = aes_sbox[i];
    x2 = gf2_8_shift(x1);
    x3 = x2 ^ x1;

    tmp.v8[0] = x2;
    tmp.v8[1] = x1;
    tmp.v8[2] = x1;
    tmp.v8[3] = x3;
    T0[i] = tmp.value;

    tmp.v8[0] = x3;
    tmp.v8[1] = x2;
    tmp.v8[2] = x1;
    tmp.v8[3] = x1;
    T1[i] = tmp.value;
     
    tmp.v8[0] = x1;
    tmp.v8[1] = x3;
    tmp.v8[2] = x2;
    tmp.v8[3] = x1;
    T2[i] = tmp.value;

    tmp.v8[0] = x1;
    tmp.v8[1] = x1;
    tmp.v8[2] = x3;
    tmp.v8[3] = x2;
    T3[i] = tmp.value;
     
  }
}