PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
rijndael.c File Reference
#include "postgres.h"
#include <sys/param.h>
#include "px.h"
#include "rijndael.h"
#include "rijndael.tbl"
Include dependency graph for rijndael.c:

Go to the source code of this file.

Macros

#define PRE_CALC_TABLES
 
#define LARGE_TABLES
 
#define rotr(x, n)   (((x) >> ((int)(n))) | ((x) << (32 - (int)(n))))
 
#define rotl(x, n)   (((x) << ((int)(n))) | ((x) >> (32 - (int)(n))))
 
#define bswap(x)   ((rotl((x), 8) & 0x00ff00ff) | (rotr((x), 8) & 0xff00ff00))
 
#define byte(x, n)   ((u1byte)((x) >> (8 * (n))))
 
#define io_swap(x)   (x)
 
#define tab_gen   1
 
#define ff_mult(a, b)   ((a) && (b) ? pow_tab[(log_tab[a] + log_tab[b]) % 255] : 0)
 
#define f_rn(bo, bi, n, k)
 
#define i_rn(bo, bi, n, k)
 
#define ls_box(x)
 
#define f_rl(bo, bi, n, k)
 
#define i_rl(bo, bi, n, k)
 
#define star_x(x)   (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b)
 
#define imix_col(y, x)
 
#define loop4(i)
 
#define loop6(i)
 
#define loop8(i)
 
#define f_nround(bo, bi, k)
 
#define f_lround(bo, bi, k)
 
#define i_nround(bo, bi, k)
 
#define i_lround(bo, bi, k)
 

Functions

static void gen_tabs (void)
 
rijndael_ctxrijndael_set_key (rijndael_ctx *ctx, const u4byte *in_key, const u4byte key_len, int encrypt)
 
void rijndael_encrypt (rijndael_ctx *ctx, const u4byte *in_blk, u4byte *out_blk)
 
void rijndael_decrypt (rijndael_ctx *ctx, const u4byte *in_blk, u4byte *out_blk)
 
void aes_set_key (rijndael_ctx *ctx, const uint8 *key, unsigned keybits, int enc)
 
void aes_ecb_encrypt (rijndael_ctx *ctx, uint8 *data, unsigned len)
 
void aes_ecb_decrypt (rijndael_ctx *ctx, uint8 *data, unsigned len)
 
void aes_cbc_encrypt (rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len)
 
void aes_cbc_decrypt (rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len)
 

Macro Definition Documentation

#define bswap (   x)    ((rotl((x), 8) & 0x00ff00ff) | (rotr((x), 8) & 0xff00ff00))

Definition at line 64 of file rijndael.c.

#define f_lround (   bo,
  bi,
 
)
Value:
do { \
f_rl(bo, bi, 0, k); \
f_rl(bo, bi, 1, k); \
f_rl(bo, bi, 2, k); \
f_rl(bo, bi, 3, k); \
} while (0)
#define f_rl(bo, bi, n, k)
Definition: rijndael.c:124

Definition at line 378 of file rijndael.c.

Referenced by rijndael_encrypt().

#define f_nround (   bo,
  bi,
 
)
Value:
do { \
f_rn(bo, bi, 0, k); \
f_rn(bo, bi, 1, k); \
f_rn(bo, bi, 2, k); \
f_rn(bo, bi, 3, k); \
k += 4; \
} while (0)
#define f_rn(bo, bi, n, k)
Definition: rijndael.c:104

Definition at line 369 of file rijndael.c.

Referenced by rijndael_encrypt().

#define f_rl (   bo,
  bi,
  n,
 
)
Value:
(bo)[n] = fl_tab[0][byte((bi)[n],0)] ^ \
fl_tab[1][byte((bi)[((n) + 1) & 3],1)] ^ \
fl_tab[2][byte((bi)[((n) + 2) & 3],2)] ^ \
fl_tab[3][byte((bi)[((n) + 3) & 3],3)] ^ *((k) + (n))
#define byte(x, n)
Definition: rijndael.c:68

Definition at line 124 of file rijndael.c.

#define f_rn (   bo,
  bi,
  n,
 
)
Value:
(bo)[n] = ft_tab[0][byte((bi)[n],0)] ^ \
ft_tab[1][byte((bi)[((n) + 1) & 3],1)] ^ \
ft_tab[2][byte((bi)[((n) + 2) & 3],2)] ^ \
ft_tab[3][byte((bi)[((n) + 3) & 3],3)] ^ *((k) + (n))
#define byte(x, n)
Definition: rijndael.c:68

