OSDN Git Service

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