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