Definition at line 104 of file rijndael.c.

#define ff_mult (   a,
 
)    ((a) && (b) ? pow_tab[(log_tab[a] + log_tab[b]) % 255] : 0)

Definition at line 102 of file rijndael.c.

Referenced by gen_tabs().

#define i_lround (   bo,
  bi,
 
)
Value:
do { \
i_rl(bo, bi, 0, k); \
i_rl(bo, bi, 1, k); \
i_rl(bo, bi, 2, k); \
i_rl(bo, bi, 3, k); \
} while (0)
#define i_rl(bo, bi, n, k)
Definition: rijndael.c:130

Definition at line 442 of file rijndael.c.

Referenced by rijndael_decrypt().

#define i_nround (   bo,
  bi,
 
)
Value:
do { \
i_rn(bo, bi, 0, k); \
i_rn(bo, bi, 1, k); \
i_rn(bo, bi, 2, k); \
i_rn(bo, bi, 3, k); \
k -= 4; \
} while (0)
#define i_rn(bo, bi, n, k)
Definition: rijndael.c:110

Definition at line 433 of file rijndael.c.

Referenced by rijndael_decrypt().

#define i_rl (   bo,
  bi,
  n,
 
)
Value:
(bo)[n] = il_tab[0][byte((bi)[n],0)] ^ \
il_tab[1][byte((bi)[((n) + 3) & 3],1)] ^ \
il_tab[2][byte((bi)[((n) + 2) & 3],2)] ^ \
il_tab[3][byte((bi)[((n) + 1) & 3],3)] ^ *((k) + (n))
#define byte(x, n)
Definition: rijndael.c:68

Definition at line 130 of file rijndael.c.

#define i_rn (   bo,
  bi,
  n,
 
)
Value:
(bo)[n] = it_tab[0][byte((bi)[n],0)] ^ \
it_tab[1][byte((bi)[((n) + 3) & 3],1)] ^ \
it_tab[2][byte((bi)[((n) + 2) & 3],2)] ^ \
it_tab[3][byte((bi)[((n) + 1) & 3],3)] ^ *((k) + (n))
#define byte(x, n)
Definition: rijndael.c:68

Definition at line 110 of file rijndael.c.

#define imix_col (   y,
 
)
Value:
do { \
u = star_x(x); \
v = star_x(u); \
w = star_x(v); \
t = w ^ (x); \
(y) = u ^ v ^ w; \
(y) ^= rotr(u ^ t, 8) ^ \
rotr(v ^ t, 16) ^ \
rotr(t,24); \
} while (0)
#define rotr(x, n)
Definition: rijndael.c:59
#define star_x(x)
Definition: rijndael.c:257

Definition at line 259 of file rijndael.c.

Referenced by rijndael_set_key().

#define io_swap (   x)    (x)

Definition at line 73 of file rijndael.c.

Referenced by rijndael_decrypt(), rijndael_encrypt(), and rijndael_set_key().

#define LARGE_TABLES

Definition at line 51 of file rijndael.c.

#define loop4 (   i)
Value:
do { t = ls_box(rotr(t, 8)) ^ rco_tab[i]; \
t ^= e_key[4 * i]; e_key[4 * i + 4] = t; \
t ^= e_key[4 * i + 1]; e_key[4 * i + 5] = t; \
t ^= e_key[4 * i + 2]; e_key[4 * i + 6] = t; \
t ^= e_key[4 * i + 3]; e_key[4 * i + 7] = t; \
} while (0)
#define rotr(x, n)
Definition: rijndael.c:59
#define ls_box(x)
Definition: rijndael.c:118
int i

Definition at line 273 of file rijndael.c.

Referenced by rijndael_set_key().

#define loop6 (   i)
Value:
do { t = ls_box(rotr(t, 8)) ^ rco_tab[i]; \
t ^= e_key[6 * (i)]; e_key[6 * (i) + 6] = t; \
t ^= e_key[6 * (i) + 1]; e_key[6 * (i) + 7] = t; \
t ^= e_key[6 * (i) + 2]; e_key[6 * (i) + 8] = t; \
t ^= e_key[6 * (i) + 3]; e_key[6 * (i) + 9] = t; \
t ^= e_key[6 * (i) + 4]; e_key[6 * (i) + 10] = t; \
t ^= e_key[6 * (i) + 5]; e_key[6 * (i) + 11] = t; \
} while (0)
#define rotr(x, n)
Definition: rijndael.c:59
#define ls_box(x)
Definition: rijndael.c:118
int i

