-#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
# define BYTE_COLUMNS 0x10
#endif
-#define WORD_FORMAT "0x%08x"
+#define WORD_FORMAT "0x%08lx"
#define WORD_COLUMNS 4
-uint8_t sbox[0x100];
-uint8_t isbox[0x100];
+unsigned char sbox[0x100];
+unsigned char isbox[0x100];
-uint8_t gf2_log[0x100];
-uint8_t gf2_exp[0x100];
+unsigned char gf2_log[0x100];
+unsigned char gf2_exp[0x100];
-uint32_t dtable[4][0x100];
-uint32_t itable[4][0x100];
-uint32_t mtable[4][0x100];
+unsigned long dtable[4][0x100];
+unsigned long itable[4][0x100];
+unsigned long mtable[4][0x100];
static unsigned
xtime(unsigned x)
{
unsigned s = sbox[i];
unsigned j;
- uint32_t t =( ( (s ^ xtime(s)) << 24)
+ unsigned long t =( ( (s ^ xtime(s)) << 24)
| (s << 16) | (s << 8)
| xtime(s) );
{
unsigned s = isbox[i];
unsigned j;
- uint32_t t = ( (mult(s, 0xb) << 24)
- | (mult(s, 0xd) << 16)
- | (mult(s, 0x9) << 8)
- | (mult(s, 0xe) ));
+ unsigned long t = ( (mult(s, 0xb) << 24)
+ | (mult(s, 0xd) << 16)
+ | (mult(s, 0x9) << 8)
+ | (mult(s, 0xe) ));
for (j = 0; j<4; j++, t = (t << 8) | (t >> 24))
itable[j][i] = t;
for (i = 0; i<0x100; i++)
{
unsigned j;
- uint32_t t = ( (mult(i, 0xb) << 24)
- | (mult(i, 0xd) << 16)
- | (mult(i, 0x9) << 8)
- | (mult(i, 0xe) ));
+ unsigned long t = ( (mult(i, 0xb) << 24)
+ | (mult(i, 0xd) << 16)
+ | (mult(i, 0x9) << 8)
+ | (mult(i, 0xe) ));
for (j = 0; j<4; j++, t = (t << 8) | (t >> 24))
mtable[j][i] = t;
}
static void
-display_byte_table(const char *name, uint8_t *table)
+display_byte_table(const char *name, unsigned char *table)
{
unsigned i, j;
}
static void
-display_table(const char *name, uint32_t table[][0x100])
+display_table(const char *name, unsigned long table[][0x100])
{
unsigned i, j, k;
#include <stdio.h>
-#include "nettle-stdint.h"
-
#define ror4(x) (((x) >> 1) | (((x) & 1) << 3))
-static uint8_t q0(uint8_t x)
+static unsigned char q0(unsigned char x)
{
- static const uint8_t t0[16] = {
+ static const unsigned char t0[16] = {
0x8, 0x1, 0x7, 0xD, 0x6, 0xF, 0x3, 0x2,
0x0, 0xB, 0x5, 0x9, 0xE, 0xC, 0xA, 0x4
};
- static const uint8_t t1[16] = {
+ static const unsigned char t1[16] = {
0xE, 0xC, 0xB, 0x8, 0x1, 0x2, 0x3, 0x5,
0xF, 0x4, 0xA, 0x6, 0x7, 0x0, 0x9, 0xD
};
- static const uint8_t t2[16] = {
+ static const unsigned char t2[16] = {
0xB, 0xA, 0x5, 0xE, 0x6, 0xD, 0x9, 0x0,
0xC, 0x8, 0xF, 0x3, 0x2, 0x4, 0x7, 0x1
};
- static const uint8_t t3[16] = {
+ static const unsigned char t3[16] = {
0xD, 0x7, 0xF, 0x4, 0x1, 0x2, 0x6, 0xE,
0x9, 0xB, 0x3, 0x0, 0x8, 0x5, 0xC, 0xA
};
- uint8_t a0 = x / 16;
- uint8_t b0 = x % 16;
+ unsigned char a0 = x / 16;
+ unsigned char b0 = x % 16;
- uint8_t a1 = a0 ^ b0;
- uint8_t b1 = a0 ^ ror4(b0) ^ ((8*a0) % 16);
+ unsigned char a1 = a0 ^ b0;
+ unsigned char b1 = a0 ^ ror4(b0) ^ ((8*a0) % 16);
- uint8_t a2 = t0[a1];
- uint8_t b2 = t1[b1];
+ unsigned char a2 = t0[a1];
+ unsigned char b2 = t1[b1];
- uint8_t a3 = a2 ^ b2;
- uint8_t b3 = a2 ^ ror4(b2) ^ ((8*a2) % 16);
+ unsigned char a3 = a2 ^ b2;
+ unsigned char b3 = a2 ^ ror4(b2) ^ ((8*a2) % 16);
- uint8_t a4 = t2[a3];
- uint8_t b4 = t3[b3];
+ unsigned char a4 = t2[a3];
+ unsigned char b4 = t3[b3];
- uint8_t y = 16*b4 + a4;
+ unsigned char y = 16*b4 + a4;
return y;
}
-static uint8_t q1(uint8_t x)
+static unsigned char q1(unsigned char x)
{
- static const uint8_t t0[16] = {
+ static const unsigned char t0[16] = {
0x2, 0x8, 0xB, 0xD, 0xF, 0x7, 0x6, 0xE,
0x3, 0x1, 0x9, 0x4, 0x0, 0xA, 0xC, 0x5
};
- static const uint8_t t1[16] = {
+ static const unsigned char t1[16] = {
0x1, 0xE, 0x2, 0xB, 0x4, 0xC, 0x3, 0x7,
0x6, 0xD, 0xA, 0x5, 0xF, 0x9, 0x0, 0x8
};
- static const uint8_t t2[16] = {
+ static const unsigned char t2[16] = {
0x4, 0xC, 0x7, 0x5, 0x1, 0x6, 0x9, 0xA,
0x0, 0xE, 0xD, 0x8, 0x2, 0xB, 0x3, 0xF
};
- static const uint8_t t3[16] = {
+ static const unsigned char t3[16] = {
0xB, 0x9, 0x5, 0x1, 0xC, 0x3, 0xD, 0xE,
0x6, 0x4, 0x7, 0xF, 0x2, 0x0, 0x8, 0xA
};
- uint8_t a0 = x / 16;
- uint8_t b0 = x % 16;
+ unsigned char a0 = x / 16;
+ unsigned char b0 = x % 16;
- uint8_t a1 = a0 ^ b0;
- uint8_t b1 = a0 ^ ror4(b0) ^ ((8*a0) % 16);
+ unsigned char a1 = a0 ^ b0;
+ unsigned char b1 = a0 ^ ror4(b0) ^ ((8*a0) % 16);
- uint8_t a2 = t0[a1];
- uint8_t b2 = t1[b1];
+ unsigned char a2 = t0[a1];
+ unsigned char b2 = t1[b1];
- uint8_t a3 = a2 ^ b2;
- uint8_t b3 = a2 ^ ror4(b2) ^ ((8*a2) % 16);
+ unsigned char a3 = a2 ^ b2;
+ unsigned char b3 = a2 ^ ror4(b2) ^ ((8*a2) % 16);
- uint8_t a4 = t2[a3];
- uint8_t b4 = t3[b3];
+ unsigned char a4 = t2[a3];
+ unsigned char b4 = t3[b3];
- uint8_t y = 16*b4 + a4;
+ unsigned char y = 16*b4 + a4;
return y;
}