Path: blob/main/sys/contrib/openzfs/module/icp/asm-x86_64/aes/aestab.h
48775 views
// SPDX-License-Identifier: Brian-Gladman-3-Clause1/*2* ---------------------------------------------------------------------------3* Copyright (c) 1998-2007, Brian Gladman, Worcester, UK. All rights reserved.4*5* LICENSE TERMS6*7* The free distribution and use of this software is allowed (with or without8* changes) provided that:9*10* 1. source code distributions include the above copyright notice, this11* list of conditions and the following disclaimer;12*13* 2. binary distributions include the above copyright notice, this list14* of conditions and the following disclaimer in their documentation;15*16* 3. the name of the copyright holder is not used to endorse products17* built using this software without specific written permission.18*19* DISCLAIMER20*21* This software is provided 'as is' with no explicit or implied warranties22* in respect of its properties, including, but not limited to, correctness23* and/or fitness for purpose.24* ---------------------------------------------------------------------------25* Issue Date: 20/12/200726*27* This file contains the code for declaring the tables needed to implement28* 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 put30* the AES tables in a structure so that a pointer can then be added to the31* AES context to pass them to the AES routines that need them. If this32* facility is used, the calling program has to ensure that this pointer is33* managed appropriately. In particular, the value of the t_dec(in, it) item34* in the table structure must be set to zero in order to ensure that the35* tables are initialised. In practice the three code sequences in aeskey.c36* that control the calls to aes_init() and the aes_init() routine itself will37* have to be changed for a specific implementation. If global variables are38* available it will generally be preferable to use them with the precomputed39* FIXED_TABLES option that uses static global tables.40*41* The following defines can be used to control the way the tables42* are defined, initialised and used in embedded environments that43* require special features for these purposes44*45* the 't_dec' construction is used to declare fixed table arrays46* the 't_set' construction is used to set fixed table values47* the 't_use' construction is used to access fixed table values48*49* 256 byte tables:50*51* t_xxx(s, box) => forward S box52* t_xxx(i, box) => inverse S box53*54* 256 32-bit word OR 4 x 256 32-bit word tables:55*56* t_xxx(f, n) => forward normal round57* t_xxx(f, l) => forward last round58* t_xxx(i, n) => inverse normal round59* t_xxx(i, l) => inverse last round60* t_xxx(l, s) => key schedule table61* t_xxx(i, m) => key schedule table62*63* Other variables and tables:64*65* t_xxx(r, c) => the rcon table66*/6768/*69* OpenSolaris OS modifications70*71* 1. Added __cplusplus and _AESTAB_H header guards72* 2. Added header file sys/types.h73* 3. Remove code defined for _MSC_VER74* 4. Changed all variables to "static const"75* 5. Changed uint_8t and uint_32t to uint8_t and uint32_t76* 6. Cstyled and hdrchk code77*/7879#ifndef _AESTAB_H80#define _AESTAB_H8182#ifdef __cplusplus83extern "C" {84#endif8586#include <sys/types.h>8788#define t_dec(m, n) t_##m##n89#define t_set(m, n) t_##m##n90#define t_use(m, n) t_##m##n9192#if defined(DO_TABLES) && defined(FIXED_TABLES)93#define d_1(t, n, b, e) static const t n[256] = b(e)94#define d_4(t, n, b, e, f, g, h) static const t n[4][256] = \95{b(e), b(f), b(g), b(h)}96static const uint32_t t_dec(r, c)[RC_LENGTH] = rc_data(w0);97#else98#define d_1(t, n, b, e) static const t n[256]99#define d_4(t, n, b, e, f, g, h) static const t n[4][256]100static const uint32_t t_dec(r, c)[RC_LENGTH];101#endif102103#if defined(SBX_SET)104d_1(uint8_t, t_dec(s, box), sb_data, h0);105#endif106#if defined(ISB_SET)107d_1(uint8_t, t_dec(i, box), isb_data, h0);108#endif109110#if defined(FT1_SET)111d_1(uint32_t, t_dec(f, n), sb_data, u0);112#endif113#if defined(FT4_SET)114d_4(uint32_t, t_dec(f, n), sb_data, u0, u1, u2, u3);115#endif116117#if defined(FL1_SET)118d_1(uint32_t, t_dec(f, l), sb_data, w0);119#endif120#if defined(FL4_SET)121d_4(uint32_t, t_dec(f, l), sb_data, w0, w1, w2, w3);122#endif123124#if defined(IT1_SET)125d_1(uint32_t, t_dec(i, n), isb_data, v0);126#endif127#if defined(IT4_SET)128d_4(uint32_t, t_dec(i, n), isb_data, v0, v1, v2, v3);129#endif130131#if defined(IL1_SET)132d_1(uint32_t, t_dec(i, l), isb_data, w0);133#endif134#if defined(IL4_SET)135d_4(uint32_t, t_dec(i, l), isb_data, w0, w1, w2, w3);136#endif137138#if defined(LS1_SET)139#if defined(FL1_SET)140#undef LS1_SET141#else142d_1(uint32_t, t_dec(l, s), sb_data, w0);143#endif144#endif145146#if defined(LS4_SET)147#if defined(FL4_SET)148#undef LS4_SET149#else150d_4(uint32_t, t_dec(l, s), sb_data, w0, w1, w2, w3);151#endif152#endif153154#if defined(IM1_SET)155d_1(uint32_t, t_dec(i, m), mm_data, v0);156#endif157#if defined(IM4_SET)158d_4(uint32_t, t_dec(i, m), mm_data, v0, v1, v2, v3);159#endif160161#ifdef __cplusplus162}163#endif164165#endif /* _AESTAB_H */166167168