Select Git revision
Forked from
Nettle / nettle
Source project has a limited visibility.
-
Niels Möller authored
Rev: nettle/ChangeLog:1.69 Rev: nettle/asm.m4:1.2
Niels Möller authoredRev: nettle/ChangeLog:1.69 Rev: nettle/asm.m4:1.2
aesdata.c 5.68 KiB
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#if 1
# define BYTE_FORMAT "0x%02x"
# define BYTE_COLUMNS 8
#else
# define BYTE_FORMAT "%3d"
# define BYTE_COLUMNS 0x10
#endif
#define WORD_FORMAT "0x%08x"
#define WORD_COLUMNS 4
uint8_t sbox[0x100];
uint8_t isbox[0x100];
uint8_t log[0x100];
uint8_t ilog[0x100];
uint32_t dtable[4][0x100];
uint32_t itable[4][0x100];
static unsigned
xtime(unsigned x)
{
assert (x < 0x100);
x <<= 1;
if (x & 0x100)
x ^= 0x11b;
assert (x < 0x100);
return x;
}
/* Computes the expoenntiatiom and logarithm tables for GF_2, to the
* base x+1 (0x03). The unit element is 1 (0x01).*/
static void
compute_log(void)
{
unsigned i = 0;
unsigned x = 1;
memset(log, 0, 0x100);
for (i = 0; i < 0x100; i++, x = x ^ xtime(x))
{
ilog[i] = x;
log[x] = i;
}
/* Invalid. */
log[0] = 0;
/* The loop above sets log[1] = 0xff, which is correct,
* but log[1] = 0 is nicer. */
log[1] = 0;
}
static unsigned
mult(unsigned a, unsigned b)
{
return (a && b) ? ilog[ (log[a] + log[b]) % 255] : 0;
}
static unsigned
invert(unsigned x)