void aes_compute_inv_tables(void) { int i; uint8_t x, xe, x9, xd, xb; v32_t tmp; /* combine sbox with linear operations to form 8-bit to 32-bit tables */ for (i=0; i < 256; i++) { x = aes_inv_sbox[i]; xe = gf2_8_multiply(0x0e, x); x9 = gf2_8_multiply(0x09, x); xd = gf2_8_multiply(0x0d, x); xb = gf2_8_multiply(0x0b, x); tmp.v8[0] = xe; tmp.v8[1] = x9; tmp.v8[2] = xd; tmp.v8[3] = xb; U0[i] = tmp.value; tmp.v8[0] = xb; tmp.v8[1] = xe; tmp.v8[2] = x9; tmp.v8[3] = xd; U1[i] = tmp.value; tmp.v8[0] = xd; tmp.v8[1] = xb; tmp.v8[2] = xe; tmp.v8[3] = x9; U2[i] = tmp.value; tmp.v8[0] = x9; tmp.v8[1] = xd; tmp.v8[2] = xb; tmp.v8[3] = xe; U3[i] = tmp.value; tmp.v8[0] = tmp.v8[1] = tmp.v8[2] = tmp.v8[3] = x; U4[i] = tmp.value; } }
gf2_8 gf2_8_compute_inverse(gf2_8 x) { unsigned int i; if (x == 0) return 0; /* zero is a special case */ for (i=0; i < 256; i++) if (gf2_8_multiply((gf2_8) i, x) == 1) return (gf2_8) i; return 0; }