Definition at line 281 of file rijndael.c.

Referenced by rijndael_set_key().

#define loop8 (   i)
Value:
do { t = ls_box(rotr(t, 8)) ^ rco_tab[i]; \
t ^= e_key[8 * (i)]; e_key[8 * (i) + 8] = t; \
t ^= e_key[8 * (i) + 1]; e_key[8 * (i) + 9] = t; \
t ^= e_key[8 * (i) + 2]; e_key[8 * (i) + 10] = t; \
t ^= e_key[8 * (i) + 3]; e_key[8 * (i) + 11] = t; \
t = e_key[8 * (i) + 4] ^ ls_box(t); \
e_key[8 * (i) + 12] = t; \
t ^= e_key[8 * (i) + 5]; e_key[8 * (i) + 13] = t; \
t ^= e_key[8 * (i) + 6]; e_key[8 * (i) + 14] = t; \
t ^= e_key[8 * (i) + 7]; e_key[8 * (i) + 15] = t; \
} while (0)
#define rotr(x, n)
Definition: rijndael.c:59
#define ls_box(x)
Definition: rijndael.c:118
int i

Definition at line 291 of file rijndael.c.

Referenced by rijndael_set_key().

#define ls_box (   x)
Value:
( fl_tab[0][byte(x, 0)] ^ \
fl_tab[1][byte(x, 1)] ^ \
fl_tab[2][byte(x, 2)] ^ \
fl_tab[3][byte(x, 3)] )
#define byte(x, n)
Definition: rijndael.c:68

Definition at line 118 of file rijndael.c.

#define PRE_CALC_TABLES

Definition at line 50 of file rijndael.c.

#define rotl (   x,
 
)    (((x) << ((int)(n))) | ((x) >> (32 - (int)(n))))

Definition at line 60 of file rijndael.c.

Referenced by gen_tabs().

#define rotr (   x,
 
)    (((x) >> ((int)(n))) | ((x) << (32 - (int)(n))))

Definition at line 59 of file rijndael.c.

#define star_x (   x)    (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b)

Definition at line 257 of file rijndael.c.

#define tab_gen   1

Definition at line 83 of file rijndael.c.

Referenced by gen_tabs(), and rijndael_set_key().

Function Documentation

void aes_cbc_decrypt ( rijndael_ctx ctx,
uint8 iva,
uint8 data,
unsigned  len 
)

Definition at line 567 of file rijndael.c.

References buf, and rijndael_decrypt().

Referenced by rj_decrypt().

568 {
569  uint32 *d = (uint32 *) data;
570  unsigned bs = 16;
571  uint32 buf[4],
572  iv[4];
573 
574  memcpy(iv, iva, bs);
575  while (len >= bs)
576  {
577  buf[0] = d[0];
578  buf[1] = d[1];
579  buf[2] = d[2];
580  buf[3] = d[3];
581 
582  rijndael_decrypt(ctx, buf, d);
583 
584  d[0] ^= iv[0];
585  d[1] ^= iv[1];
586  d[2] ^= iv[2];
587  d[3] ^= iv[3];
588 
589  iv[0] = buf[0];
590  iv[1] = buf[1];
591  iv[2] = buf[2];
592  iv[3] = buf[3];
593  d += 4;
594  len -= bs;
595  }
596 }
static char * buf
Definition: pg_test_fsync.c:66
unsigned int uint32
Definition: c.h:268
void rijndael_decrypt(rijndael_ctx *ctx, const u4byte *in_blk, u4byte *out_blk)
Definition: rijndael.c:451
void aes_cbc_encrypt ( rijndael_ctx ctx,
uint8 iva,
uint8 data,
unsigned  len 
)

Definition at line 545 of file rijndael.c.

References rijndael_encrypt().

Referenced by rj_encrypt().

546 {
547  uint32 *iv = (uint32 *) iva;
548  uint32 *d = (uint32 *) data;
549  unsigned bs = 16;
550 
551  while (len >= bs)
552  {
553  d[0] ^= iv[0];
554  d[1] ^= iv[1];
555  d[2] ^= iv[2];
556  d[3] ^= iv[3];
557 
558  rijndael_encrypt(ctx, d, d);
559 
560  iv = d;
561  d += bs / 4;
562  len -= bs;
563  }
564 }
unsigned int uint32
Definition: c.h:268
void rijndael_encrypt(rijndael_ctx *ctx, const u4byte *in_blk, u4byte *out_blk)
Definition: rijndael.c:387
void aes_ecb_decrypt ( rijndael_ctx ctx,
uint8 data,
unsigned  len 
)

