]>
Commit | Line | Data |
---|---|---|
91447636 A |
1 | /*\r |
2 | ---------------------------------------------------------------------------\r | |
3 | Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.\r | |
4 | \r | |
5 | LICENSE TERMS\r | |
6 | \r | |
7 | The free distribution and use of this software in both source and binary\r | |
8 | form is allowed (with or without changes) provided that:\r | |
9 | \r | |
10 | 1. distributions of this source code include the above copyright\r | |
11 | notice, this list of conditions and the following disclaimer;\r | |
12 | \r | |
13 | 2. distributions in binary form include the above copyright\r | |
14 | notice, this list of conditions and the following disclaimer\r | |
15 | in the documentation and/or other associated materials;\r | |
16 | \r | |
17 | 3. the copyright holder's name is not used to endorse products\r | |
18 | built using this software without specific written permission.\r | |
19 | \r | |
20 | ALTERNATIVELY, provided that this notice is retained in full, this product\r | |
21 | may be distributed under the terms of the GNU General Public License (GPL),\r | |
22 | in which case the provisions of the GPL apply INSTEAD OF those given above.\r | |
23 | \r | |
24 | DISCLAIMER\r | |
25 | \r | |
26 | This software is provided 'as is' with no explicit or implied warranties\r | |
27 | in respect of its properties, including, but not limited to, correctness\r | |
28 | and/or fitness for purpose.\r | |
29 | ---------------------------------------------------------------------------\r | |
30 | Issue 28/01/2004\r | |
31 | \r | |
32 | This file contains the code for declaring the tables needed to implement\r | |
33 | AES. The file aesopt.h is assumed to be included before this header file.\r | |
34 | If there are no global variables, the definitions here can be used to put\r | |
35 | the AES tables in a structure so that a pointer can then be added to the\r | |
36 | AES context to pass them to the AES routines that need them. If this\r | |
37 | facility is used, the calling program has to ensure that this pointer is\r | |
38 | managed appropriately. In particular, the value of the t_dec(in,it) item\r | |
39 | in the table structure must be set to zero in order to ensure that the\r | |
40 | tables are initialised. In practice the three code sequences in aeskey.c\r | |
41 | that control the calls to gen_tabs() and the gen_tabs() routine itself will\r | |
42 | have to be changed for a specific implementation. If global variables are\r | |
43 | available it will generally be preferable to use them with the precomputed\r | |
44 | FIXED_TABLES option that uses static global tables.\r | |
45 | \r | |
46 | The following defines can be used to control the way the tables\r | |
47 | are defined, initialised and used in embedded environments that\r | |
48 | require special features for these purposes\r | |
49 | \r | |
50 | the 't_dec' construction is used to declare fixed table arrays\r | |
51 | the 't_set' construction is used to set fixed table values\r | |
52 | the 't_use' construction is used to access fixed table values\r | |
53 | \r | |
54 | 256 byte tables:\r | |
55 | \r | |
56 | t_xxx(s,box) => forward S box\r | |
57 | t_xxx(i,box) => inverse S box\r | |
58 | \r | |
59 | 256 32-bit word OR 4 x 256 32-bit word tables:\r | |
60 | \r | |
61 | t_xxx(f,n) => forward normal round\r | |
62 | t_xxx(f,l) => forward last round\r | |
63 | t_xxx(i,n) => inverse normal round\r | |
64 | t_xxx(i,l) => inverse last round\r | |
65 | t_xxx(l,s) => key schedule table\r | |
66 | t_xxx(i,m) => key schedule table\r | |
67 | \r | |
68 | Other variables and tables:\r | |
69 | \r | |
70 | t_xxx(r,c) => the rcon table\r | |
71 | */\r | |
72 | \r | |
73 | #if !defined( _AESTAB_H )\r | |
74 | #define _AESTAB_H\r | |
75 | \r | |
76 | #define t_dec(m,n) t_##m##n\r | |
77 | #define t_set(m,n) t_##m##n\r | |
78 | #define t_use(m,n) t_##m##n\r | |
79 | \r | |
80 | #if defined(FIXED_TABLES)\r | |
81 | #define Const const\r | |
82 | #else\r | |
83 | #define Const\r | |
84 | #endif\r | |
85 | \r | |
86 | #if defined(DO_TABLES)\r | |
87 | #define Extern\r | |
88 | #else\r | |
89 | #define Extern extern\r | |
90 | #endif\r | |
91 | \r | |
92 | #if defined(_MSC_VER) && defined(TABLE_ALIGN)\r | |
93 | #define Align __declspec(align(TABLE_ALIGN))\r | |
94 | #else\r | |
95 | #define Align\r | |
96 | #endif\r | |
97 | \r | |
98 | #if defined(__cplusplus)\r | |
99 | extern "C"\r | |
100 | {\r | |
101 | #endif\r | |
102 | \r | |
103 | #if defined(DO_TABLES) && defined(FIXED_TABLES)\r | |
104 | #define d_1(t,n,b,e) Align Const t n[256] = b(e)\r | |
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) }\r | |
106 | Extern Align Const aes_32t t_dec(r,c)[RC_LENGTH] = rc_data(w0);\r | |
107 | #else\r | |
108 | #define d_1(t,n,b,e) Extern Align Const t n[256]\r | |
109 | #define d_4(t,n,b,e,f,g,h) Extern Align Const t n[4][256]\r | |
110 | Extern Align Const aes_32t t_dec(r,c)[RC_LENGTH];\r | |
111 | #endif\r | |
112 | \r | |
113 | #if defined( SBX_SET )\r | |
114 | d_1(aes_08t, t_dec(s,box), sb_data, h0);\r | |
115 | #endif\r | |
116 | #if defined( ISB_SET )\r | |
117 | d_1(aes_08t, t_dec(i,box), isb_data, h0);\r | |
118 | #endif\r | |
119 | \r | |
120 | #if defined( FT1_SET )\r | |
121 | d_1(aes_32t, t_dec(f,n), sb_data, u0);\r | |
122 | #endif\r | |
123 | #if defined( FT4_SET )\r | |
124 | d_4(aes_32t, t_dec(f,n), sb_data, u0, u1, u2, u3);\r | |
125 | #endif\r | |
126 | \r | |
127 | #if defined( FL1_SET )\r | |
128 | d_1(aes_32t, t_dec(f,l), sb_data, w0);\r | |
129 | #endif\r | |
130 | #if defined( FL4_SET )\r | |
131 | d_4(aes_32t, t_dec(f,l), sb_data, w0, w1, w2, w3);\r | |
132 | #endif\r | |
133 | \r | |
134 | #if defined( IT1_SET )\r | |
135 | d_1(aes_32t, t_dec(i,n), isb_data, v0);\r | |
136 | #endif\r | |
137 | #if defined( IT4_SET )\r | |
138 | d_4(aes_32t, t_dec(i,n), isb_data, v0, v1, v2, v3);\r | |
139 | #endif\r | |
140 | \r | |
141 | #if defined( IL1_SET )\r | |
142 | d_1(aes_32t, t_dec(i,l), isb_data, w0);\r | |
143 | #endif\r | |
144 | #if defined( IL4_SET )\r | |
145 | d_4(aes_32t, t_dec(i,l), isb_data, w0, w1, w2, w3);\r | |
146 | #endif\r | |
147 | \r | |
148 | #if defined( LS1_SET )\r | |
149 | #if defined( FL1_SET )\r | |
150 | #undef LS1_SET\r | |
151 | #else\r | |
152 | d_1(aes_32t, t_dec(l,s), sb_data, w0);\r | |
153 | #endif\r | |
154 | #endif\r | |
155 | \r | |
156 | #if defined( LS4_SET )\r | |
157 | #if defined( FL4_SET )\r | |
158 | #undef LS4_SET\r | |
159 | #else\r | |
160 | d_4(aes_32t, t_dec(l,s), sb_data, w0, w1, w2, w3);\r | |
161 | #endif\r | |
162 | #endif\r | |
163 | \r | |
164 | #if defined( IM1_SET )\r | |
165 | d_1(aes_32t, t_dec(i,m), mm_data, v0);\r | |
166 | #endif\r | |
167 | #if defined( IM4_SET )\r | |
168 | d_4(aes_32t, t_dec(i,m), mm_data, v0, v1, v2, v3);\r | |
169 | #endif\r | |
170 | \r | |
171 | #if defined(__cplusplus)\r | |
172 | }\r | |
173 | #endif\r | |
174 | \r | |
175 | #endif\r |