|
|
1.1 root 1: /*
2: ---------------------------------------------------------------------------
1.1.1.3 ! root 3: Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
1.1 root 4:
5: LICENSE TERMS
6:
7: The free distribution and use of this software in both source and binary
8: form is allowed (with or without changes) provided that:
9:
10: 1. distributions of this source code include the above copyright
11: notice, this list of conditions and the following disclaimer;
12:
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;
16:
17: 3. the copyright holder's name is not used to endorse products
18: built using this software without specific written permission.
19:
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.
23:
24: DISCLAIMER
25:
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: ---------------------------------------------------------------------------
1.1.1.3 ! root 30: Issue 09/09/2006
1.1 root 31:
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.
45:
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
49:
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
53:
54: 256 byte tables:
55:
56: t_xxx(s,box) => forward S box
57: t_xxx(i,box) => inverse S box
58:
59: 256 32-bit word OR 4 x 256 32-bit word tables:
60:
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
67:
68: Other variables and tables:
69:
70: t_xxx(r,c) => the rcon table
71: */
72:
73: #if !defined( _AESTAB_H )
74: #define _AESTAB_H
75:
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
79:
80: #if defined(FIXED_TABLES)
1.1.1.3 ! root 81: # if defined( __MSDOS__ ) || defined( __WIN16__ )
! 82: /* make tables far data to avoid using too much DGROUP space (PG) */
! 83: # define CONST const far
! 84: # else
! 85: # define CONST const
! 86: # endif
1.1 root 87: #else
1.1.1.3 ! root 88: # define CONST
1.1 root 89: #endif
90:
91: #if defined(DO_TABLES)
1.1.1.2 root 92: #define EXTERN
1.1 root 93: #else
1.1.1.2 root 94: #define EXTERN extern
1.1 root 95: #endif
96:
97: #if defined(_MSC_VER) && defined(TABLE_ALIGN)
1.1.1.2 root 98: #define ALIGN __declspec(align(TABLE_ALIGN))
1.1 root 99: #else
1.1.1.2 root 100: #define ALIGN
1.1 root 101: #endif
102:
103: #if defined(__cplusplus)
104: extern "C"
105: {
106: #endif
107:
1.1.1.3 ! root 108: #if defined( __WATCOMC__ ) && ( __WATCOMC__ >= 1100 )
! 109: # define XP_DIR __cdecl
! 110: #else
! 111: # define XP_DIR
! 112: #endif
! 113:
1.1 root 114: #if defined(DO_TABLES) && defined(FIXED_TABLES)
1.1.1.3 ! root 115: #define d_1(t,n,b,e) ALIGN CONST XP_DIR t n[256] = b(e)
! 116: #define d_4(t,n,b,e,f,g,h) ALIGN CONST XP_DIR t n[4][256] = { b(e), b(f), b(g), b(h) }
1.1.1.2 root 117: EXTERN ALIGN CONST uint_32t t_dec(r,c)[RC_LENGTH] = rc_data(w0);
118: #else
1.1.1.3 ! root 119: #define d_1(t,n,b,e) EXTERN ALIGN CONST XP_DIR t n[256]
! 120: #define d_4(t,n,b,e,f,g,h) EXTERN ALIGN CONST XP_DIR t n[4][256]
1.1.1.2 root 121: EXTERN ALIGN CONST uint_32t t_dec(r,c)[RC_LENGTH];
1.1 root 122: #endif
123:
124: #if defined( SBX_SET )
1.1.1.2 root 125: d_1(uint_8t, t_dec(s,box), sb_data, h0);
1.1 root 126: #endif
127: #if defined( ISB_SET )
1.1.1.2 root 128: d_1(uint_8t, t_dec(i,box), isb_data, h0);
1.1 root 129: #endif
130:
131: #if defined( FT1_SET )
1.1.1.2 root 132: d_1(uint_32t, t_dec(f,n), sb_data, u0);
1.1 root 133: #endif
134: #if defined( FT4_SET )
1.1.1.2 root 135: d_4(uint_32t, t_dec(f,n), sb_data, u0, u1, u2, u3);
1.1 root 136: #endif
137:
138: #if defined( FL1_SET )
1.1.1.2 root 139: d_1(uint_32t, t_dec(f,l), sb_data, w0);
1.1 root 140: #endif
141: #if defined( FL4_SET )
1.1.1.2 root 142: d_4(uint_32t, t_dec(f,l), sb_data, w0, w1, w2, w3);
1.1 root 143: #endif
144:
145: #if defined( IT1_SET )
1.1.1.2 root 146: d_1(uint_32t, t_dec(i,n), isb_data, v0);
1.1 root 147: #endif
148: #if defined( IT4_SET )
1.1.1.2 root 149: d_4(uint_32t, t_dec(i,n), isb_data, v0, v1, v2, v3);
1.1 root 150: #endif
151:
152: #if defined( IL1_SET )
1.1.1.2 root 153: d_1(uint_32t, t_dec(i,l), isb_data, w0);
1.1 root 154: #endif
155: #if defined( IL4_SET )
1.1.1.2 root 156: d_4(uint_32t, t_dec(i,l), isb_data, w0, w1, w2, w3);
1.1 root 157: #endif
158:
159: #if defined( LS1_SET )
160: #if defined( FL1_SET )
161: #undef LS1_SET
162: #else
1.1.1.2 root 163: d_1(uint_32t, t_dec(l,s), sb_data, w0);
1.1 root 164: #endif
165: #endif
166:
167: #if defined( LS4_SET )
168: #if defined( FL4_SET )
169: #undef LS4_SET
170: #else
1.1.1.2 root 171: d_4(uint_32t, t_dec(l,s), sb_data, w0, w1, w2, w3);
1.1 root 172: #endif
173: #endif
174:
175: #if defined( IM1_SET )
1.1.1.2 root 176: d_1(uint_32t, t_dec(i,m), mm_data, v0);
1.1 root 177: #endif
178: #if defined( IM4_SET )
1.1.1.2 root 179: d_4(uint_32t, t_dec(i,m), mm_data, v0, v1, v2, v3);
1.1 root 180: #endif
181:
182: #if defined(__cplusplus)
183: }
184: #endif
185:
186: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.