Definition at line 529 of file rijndael.c.

References rijndael_decrypt().

Referenced by rj_decrypt().

530 {
531  unsigned bs = 16;
532  uint32 *d;
533 
534  while (len >= bs)
535  {
536  d = (uint32 *) data;
537  rijndael_decrypt(ctx, d, d);
538 
539  len -= bs;
540  data += bs;
541  }
542 }
unsigned int uint32
Definition: c.h:268
void rijndael_decrypt(rijndael_ctx *ctx, const u4byte *in_blk, u4byte *out_blk)
Definition: rijndael.c:451
void aes_ecb_encrypt ( rijndael_ctx ctx,
uint8 data,
unsigned  len 
)

Definition at line 513 of file rijndael.c.

References rijndael_encrypt().

Referenced by rj_encrypt().

514 {
515  unsigned bs = 16;
516  uint32 *d;
517 
518  while (len >= bs)
519  {
520  d = (uint32 *) data;
521  rijndael_encrypt(ctx, d, d);
522 
523  len -= bs;
524  data += bs;
525  }
526 }
unsigned int uint32
Definition: c.h:268
void rijndael_encrypt(rijndael_ctx *ctx, const u4byte *in_blk, u4byte *out_blk)
Definition: rijndael.c:387
void aes_set_key ( rijndael_ctx ctx,
const uint8 key,
unsigned  keybits,
int  enc 
)

Definition at line 504 of file rijndael.c.

References rijndael_set_key().

Referenced by rj_real_init().

505 {
506  uint32 *k;
507 
508  k = (uint32 *) key;
509  rijndael_set_key(ctx, k, keybits, enc);
510 }
rijndael_ctx * rijndael_set_key(rijndael_ctx *ctx, const u4byte *in_key, const u4byte key_len, int encrypt)
Definition: rijndael.c:305
struct pg_encoding enc
Definition: encode.c:522
unsigned int uint32
Definition: c.h:268
static void gen_tabs ( void  )
static

Definition at line 157 of file rijndael.c.

References ff_mult, i, rotl, and tab_gen.

Referenced by rijndael_set_key().

158 {
159 #ifndef PRE_CALC_TABLES
160  u4byte i,
161  t;
162  u1byte p,
163  q;
164 
165  /* log and power tables for GF(2**8) finite field with */
166  /* 0x11b as modular polynomial - the simplest prmitive */
167  /* root is 0x11, used here to generate the tables */
168 
169  for (i = 0, p = 1; i < 256; ++i)
170  {
171  pow_tab[i] = (u1byte) p;
172  log_tab[p] = (u1byte) i;
173 
174  p = p ^ (p << 1) ^ (p & 0x80 ? 0x01b : 0);
175  }
176 
177  log_tab[1] = 0;
178  p = 1;
179 
180  for (i = 0; i < 10; ++i)
181  {
182  rco_tab[i] = p;
183 
184  p = (p << 1) ^ (p & 0x80 ? 0x1b : 0);
185  }
186 
187  /* note that the affine byte transformation matrix in */
188  /* rijndael specification is in big endian format with */
189  /* bit 0 as the most significant bit. In the remainder */
190  /* of the specification the bits are numbered from the */
191  /* least significant end of a byte. */
192 
193  for (i = 0; i < 256; ++i)
194  {
195  p = (i ? pow_tab[255 - log_tab[i]] : 0);
196  q = p;
197  q = (q >> 7) | (q << 1);
198  p ^= q;
199  q = (q >> 7) | (q << 1);
200  p ^= q;
201  q = (q >> 7) | (q << 1);
202  p ^= q;
203  q = (q >> 7) | (q << 1);
204  p ^= q ^ 0x63;
205  sbx_tab[i] = (u1byte) p;
206  isb_tab[p] = (u1byte) i;
207  }
208 
209  for (i = 0; i < 256; ++i)
210  {
211  p = sbx_tab[i];
212 
213 #ifdef LARGE_TABLES
214 
215  t = p;
216  fl_tab[0][i] = t;
217  fl_tab[1][i] = rotl(t, 8);
218  fl_tab[2][i] = rotl(t, 16);
219  fl_tab[3][i] = rotl(t, 24);
220 #endif
221  t = ((u4byte) ff_mult(2, p)) |
222  ((u4byte) p << 8) |
223  ((u4byte) p << 16) |
224  ((u4byte) ff_mult(3, p) << 24);
225 
226  ft_tab[0][i] = t;
227  ft_tab[1][i] = rotl(t, 8);
228  ft_tab[2][i] = rotl(t, 16);
229  ft_tab[3][i] = rotl(t, 24);
230 
231  p = isb_tab[i];
232 
233 #ifdef LARGE_TABLES
234 
235  t = p;
236  il_tab[0][i] = t;
237  il_tab[1][i] = rotl(t, 8);
238  il_tab[2][i] = rotl(t, 16);
239  il_tab[3][i] = rotl(t, 24);
240 #endif
241  t = ((u4byte) ff_mult(14, p)) |
242  ((u4byte) ff_mult(9, p) << 8) |
243  ((u4byte) ff_mult(13, p) << 16) |
244  ((u4byte) ff_mult(11, p) << 24);
245 
246  it_tab[0][i] = t;
247  it_tab[1][i] = rotl(t, 8);
248  it_tab[2][i] = rotl(t, 16);
249  it_tab[3][i] = rotl(t, 24);
250  }
251 
252  tab_gen = 1;
253 #endif /* !PRE_CALC_TABLES */
254 }
uint32 u4byte
Definition: rijndael.h:27
uint8 u1byte
Definition: rijndael.h:25
#define tab_gen
Definition: rijndael.c:83
#define ff_mult(a, b)
Definition: rijndael.c:102
int i
#define rotl(x, n)
Definition: rijndael.c:60
void rijndael_decrypt ( rijndael_ctx ctx,
const u4byte in_blk,
u4byte out_blk 
)

