~ubuntu-branches/ubuntu/trusty/nettle/trusty

« back to all changes in this revision

Viewing changes to aesdata.c

  • Committer: Package Import Robot
  • Author(s): Magnus Holmgren
  • Date: 2013-05-07 22:57:14 UTC
  • mfrom: (8.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130507225714-s331yr8ov53dtt17
Tags: 2.7-2
Tag some (ECC related) symbols that only exist on some architectures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#if HAVE_CONFIG_H
2
 
# include "config.h"
3
 
#endif
4
 
 
5
1
#include <assert.h>
6
2
#include <stdlib.h>
7
3
#include <stdio.h>
8
4
#include <string.h>
9
5
 
10
 
#include "nettle-types.h"
11
 
 
12
6
#if 1
13
7
# define BYTE_FORMAT "0x%02x"
14
8
# define BYTE_COLUMNS 8
17
11
# define BYTE_COLUMNS 0x10
18
12
#endif
19
13
 
20
 
#define WORD_FORMAT "0x%08x"
 
14
#define WORD_FORMAT "0x%08lx"
21
15
#define WORD_COLUMNS 4
22
16
 
23
 
uint8_t sbox[0x100];
24
 
uint8_t isbox[0x100];
25
 
 
26
 
uint8_t gf2_log[0x100];
27
 
uint8_t gf2_exp[0x100];
28
 
 
29
 
uint32_t dtable[4][0x100];
30
 
uint32_t itable[4][0x100];
 
17
unsigned char sbox[0x100];
 
18
unsigned char isbox[0x100];
 
19
 
 
20
unsigned char gf2_log[0x100];
 
21
unsigned char gf2_exp[0x100];
 
22
 
 
23
unsigned long dtable[4][0x100];
 
24
unsigned long itable[4][0x100];
 
25
unsigned long mtable[4][0x100];
31
26
 
32
27
static unsigned
33
28
xtime(unsigned x)
108
103
    {
109
104
      unsigned s = sbox[i];
110
105
      unsigned j;
111
 
      uint32_t t  =( ( (s ^ xtime(s)) << 24)
 
106
      unsigned long t  =( ( (s ^ xtime(s)) << 24)
112
107
                     | (s << 16) | (s << 8)
113
108
                     | xtime(s) );
114
109
 
127
122
    {
128
123
      unsigned s = isbox[i];
129
124
      unsigned j;
130
 
      uint32_t t = ( (mult(s, 0xb) << 24)
131
 
                   | (mult(s, 0xd) << 16)
132
 
                   | (mult(s, 0x9) << 8)
133
 
                   | (mult(s, 0xe) ));
 
125
      unsigned long t = ( (mult(s, 0xb) << 24)
 
126
                        | (mult(s, 0xd) << 16)
 
127
                        | (mult(s, 0x9) << 8)
 
128
                        | (mult(s, 0xe) ));
134
129
      
135
130
      for (j = 0; j<4; j++, t = (t << 8) | (t >> 24))
136
131
        itable[j][i] = t;
137
132
    }
138
133
}
139
134
 
140
 
static void
141
 
display_byte_table(const char *name, uint8_t *table)
 
135
/* Used for key inversion, inverse mix column. No sbox. */
 
136
static void
 
137
compute_mtable(void)
 
138
{
 
139
  unsigned i;
 
140
  for (i = 0; i<0x100; i++)
 
141
    {
 
142
      unsigned j;
 
143
      unsigned long t = ( (mult(i, 0xb) << 24)
 
144
                        | (mult(i, 0xd) << 16)
 
145
                        | (mult(i, 0x9) << 8)
 
146
                        | (mult(i, 0xe) ));
 
147
      
 
148
      for (j = 0; j<4; j++, t = (t << 8) | (t >> 24))
 
149
        mtable[j][i] = t;
 
150
    }
 
151
}
 
152
 
 
153
static void
 
154
display_byte_table(const char *name, unsigned char *table)
142
155
{
143
156
  unsigned i, j;
144
157
 
155
168
}
156
169
 
157
170
static void
158
 
display_table(const char *name, uint32_t table[][0x100])
 
171
display_table(const char *name, unsigned long table[][0x100])
159
172
{
160
173
  unsigned i, j, k;
161
174
  
200
213
 
201
214
      compute_itable();
202
215
      display_table("itable", itable);
203
 
  
 
216
 
 
217
      compute_mtable();
 
218
      display_table("mtable", mtable);
 
219
 
204
220
      return 0;
205
221
    }
206
222
  else if (argc == 2)