Merge remote-tracking branch 'mjb/master'
[fw/altos] / src / aes / ao_aes_int.h
1 /* Copyright (C) 2000-2009 Peter Selinger.
2    This file is part of ccrypt. It is free software and it is covered
3    by the GNU general public license. See the file COPYING for details. */
4
5 /* rijndael.h */
6 /* $Id: rijndael.h 258 2009-08-26 17:46:10Z selinger $ */
7
8 /* derived from original source: rijndael-alg-ref.h   v2.0   August '99
9  * Reference ANSI C code for NIST competition
10  * authors: Paulo Barreto
11  *          Vincent Rijmen
12  */
13
14 #ifndef __RIJNDAEL_H
15 #define __RIJNDAEL_H
16
17 #include <stdint.h>
18
19 typedef uint8_t word8;
20 typedef uint32_t word32;
21
22 /* a type to hold 32 bits accessible as 1 integer or 4 bytes */
23 union word8x4_u {
24   word8 w8[4];
25   word32 w32;
26 };
27 typedef union word8x4_u word8x4;
28
29 #include "ao_aes_tables.h"
30
31 #define MAXBC           (256/32)
32 #define MAXKC           (256/32)
33 #define MAXROUNDS       14
34 #define MAXRK           ((MAXROUNDS+1)*MAXBC)
35
36 typedef struct {
37   int BC;
38   int KC;
39   int ROUNDS;
40   int shift[2][4];
41   word32 rk[MAXRK];
42 } roundkey;
43
44 /* keys and blocks are externally treated as word32 arrays, to
45    make sure they are aligned on 4-byte boundaries on architectures
46    that require it. */
47
48 /* make a roundkey rkk from key. key must have appropriate size given
49    by keyBits. keyBits and blockBits may only be 128, 196, or
50    256. Returns non-zero if arguments are invalid. */
51
52 int xrijndaelKeySched(word32 key[], int keyBits, int blockBits,
53                       roundkey *rkk);
54
55 /* encrypt, resp. decrypt, block using rijndael roundkey rkk. rkk must
56    have been created with xrijndaelKeySched. Size of block, in bits,
57    must be equal to blockBits parameter that was used to make rkk. In
58    all other cases, behavior is undefined - for reasons of speed, no
59    check for error conditions is done. */
60
61 void xrijndaelEncrypt(word32 block[], roundkey *rkk);
62 void xrijndaelDecrypt(word32 block[], roundkey *rkk);
63
64 #endif                          /* __RIJNDAEL_H */