Definition at line 451 of file rijndael.c.

References _rijndael_ctx::d_key, _rijndael_ctx::e_key, i_lround, i_nround, io_swap, and _rijndael_ctx::k_len.

Referenced by aes_cbc_decrypt(), and aes_ecb_decrypt().

452 {
453  u4byte b0[4],
454  b1[4],
455  *kp;
456  u4byte k_len = ctx->k_len;
457  u4byte *e_key = ctx->e_key;
458  u4byte *d_key = ctx->d_key;
459 
460  b0[0] = io_swap(in_blk[0]) ^ e_key[4 * k_len + 24];
461  b0[1] = io_swap(in_blk[1]) ^ e_key[4 * k_len + 25];
462  b0[2] = io_swap(in_blk[2]) ^ e_key[4 * k_len + 26];
463  b0[3] = io_swap(in_blk[3]) ^ e_key[4 * k_len + 27];
464 
465  kp = d_key + 4 * (k_len + 5);
466 
467  if (k_len > 6)
468  {
469  i_nround(b1, b0, kp);
470  i_nround(b0, b1, kp);
471  }
472 
473  if (k_len > 4)
474  {
475  i_nround(b1, b0, kp);
476  i_nround(b0, b1, kp);
477  }
478 
479  i_nround(b1, b0, kp);
480  i_nround(b0, b1, kp);
481  i_nround(b1, b0, kp);
482  i_nround(b0, b1, kp);
483  i_nround(b1, b0, kp);
484  i_nround(b0, b1, kp);
485  i_nround(b1, b0, kp);
486  i_nround(b0, b1, kp);
487  i_nround(b1, b0, kp);
488  i_lround(b0, b1, kp);
489 
490  out_blk[0] = io_swap(b0[0]);
491  out_blk[1] = io_swap(b0[1]);
492  out_blk[2] = io_swap(b0[2]);
493  out_blk[3] = io_swap(b0[3]);
494 }
#define i_lround(bo, bi, k)
Definition: rijndael.c:442
uint32 u4byte
Definition: rijndael.h:27
u4byte k_len
Definition: rijndael.h:35
#define i_nround(bo, bi, k)
Definition: rijndael.c:433
u4byte d_key[64]
Definition: rijndael.h:38
#define io_swap(x)
Definition: rijndael.c:73
u4byte e_key[64]
Definition: rijndael.h:37
void rijndael_encrypt ( rijndael_ctx ctx,
const u4byte in_blk,
u4byte out_blk 
)

Definition at line 387 of file rijndael.c.

References _rijndael_ctx::e_key, f_lround, f_nround, io_swap, and _rijndael_ctx::k_len.

Referenced by aes_cbc_encrypt(), and aes_ecb_encrypt().

