Select Git revision
aes-encrypt-internal.asm
Forked from
Nettle / nettle
Source project has a limited visibility.
aesdata.c 5.79 KiB
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "nettle-types.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 gf2_log[0x100];
uint8_t gf2_exp[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 exponentiatiom 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(gf2_log, 0, 0x100);
for (i = 0; i < 0x100; i++, x = x ^ xtime(x))
{
gf2_exp[i] = x;
gf2_log[x] = i;
}
/* Invalid. */
gf2_log[0] = 0;
/* The loop above sets gf2_log[1] = 0xff, which is correct,
* but gf2_log[1] = 0 is nicer. */
gf2_log[1] = 0;
}
static unsigned
mult(unsigned a, unsigned b)
{