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