388 {
389  u4byte k_len = ctx->k_len;
390  u4byte *e_key = ctx->e_key;
391  u4byte b0[4],
392  b1[4],
393  *kp;
394 
395  b0[0] = io_swap(in_blk[0]) ^ e_key[0];
396  b0[1] = io_swap(in_blk[1]) ^ e_key[1];
397  b0[2] = io_swap(in_blk[2]) ^ e_key[2];
398  b0[3] = io_swap(in_blk[3]) ^ e_key[3];
399 
400  kp = e_key + 4;
401 
402  if (k_len > 6)
403  {
404  f_nround(b1, b0, kp);
405  f_nround(b0, b1, kp);
406  }
407 
408  if (k_len > 4)
409  {
410  f_nround(b1, b0, kp);
411  f_nround(b0, b1, kp);
412  }
413 
414  f_nround(b1, b0, kp);
415  f_nround(b0, b1, kp);
416  f_nround(b1, b0, kp);
417  f_nround(b0, b1, kp);
418  f_nround(b1, b0, kp);
419  f_nround(b0, b1, kp);
420  f_nround(b1, b0, kp);
421  f_nround(b0, b1, kp);
422  f_nround(b1, b0, kp);
423  f_lround(b0, b1, kp);
424 
425  out_blk[0] = io_swap(b0[0]);
426  out_blk[1] = io_swap(b0[1]);
427  out_blk[2] = io_swap(b0[2]);
428  out_blk[3] = io_swap(b0[3]);
429 }
uint32 u4byte
Definition: rijndael.h:27
u4byte k_len
Definition: rijndael.h:35
#define f_nround(bo, bi, k)
Definition: rijndael.c:369
#define f_lround(bo, bi, k)
Definition: rijndael.c:378
#define io_swap(x)
Definition: rijndael.c:73
u4byte e_key[64]
Definition: rijndael.h:37
rijndael_ctx* rijndael_set_key ( rijndael_ctx ctx,
const u4byte in_key,
const u4byte  key_len,
int  encrypt 
)

Definition at line 305 of file rijndael.c.

References _rijndael_ctx::d_key, _rijndael_ctx::decrypt, _rijndael_ctx::e_key, gen_tabs(), i, imix_col, io_swap, _rijndael_ctx::k_len, loop4, loop6, loop8, and tab_gen.

Referenced by aes_set_key().

307 {
308  u4byte i,
309  t,
310  u,
311  v,
312  w;
313  u4byte *e_key = ctx->e_key;
314  u4byte *d_key = ctx->d_key;
315 
316  ctx->decrypt = !encrypt;
317 
318  if (!tab_gen)
319  gen_tabs();
320 
321  ctx->k_len = (key_len + 31) / 32;
322 
323  e_key[0] = io_swap(in_key[0]);
324  e_key[1] = io_swap(in_key[1]);
325  e_key[2] = io_swap(in_key[2]);
326  e_key[3] = io_swap(in_key[3]);
327 
328  switch (ctx->k_len)
329  {
330  case 4:
331  t = e_key[3];
332  for (i = 0; i < 10; ++i)
333  loop4(i);
334  break;
335 
336  case 6:
337  e_key[4] = io_swap(in_key[4]);
338  t = e_key[5] = io_swap(in_key[5]);
339  for (i = 0; i < 8; ++i)
340  loop6(i);
341  break;
342 
343  case 8:
344  e_key[4] = io_swap(in_key[4]);
345  e_key[5] = io_swap(in_key[5]);
346  e_key[6] = io_swap(in_key[6]);
347  t = e_key[7] = io_swap(in_key[7]);
348  for (i = 0; i < 7; ++i)
349  loop8(i);
350  break;
351  }
352 
353  if (!encrypt)
354  {
355  d_key[0] = e_key[0];
356  d_key[1] = e_key[1];
357  d_key[2] = e_key[2];
358  d_key[3] = e_key[3];
359 
360  for (i = 4; i < 4 * ctx->k_len + 24; ++i)
361  imix_col(d_key[i], e_key[i]);
362  }
363 
364  return ctx;
365 }
#define loop6(i)
Definition: rijndael.c:281
#define loop4(i)
Definition: rijndael.c:273
#define imix_col(y, x)
Definition: rijndael.c:259
uint32 u4byte
Definition: rijndael.h:27
u4byte k_len
Definition: rijndael.h:35
u4byte d_key[64]
Definition: rijndael.h:38
#define io_swap(x)
Definition: rijndael.c:73
#define tab_gen
Definition: rijndael.c:83
#define loop8(i)
Definition: rijndael.c:291
static void gen_tabs(void)
Definition: rijndael.c:157
u4byte e_key[64]
Definition: rijndael.h:37
int i