10 # define BYTE_FORMAT "0x%02x"
11 # define BYTE_COLUMNS 8
13 # define BYTE_FORMAT "%3d"
14 # define BYTE_COLUMNS 0x10
17 #define WORD_FORMAT "0x%08lx"
18 #define WORD_COLUMNS 4
82 (0x63^
x^(
x>>4)^(
x<<4)^(
x>>5)^(
x<<3)^(
x>>6)^(
x<<2)^(
x>>7)^(
x<<1));
89 for (
i = 0;
i<0x100;
i++)
105 for (
i = 0;
i<0x100;
i++)
109 unsigned long t =( ( (
s ^
xtime(
s)) << 24)
110 | (
s << 16) | (
s << 8)
113 for (j = 0; j<4; j++, t = (t << 8) | (t >> 24))
124 for (
i = 0;
i<0x100;
i++)
128 unsigned long t = ( (
mult(
s, 0xb) << 24)
129 | (
mult(
s, 0xd) << 16)
130 | (
mult(
s, 0x9) << 8)
133 for (j = 0; j<4; j++, t = (t << 8) | (t >> 24))
143 for (
i = 0;
i<0x100;
i++)
146 unsigned long t = ( (
mult(
i, 0xb) << 24)
147 | (
mult(
i, 0xd) << 16)
148 | (
mult(
i, 0x9) << 8)
151 for (j = 0; j<4; j++, t = (t << 8) | (t >> 24))
178 printf(
"uint32_t %s[4][0x100] =\n{\n ",
name);
180 for (
k = 0;
k<4;
k++)
197 printf(
"(%x x^3 + %x x^2 + %x x + %x)",
198 p[3],
p[2],
p[1],
p[0]);
228 for (
a = 1;
a<0x100;
a++)
234 printf(
"invert(%x) = 0 !\n",
a);
238 printf(
"invert(%x) = %x; product = %x\n",
241 for (
b = 1;
b<0x100;
b++)
251 printf(
"%x x %x = %x, invert(%x) = %x, %x x %x = %x\n",
252 a,
b,
c,
a, a1,
c, a1, u);
256 printf(
"%x x %x = %x, invert(%x) = %x, %x x %x = %x\n",
293 for (
i = 0;
i<4;
i++)
303 for (
i = 0;
i<4;
i++)
static unsigned invert(unsigned x)
static void compute_itable(void)
unsigned char gf2_exp[0x100]
static unsigned affine(unsigned x)
int main(int argc, char **argv)
unsigned char gf2_log[0x100]
unsigned long itable[4][0x100]
static void display_polynomial(const unsigned *p)
static unsigned mult(unsigned a, unsigned b)
static void compute_log(void)
unsigned long dtable[4][0x100]
static void compute_sbox(void)
static void compute_dtable(void)
static unsigned xtime(unsigned x)
unsigned char isbox[0x100]
static void compute_mtable(void)
unsigned long mtable[4][0x100]
static void display_table(const char *name, unsigned long table[][0x100])
static void display_byte_table(const char *name, unsigned char *table)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
return memset(p, 0, total)
static static fork const void static count static fd const char const char static newpath char char argv
assert(limit<=UINT32_MAX/2)