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