2 ---------------------------------------------------------------------------
3 Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
7 The free distribution and use of this software in both source and binary
8 form is allowed (with or without changes) provided that:
10 1. distributions of this source code include the above copyright
11 notice, this list of conditions and the following disclaimer;
13 2. distributions in binary form include the above copyright
14 notice, this list of conditions and the following disclaimer
15 in the documentation and/or other associated materials;
17 3. the copyright holder's name is not used to endorse products
18 built using this software without specific written permission.
20 ALTERNATIVELY, provided that this notice is retained in full, this product
21 may be distributed under the terms of the GNU General Public License (GPL),
22 in which case the provisions of the GPL apply INSTEAD OF those given above.
26 This software is provided 'as is' with no explicit or implied warranties
27 in respect of its properties, including, but not limited to, correctness
28 and/or fitness for purpose.
29 ---------------------------------------------------------------------------
32 This file contains the code for declaring the tables needed to implement
33 AES. The file aesopt.h is assumed to be included before this header file.
34 If there are no global variables, the definitions here can be used to put
35 the AES tables in a structure so that a pointer can then be added to the
36 AES context to pass them to the AES routines that need them. If this
37 facility is used, the calling program has to ensure that this pointer is
38 managed appropriately. In particular, the value of the t_dec(in,it) item
39 in the table structure must be set to zero in order to ensure that the
40 tables are initialised. In practice the three code sequences in aeskey.c
41 that control the calls to gen_tabs() and the gen_tabs() routine itself will
42 have to be changed for a specific implementation. If global variables are
43 available it will generally be preferable to use them with the precomputed
44 FIXED_TABLES option that uses static global tables.
46 The following defines can be used to control the way the tables
47 are defined, initialised and used in embedded environments that
48 require special features for these purposes
50 the 't_dec' construction is used to declare fixed table arrays
51 the 't_set' construction is used to set fixed table values
52 the 't_use' construction is used to access fixed table values
56 t_xxx(s,box) => forward S box
57 t_xxx(i,box) => inverse S box
59 256 32-bit word OR 4 x 256 32-bit word tables:
61 t_xxx(f,n) => forward normal round
62 t_xxx(f,l) => forward last round
63 t_xxx(i,n) => inverse normal round
64 t_xxx(i,l) => inverse last round
65 t_xxx(l,s) => key schedule table
66 t_xxx(i,m) => key schedule table
68 Other variables and tables:
70 t_xxx(r,c) => the rcon table
73 #if !defined( _AESTAB_H )
76 #define t_dec(m,n) t_##m##n
77 #define t_set(m,n) t_##m##n
78 #define t_use(m,n) t_##m##n
80 #if defined(FIXED_TABLES)
86 #if defined(DO_TABLES)
92 #if defined(_MSC_VER) && defined(TABLE_ALIGN)
93 #define Align __declspec(align(TABLE_ALIGN))
98 #if defined(__cplusplus)
103 #if defined(DO_TABLES) && defined(FIXED_TABLES)
104 #define d_1(t,n,b,e) Align Const t n[256] = b(e)
105 #define d_4(t,n,b,e,f,g,h) Align Const t n[4][256] = { b(e), b(f), b(g), b(h) }
106 Extern Align Const aes_32t
t_dec(r
,c
)[RC_LENGTH
] = rc_data(w0
);
108 #define d_1(t,n,b,e) Extern Align Const t n[256]
109 #define d_4(t,n,b,e,f,g,h) Extern Align Const t n[4][256]
110 Extern Align Const aes_32t
t_dec(r
,c
)[RC_LENGTH
];
113 #if defined( SBX_SET )
114 d_1(aes_08t
, t_dec(s
,box
), sb_data
, h0
);
116 #if defined( ISB_SET )
117 d_1(aes_08t
, t_dec(i
,box
), isb_data
, h0
);
120 #if defined( FT1_SET )
121 d_1(aes_32t
, t_dec(f
,n
), sb_data
, u0
);
123 #if defined( FT4_SET )
124 d_4(aes_32t
, t_dec(f
,n
), sb_data
, u0
, u1
, u2
, u3
);
127 #if defined( FL1_SET )
128 d_1(aes_32t
, t_dec(f
,l
), sb_data
, w0
);
130 #if defined( FL4_SET )
131 d_4(aes_32t
, t_dec(f
,l
), sb_data
, w0
, w1
, w2
, w3
);
134 #if defined( IT1_SET )
135 d_1(aes_32t
, t_dec(i
,n
), isb_data
, v0
);
137 #if defined( IT4_SET )
138 d_4(aes_32t
, t_dec(i
,n
), isb_data
, v0
, v1
, v2
, v3
);
141 #if defined( IL1_SET )
142 d_1(aes_32t
, t_dec(i
,l
), isb_data
, w0
);
144 #if defined( IL4_SET )
145 d_4(aes_32t
, t_dec(i
,l
), isb_data
, w0
, w1
, w2
, w3
);
148 #if defined( LS1_SET )
149 #if defined( FL1_SET )
152 d_1(aes_32t
, t_dec(l
,s
), sb_data
, w0
);
156 #if defined( LS4_SET )
157 #if defined( FL4_SET )
160 d_4(aes_32t
, t_dec(l
,s
), sb_data
, w0
, w1
, w2
, w3
);
164 #if defined( IM1_SET )
165 d_1(aes_32t
, t_dec(i
,m
), mm_data
, v0
);
167 #if defined( IM4_SET )
168 d_4(aes_32t
, t_dec(i
,m
), mm_data
, v0
, v1
, v2
, v3
);
171 #if defined(__cplusplus)