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