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