Crypto++ 8.9
Free C++ class library of cryptographic schemes
lea.cpp
1// lea.cpp - written and placed in the public domain by Kim Sung Hee and Jeffrey Walton
2// Based on "LEA: A 128-Bit Block Cipher for Fast Encryption on Common
3// Processors" by Deukjo Hong, Jung-Keun Lee, Dong-Chan Kim, Daesung Kwon,
4// Kwon Ho Ryu, and Dong-Geon Lee.
5//
6// This implementation is based on source files found in a zip file at the
7// Korea Internet and Security Agency (https://www.kisa.or.kr/eng/main.jsp).
8// The zip files was downloaded from the Korean language area of the site so we
9// don't have a url or english zip filename to cite. The source filename from
10// the zip is lea_core.c.
11//
12// The LEA team appears to have applied optimizations to functions in lea_core.c.
13// The implementation does not exactly follow the aglorithmic description from
14// the LEA paper.
15
16#include "pch.h"
17#include "config.h"
18
19#include "lea.h"
20#include "misc.h"
21#include "cpu.h"
22
23ANONYMOUS_NAMESPACE_BEGIN
24
25using CryptoPP::word32;
26using CryptoPP::rotlConstant;
27
28ANONYMOUS_NAMESPACE_END
29
30const word32 delta[8][36] = {
31 {0xc3efe9db, 0x87dfd3b7, 0x0fbfa76f, 0x1f7f4ede, 0x3efe9dbc, 0x7dfd3b78, 0xfbfa76f0, 0xf7f4ede1,
32 0xefe9dbc3, 0xdfd3b787, 0xbfa76f0f, 0x7f4ede1f, 0xfe9dbc3e, 0xfd3b787d, 0xfa76f0fb, 0xf4ede1f7,
33 0xe9dbc3ef, 0xd3b787df, 0xa76f0fbf, 0x4ede1f7f, 0x9dbc3efe, 0x3b787dfd, 0x76f0fbfa, 0xede1f7f4,
34 0xdbc3efe9, 0xb787dfd3, 0x6f0fbfa7, 0xde1f7f4e, 0xbc3efe9d, 0x787dfd3b, 0xf0fbfa76, 0xe1f7f4eD,
35 0xc3efe9db, 0x87dfd3b7, 0x0fbfa76f, 0x1f7f4ede},
36 {0x44626b02, 0x88c4d604, 0x1189ac09, 0x23135812, 0x4626b024, 0x8c4d6048, 0x189ac091, 0x31358122,
37 0x626b0244, 0xc4d60488, 0x89ac0911, 0x13581223, 0x26b02446, 0x4d60488c, 0x9ac09118, 0x35812231,
38 0x6b024462, 0xd60488c4, 0xac091189, 0x58122313, 0xb0244626, 0x60488c4d, 0xc091189a, 0x81223135,
39 0x0244626b, 0x0488c4d6, 0x091189ac, 0x12231358, 0x244626b0, 0x488c4d60, 0x91189ac0, 0x22313581,
40 0x44626b02, 0x88c4d604, 0x1189ac09, 0x23135812},
41 {0x79e27c8a, 0xf3c4f914, 0xe789f229, 0xcf13e453, 0x9e27c8a7, 0x3c4f914f, 0x789f229e, 0xf13e453c,
42 0xe27c8a79, 0xc4f914f3, 0x89f229e7, 0x13e453cf, 0x27c8a79e, 0x4f914f3c, 0x9f229e78, 0x3e453cf1,
43 0x7c8a79e2, 0xf914f3c4, 0xf229e789, 0xe453cf13, 0xc8a79e27, 0x914f3c4f, 0x229e789f, 0x453cf13e,
44 0x8a79e27c, 0x14f3c4f9, 0x29e789f2, 0x53cf13e4, 0xa79e27c8, 0x4f3c4f91, 0x9e789f22, 0x3cf13e45,
45 0x79e27c8a, 0xf3c4f914, 0xe789f229, 0xcf13e453},
46 {0x78df30ec, 0xf1be61d8, 0xe37cc3b1, 0xc6f98763, 0x8df30ec7, 0x1be61d8f, 0x37cc3b1e, 0x6f98763c,
47 0xdf30ec78, 0xbe61d8f1, 0x7cc3b1e3, 0xf98763c6, 0xf30ec78d, 0xe61d8f1b, 0xcc3b1e37, 0x98763c6f,
48 0x30ec78df, 0x61d8f1be, 0xc3b1e37c, 0x8763c6f9, 0x0ec78df3, 0x1d8f1be6, 0x3b1e37cc, 0x763c6f98,
49 0xec78df30, 0xd8f1be61, 0xb1e37cc3, 0x63c6f987, 0xc78df30e, 0x8f1be61d, 0x1e37cc3b, 0x3c6f9876,
50 0x78df30ec, 0xf1be61d8, 0xe37cc3b1, 0xc6f98763},
51 {0x715ea49e, 0xe2bd493c, 0xc57a9279, 0x8af524f3, 0x15ea49e7, 0x2bd493ce, 0x57a9279c, 0xaf524f38,
52 0x5ea49e71, 0xbd493ce2, 0x7a9279c5, 0xf524f38a, 0xea49e715, 0xd493ce2b, 0xa9279c57, 0x524f38af,
53 0xa49e715e, 0x493ce2bd, 0x9279c57a, 0x24f38af5, 0x49e715ea, 0x93ce2bd4, 0x279c57a9, 0x4f38af52,
54 0x9e715ea4, 0x3ce2bd49, 0x79c57a92, 0xf38af524, 0xe715ea49, 0xce2bd493, 0x9c57a927, 0x38af524f,
55 0x715ea49e, 0xe2bd493c, 0xc57a9279, 0x8af524f3},
56 {0xc785da0a, 0x8f0bb415, 0x1e17682b, 0x3c2ed056, 0x785da0ac, 0xf0bb4158, 0xe17682b1, 0xc2ed0563,
57 0x85da0ac7, 0x0bb4158f, 0x17682b1e, 0x2ed0563c, 0x5da0ac78, 0xbb4158f0, 0x7682b1e1, 0xed0563c2,
58 0xda0ac785, 0xb4158f0b, 0x682b1e17, 0xd0563c2e, 0xa0ac785d, 0x4158f0bb, 0x82b1e176, 0x0563c2ed,
59 0x0ac785da, 0x158f0bb4, 0x2b1e1768, 0x563c2ed0, 0xac785da0, 0x58f0bb41, 0xb1e17682, 0x63c2ed05,
60 0xc785da0a, 0x8f0bb415, 0x1e17682b, 0x3c2ed056},
61 {0xe04ef22a, 0xc09de455, 0x813bc8ab, 0x02779157, 0x04ef22ae, 0x09de455c, 0x13bc8ab8, 0x27791570,
62 0x4ef22ae0, 0x9de455c0, 0x3bc8ab81, 0x77915702, 0xef22ae04, 0xde455c09, 0xbc8ab813, 0x79157027,
63 0xf22ae04e, 0xe455c09d, 0xc8ab813b, 0x91570277, 0x22ae04ef, 0x455c09de, 0x8ab813bc, 0x15702779,
64 0x2ae04ef2, 0x55c09de4, 0xab813bc8, 0x57027791, 0xae04ef22, 0x5c09de45, 0xb813bc8a, 0x70277915,
65 0xe04ef22a, 0xc09de455, 0x813bc8ab, 0x02779157},
66 {0xe5c40957, 0xcb8812af, 0x9710255f, 0x2e204abf, 0x5c40957e, 0xb8812afc, 0x710255f9, 0xe204abf2,
67 0xc40957e5, 0x8812afcb, 0x10255f97, 0x204abf2e, 0x40957e5c, 0x812afcb8, 0x0255f971, 0x04abf2e2,
68 0x0957e5c4, 0x12afcb88, 0x255f9710, 0x4abf2e20, 0x957e5c40, 0x2afcb881, 0x55f97102, 0xabf2e204,
69 0x57e5c409, 0xafcb8812, 0x5f971025, 0xbf2e204a, 0x7e5c4095, 0xfcb8812a, 0xf9710255, 0xf2e204ab,
70 0xe5c40957, 0xcb8812af, 0x9710255f, 0x2e204abf}
71};
72
73inline void SetKey128(word32 rkey[144], const word32 key[4])
74{
75 rkey[ 0] = rotlConstant<1>( key[ 0] + delta[0][ 0]);
76 rkey[ 6] = rotlConstant<1>(rkey[ 0] + delta[1][ 1]);
77 rkey[ 12] = rotlConstant<1>(rkey[ 6] + delta[2][ 2]);
78 rkey[ 18] = rotlConstant<1>(rkey[ 12] + delta[3][ 3]);
79 rkey[ 24] = rotlConstant<1>(rkey[ 18] + delta[0][ 4]);
80 rkey[ 30] = rotlConstant<1>(rkey[ 24] + delta[1][ 5]);
81 rkey[ 36] = rotlConstant<1>(rkey[ 30] + delta[2][ 6]);
82 rkey[ 42] = rotlConstant<1>(rkey[ 36] + delta[3][ 7]);
83 rkey[ 48] = rotlConstant<1>(rkey[ 42] + delta[0][ 8]);
84 rkey[ 54] = rotlConstant<1>(rkey[ 48] + delta[1][ 9]);
85 rkey[ 60] = rotlConstant<1>(rkey[ 54] + delta[2][10]);
86 rkey[ 66] = rotlConstant<1>(rkey[ 60] + delta[3][11]);
87 rkey[ 72] = rotlConstant<1>(rkey[ 66] + delta[0][12]);
88 rkey[ 78] = rotlConstant<1>(rkey[ 72] + delta[1][13]);
89 rkey[ 84] = rotlConstant<1>(rkey[ 78] + delta[2][14]);
90 rkey[ 90] = rotlConstant<1>(rkey[ 84] + delta[3][15]);
91 rkey[ 96] = rotlConstant<1>(rkey[ 90] + delta[0][16]);
92 rkey[102] = rotlConstant<1>(rkey[ 96] + delta[1][17]);
93 rkey[108] = rotlConstant<1>(rkey[102] + delta[2][18]);
94 rkey[114] = rotlConstant<1>(rkey[108] + delta[3][19]);
95 rkey[120] = rotlConstant<1>(rkey[114] + delta[0][20]);
96 rkey[126] = rotlConstant<1>(rkey[120] + delta[1][21]);
97 rkey[132] = rotlConstant<1>(rkey[126] + delta[2][22]);
98 rkey[138] = rotlConstant<1>(rkey[132] + delta[3][23]);
99
100 rkey[ 1] = rkey[ 3] = rkey[ 5] = rotlConstant<3>( key[ 1] + delta[0][ 1]);
101 rkey[ 7] = rkey[ 9] = rkey[ 11] = rotlConstant<3>(rkey[ 1] + delta[1][ 2]);
102 rkey[ 13] = rkey[ 15] = rkey[ 17] = rotlConstant<3>(rkey[ 7] + delta[2][ 3]);
103 rkey[ 19] = rkey[ 21] = rkey[ 23] = rotlConstant<3>(rkey[ 13] + delta[3][ 4]);
104 rkey[ 25] = rkey[ 27] = rkey[ 29] = rotlConstant<3>(rkey[ 19] + delta[0][ 5]);
105 rkey[ 31] = rkey[ 33] = rkey[ 35] = rotlConstant<3>(rkey[ 25] + delta[1][ 6]);
106 rkey[ 37] = rkey[ 39] = rkey[ 41] = rotlConstant<3>(rkey[ 31] + delta[2][ 7]);
107 rkey[ 43] = rkey[ 45] = rkey[ 47] = rotlConstant<3>(rkey[ 37] + delta[3][ 8]);
108 rkey[ 49] = rkey[ 51] = rkey[ 53] = rotlConstant<3>(rkey[ 43] + delta[0][ 9]);
109 rkey[ 55] = rkey[ 57] = rkey[ 59] = rotlConstant<3>(rkey[ 49] + delta[1][10]);
110 rkey[ 61] = rkey[ 63] = rkey[ 65] = rotlConstant<3>(rkey[ 55] + delta[2][11]);
111 rkey[ 67] = rkey[ 69] = rkey[ 71] = rotlConstant<3>(rkey[ 61] + delta[3][12]);
112 rkey[ 73] = rkey[ 75] = rkey[ 77] = rotlConstant<3>(rkey[ 67] + delta[0][13]);
113 rkey[ 79] = rkey[ 81] = rkey[ 83] = rotlConstant<3>(rkey[ 73] + delta[1][14]);
114 rkey[ 85] = rkey[ 87] = rkey[ 89] = rotlConstant<3>(rkey[ 79] + delta[2][15]);
115 rkey[ 91] = rkey[ 93] = rkey[ 95] = rotlConstant<3>(rkey[ 85] + delta[3][16]);
116 rkey[ 97] = rkey[ 99] = rkey[101] = rotlConstant<3>(rkey[ 91] + delta[0][17]);
117 rkey[103] = rkey[105] = rkey[107] = rotlConstant<3>(rkey[ 97] + delta[1][18]);
118 rkey[109] = rkey[111] = rkey[113] = rotlConstant<3>(rkey[103] + delta[2][19]);
119 rkey[115] = rkey[117] = rkey[119] = rotlConstant<3>(rkey[109] + delta[3][20]);
120 rkey[121] = rkey[123] = rkey[125] = rotlConstant<3>(rkey[115] + delta[0][21]);
121 rkey[127] = rkey[129] = rkey[131] = rotlConstant<3>(rkey[121] + delta[1][22]);
122 rkey[133] = rkey[135] = rkey[137] = rotlConstant<3>(rkey[127] + delta[2][23]);
123 rkey[139] = rkey[141] = rkey[143] = rotlConstant<3>(rkey[133] + delta[3][24]);
124
125 rkey[ 2] = rotlConstant<6>( key[ 2] + delta[0][ 2]);
126 rkey[ 8] = rotlConstant<6>(rkey[ 2] + delta[1][ 3]);
127 rkey[ 14] = rotlConstant<6>(rkey[ 8] + delta[2][ 4]);
128 rkey[ 20] = rotlConstant<6>(rkey[ 14] + delta[3][ 5]);
129 rkey[ 26] = rotlConstant<6>(rkey[ 20] + delta[0][ 6]);
130 rkey[ 32] = rotlConstant<6>(rkey[ 26] + delta[1][ 7]);
131 rkey[ 38] = rotlConstant<6>(rkey[ 32] + delta[2][ 8]);
132 rkey[ 44] = rotlConstant<6>(rkey[ 38] + delta[3][ 9]);
133 rkey[ 50] = rotlConstant<6>(rkey[ 44] + delta[0][10]);
134 rkey[ 56] = rotlConstant<6>(rkey[ 50] + delta[1][11]);
135 rkey[ 62] = rotlConstant<6>(rkey[ 56] + delta[2][12]);
136 rkey[ 68] = rotlConstant<6>(rkey[ 62] + delta[3][13]);
137 rkey[ 74] = rotlConstant<6>(rkey[ 68] + delta[0][14]);
138 rkey[ 80] = rotlConstant<6>(rkey[ 74] + delta[1][15]);
139 rkey[ 86] = rotlConstant<6>(rkey[ 80] + delta[2][16]);
140 rkey[ 92] = rotlConstant<6>(rkey[ 86] + delta[3][17]);
141 rkey[ 98] = rotlConstant<6>(rkey[ 92] + delta[0][18]);
142 rkey[104] = rotlConstant<6>(rkey[ 98] + delta[1][19]);
143 rkey[110] = rotlConstant<6>(rkey[104] + delta[2][20]);
144 rkey[116] = rotlConstant<6>(rkey[110] + delta[3][21]);
145 rkey[122] = rotlConstant<6>(rkey[116] + delta[0][22]);
146 rkey[128] = rotlConstant<6>(rkey[122] + delta[1][23]);
147 rkey[134] = rotlConstant<6>(rkey[128] + delta[2][24]);
148 rkey[140] = rotlConstant<6>(rkey[134] + delta[3][25]);
149
150 rkey[ 4] = rotlConstant<11>( key[ 3] + delta[0][ 3]);
151 rkey[ 10] = rotlConstant<11>(rkey[ 4] + delta[1][ 4]);
152 rkey[ 16] = rotlConstant<11>(rkey[ 10] + delta[2][ 5]);
153 rkey[ 22] = rotlConstant<11>(rkey[ 16] + delta[3][ 6]);
154 rkey[ 28] = rotlConstant<11>(rkey[ 22] + delta[0][ 7]);
155 rkey[ 34] = rotlConstant<11>(rkey[ 28] + delta[1][ 8]);
156 rkey[ 40] = rotlConstant<11>(rkey[ 34] + delta[2][ 9]);
157 rkey[ 46] = rotlConstant<11>(rkey[ 40] + delta[3][10]);
158 rkey[ 52] = rotlConstant<11>(rkey[ 46] + delta[0][11]);
159 rkey[ 58] = rotlConstant<11>(rkey[ 52] + delta[1][12]);
160 rkey[ 64] = rotlConstant<11>(rkey[ 58] + delta[2][13]);
161 rkey[ 70] = rotlConstant<11>(rkey[ 64] + delta[3][14]);
162 rkey[ 76] = rotlConstant<11>(rkey[ 70] + delta[0][15]);
163 rkey[ 82] = rotlConstant<11>(rkey[ 76] + delta[1][16]);
164 rkey[ 88] = rotlConstant<11>(rkey[ 82] + delta[2][17]);
165 rkey[ 94] = rotlConstant<11>(rkey[ 88] + delta[3][18]);
166 rkey[100] = rotlConstant<11>(rkey[ 94] + delta[0][19]);
167 rkey[106] = rotlConstant<11>(rkey[100] + delta[1][20]);
168 rkey[112] = rotlConstant<11>(rkey[106] + delta[2][21]);
169 rkey[118] = rotlConstant<11>(rkey[112] + delta[3][22]);
170 rkey[124] = rotlConstant<11>(rkey[118] + delta[0][23]);
171 rkey[130] = rotlConstant<11>(rkey[124] + delta[1][24]);
172 rkey[136] = rotlConstant<11>(rkey[130] + delta[2][25]);
173 rkey[142] = rotlConstant<11>(rkey[136] + delta[3][26]);
174}
175
176inline void SetKey192(word32 rkey[168], const word32 key[6])
177{
178 rkey[ 0] = rotlConstant<1>( key[ 0] + delta[0][ 0]);
179 rkey[ 6] = rotlConstant<1>(rkey[ 0] + delta[1][ 1]);
180 rkey[ 12] = rotlConstant<1>(rkey[ 6] + delta[2][ 2]);
181 rkey[ 18] = rotlConstant<1>(rkey[ 12] + delta[3][ 3]);
182 rkey[ 24] = rotlConstant<1>(rkey[ 18] + delta[4][ 4]);
183 rkey[ 30] = rotlConstant<1>(rkey[ 24] + delta[5][ 5]);
184 rkey[ 36] = rotlConstant<1>(rkey[ 30] + delta[0][ 6]);
185 rkey[ 42] = rotlConstant<1>(rkey[ 36] + delta[1][ 7]);
186 rkey[ 48] = rotlConstant<1>(rkey[ 42] + delta[2][ 8]);
187 rkey[ 54] = rotlConstant<1>(rkey[ 48] + delta[3][ 9]);
188 rkey[ 60] = rotlConstant<1>(rkey[ 54] + delta[4][10]);
189 rkey[ 66] = rotlConstant<1>(rkey[ 60] + delta[5][11]);
190 rkey[ 72] = rotlConstant<1>(rkey[ 66] + delta[0][12]);
191 rkey[ 78] = rotlConstant<1>(rkey[ 72] + delta[1][13]);
192 rkey[ 84] = rotlConstant<1>(rkey[ 78] + delta[2][14]);
193 rkey[ 90] = rotlConstant<1>(rkey[ 84] + delta[3][15]);
194 rkey[ 96] = rotlConstant<1>(rkey[ 90] + delta[4][16]);
195 rkey[102] = rotlConstant<1>(rkey[ 96] + delta[5][17]);
196 rkey[108] = rotlConstant<1>(rkey[102] + delta[0][18]);
197 rkey[114] = rotlConstant<1>(rkey[108] + delta[1][19]);
198 rkey[120] = rotlConstant<1>(rkey[114] + delta[2][20]);
199 rkey[126] = rotlConstant<1>(rkey[120] + delta[3][21]);
200 rkey[132] = rotlConstant<1>(rkey[126] + delta[4][22]);
201 rkey[138] = rotlConstant<1>(rkey[132] + delta[5][23]);
202 rkey[144] = rotlConstant<1>(rkey[138] + delta[0][24]);
203 rkey[150] = rotlConstant<1>(rkey[144] + delta[1][25]);
204 rkey[156] = rotlConstant<1>(rkey[150] + delta[2][26]);
205 rkey[162] = rotlConstant<1>(rkey[156] + delta[3][27]);
206
207 rkey[ 1] = rotlConstant<3>( key[ 1] + delta[0][ 1]);
208 rkey[ 7] = rotlConstant<3>(rkey[ 1] + delta[1][ 2]);
209 rkey[ 13] = rotlConstant<3>(rkey[ 7] + delta[2][ 3]);
210 rkey[ 19] = rotlConstant<3>(rkey[ 13] + delta[3][ 4]);
211 rkey[ 25] = rotlConstant<3>(rkey[ 19] + delta[4][ 5]);
212 rkey[ 31] = rotlConstant<3>(rkey[ 25] + delta[5][ 6]);
213 rkey[ 37] = rotlConstant<3>(rkey[ 31] + delta[0][ 7]);
214 rkey[ 43] = rotlConstant<3>(rkey[ 37] + delta[1][ 8]);
215 rkey[ 49] = rotlConstant<3>(rkey[ 43] + delta[2][ 9]);
216 rkey[ 55] = rotlConstant<3>(rkey[ 49] + delta[3][10]);
217 rkey[ 61] = rotlConstant<3>(rkey[ 55] + delta[4][11]);
218 rkey[ 67] = rotlConstant<3>(rkey[ 61] + delta[5][12]);
219 rkey[ 73] = rotlConstant<3>(rkey[ 67] + delta[0][13]);
220 rkey[ 79] = rotlConstant<3>(rkey[ 73] + delta[1][14]);
221 rkey[ 85] = rotlConstant<3>(rkey[ 79] + delta[2][15]);
222 rkey[ 91] = rotlConstant<3>(rkey[ 85] + delta[3][16]);
223 rkey[ 97] = rotlConstant<3>(rkey[ 91] + delta[4][17]);
224 rkey[103] = rotlConstant<3>(rkey[ 97] + delta[5][18]);
225 rkey[109] = rotlConstant<3>(rkey[103] + delta[0][19]);
226 rkey[115] = rotlConstant<3>(rkey[109] + delta[1][20]);
227 rkey[121] = rotlConstant<3>(rkey[115] + delta[2][21]);
228 rkey[127] = rotlConstant<3>(rkey[121] + delta[3][22]);
229 rkey[133] = rotlConstant<3>(rkey[127] + delta[4][23]);
230 rkey[139] = rotlConstant<3>(rkey[133] + delta[5][24]);
231 rkey[145] = rotlConstant<3>(rkey[139] + delta[0][25]);
232 rkey[151] = rotlConstant<3>(rkey[145] + delta[1][26]);
233 rkey[157] = rotlConstant<3>(rkey[151] + delta[2][27]);
234 rkey[163] = rotlConstant<3>(rkey[157] + delta[3][28]);
235
236 rkey[ 2] = rotlConstant<6>( key[ 2] + delta[0][ 2]);
237 rkey[ 8] = rotlConstant<6>(rkey[ 2] + delta[1][ 3]);
238 rkey[ 14] = rotlConstant<6>(rkey[ 8] + delta[2][ 4]);
239 rkey[ 20] = rotlConstant<6>(rkey[ 14] + delta[3][ 5]);
240 rkey[ 26] = rotlConstant<6>(rkey[ 20] + delta[4][ 6]);
241 rkey[ 32] = rotlConstant<6>(rkey[ 26] + delta[5][ 7]);
242 rkey[ 38] = rotlConstant<6>(rkey[ 32] + delta[0][ 8]);
243 rkey[ 44] = rotlConstant<6>(rkey[ 38] + delta[1][ 9]);
244 rkey[ 50] = rotlConstant<6>(rkey[ 44] + delta[2][10]);
245 rkey[ 56] = rotlConstant<6>(rkey[ 50] + delta[3][11]);
246 rkey[ 62] = rotlConstant<6>(rkey[ 56] + delta[4][12]);
247 rkey[ 68] = rotlConstant<6>(rkey[ 62] + delta[5][13]);
248 rkey[ 74] = rotlConstant<6>(rkey[ 68] + delta[0][14]);
249 rkey[ 80] = rotlConstant<6>(rkey[ 74] + delta[1][15]);
250 rkey[ 86] = rotlConstant<6>(rkey[ 80] + delta[2][16]);
251 rkey[ 92] = rotlConstant<6>(rkey[ 86] + delta[3][17]);
252 rkey[ 98] = rotlConstant<6>(rkey[ 92] + delta[4][18]);
253 rkey[104] = rotlConstant<6>(rkey[ 98] + delta[5][19]);
254 rkey[110] = rotlConstant<6>(rkey[104] + delta[0][20]);
255 rkey[116] = rotlConstant<6>(rkey[110] + delta[1][21]);
256 rkey[122] = rotlConstant<6>(rkey[116] + delta[2][22]);
257 rkey[128] = rotlConstant<6>(rkey[122] + delta[3][23]);
258 rkey[134] = rotlConstant<6>(rkey[128] + delta[4][24]);
259 rkey[140] = rotlConstant<6>(rkey[134] + delta[5][25]);
260 rkey[146] = rotlConstant<6>(rkey[140] + delta[0][26]);
261 rkey[152] = rotlConstant<6>(rkey[146] + delta[1][27]);
262 rkey[158] = rotlConstant<6>(rkey[152] + delta[2][28]);
263 rkey[164] = rotlConstant<6>(rkey[158] + delta[3][29]);
264
265 rkey[ 3] = rotlConstant<11>( key[ 3] + delta[0][ 3]);
266 rkey[ 9] = rotlConstant<11>(rkey[ 3] + delta[1][ 4]);
267 rkey[ 15] = rotlConstant<11>(rkey[ 9] + delta[2][ 5]);
268 rkey[ 21] = rotlConstant<11>(rkey[ 15] + delta[3][ 6]);
269 rkey[ 27] = rotlConstant<11>(rkey[ 21] + delta[4][ 7]);
270 rkey[ 33] = rotlConstant<11>(rkey[ 27] + delta[5][ 8]);
271 rkey[ 39] = rotlConstant<11>(rkey[ 33] + delta[0][ 9]);
272 rkey[ 45] = rotlConstant<11>(rkey[ 39] + delta[1][10]);
273 rkey[ 51] = rotlConstant<11>(rkey[ 45] + delta[2][11]);
274 rkey[ 57] = rotlConstant<11>(rkey[ 51] + delta[3][12]);
275 rkey[ 63] = rotlConstant<11>(rkey[ 57] + delta[4][13]);
276 rkey[ 69] = rotlConstant<11>(rkey[ 63] + delta[5][14]);
277 rkey[ 75] = rotlConstant<11>(rkey[ 69] + delta[0][15]);
278 rkey[ 81] = rotlConstant<11>(rkey[ 75] + delta[1][16]);
279 rkey[ 87] = rotlConstant<11>(rkey[ 81] + delta[2][17]);
280 rkey[ 93] = rotlConstant<11>(rkey[ 87] + delta[3][18]);
281 rkey[ 99] = rotlConstant<11>(rkey[ 93] + delta[4][19]);
282 rkey[105] = rotlConstant<11>(rkey[ 99] + delta[5][20]);
283 rkey[111] = rotlConstant<11>(rkey[105] + delta[0][21]);
284 rkey[117] = rotlConstant<11>(rkey[111] + delta[1][22]);
285 rkey[123] = rotlConstant<11>(rkey[117] + delta[2][23]);
286 rkey[129] = rotlConstant<11>(rkey[123] + delta[3][24]);
287 rkey[135] = rotlConstant<11>(rkey[129] + delta[4][25]);
288 rkey[141] = rotlConstant<11>(rkey[135] + delta[5][26]);
289 rkey[147] = rotlConstant<11>(rkey[141] + delta[0][27]);
290 rkey[153] = rotlConstant<11>(rkey[147] + delta[1][28]);
291 rkey[159] = rotlConstant<11>(rkey[153] + delta[2][29]);
292 rkey[165] = rotlConstant<11>(rkey[159] + delta[3][30]);
293
294 rkey[ 4] = rotlConstant<13>( key[ 4] + delta[0][ 4]);
295 rkey[ 10] = rotlConstant<13>(rkey[ 4] + delta[1][ 5]);
296 rkey[ 16] = rotlConstant<13>(rkey[ 10] + delta[2][ 6]);
297 rkey[ 22] = rotlConstant<13>(rkey[ 16] + delta[3][ 7]);
298 rkey[ 28] = rotlConstant<13>(rkey[ 22] + delta[4][ 8]);
299 rkey[ 34] = rotlConstant<13>(rkey[ 28] + delta[5][ 9]);
300 rkey[ 40] = rotlConstant<13>(rkey[ 34] + delta[0][10]);
301 rkey[ 46] = rotlConstant<13>(rkey[ 40] + delta[1][11]);
302 rkey[ 52] = rotlConstant<13>(rkey[ 46] + delta[2][12]);
303 rkey[ 58] = rotlConstant<13>(rkey[ 52] + delta[3][13]);
304 rkey[ 64] = rotlConstant<13>(rkey[ 58] + delta[4][14]);
305 rkey[ 70] = rotlConstant<13>(rkey[ 64] + delta[5][15]);
306 rkey[ 76] = rotlConstant<13>(rkey[ 70] + delta[0][16]);
307 rkey[ 82] = rotlConstant<13>(rkey[ 76] + delta[1][17]);
308 rkey[ 88] = rotlConstant<13>(rkey[ 82] + delta[2][18]);
309 rkey[ 94] = rotlConstant<13>(rkey[ 88] + delta[3][19]);
310 rkey[100] = rotlConstant<13>(rkey[ 94] + delta[4][20]);
311 rkey[106] = rotlConstant<13>(rkey[100] + delta[5][21]);
312 rkey[112] = rotlConstant<13>(rkey[106] + delta[0][22]);
313 rkey[118] = rotlConstant<13>(rkey[112] + delta[1][23]);
314 rkey[124] = rotlConstant<13>(rkey[118] + delta[2][24]);
315 rkey[130] = rotlConstant<13>(rkey[124] + delta[3][25]);
316 rkey[136] = rotlConstant<13>(rkey[130] + delta[4][26]);
317 rkey[142] = rotlConstant<13>(rkey[136] + delta[5][27]);
318 rkey[148] = rotlConstant<13>(rkey[142] + delta[0][28]);
319 rkey[154] = rotlConstant<13>(rkey[148] + delta[1][29]);
320 rkey[160] = rotlConstant<13>(rkey[154] + delta[2][30]);
321 rkey[166] = rotlConstant<13>(rkey[160] + delta[3][31]);
322
323 rkey[ 5] = rotlConstant<17>( key[ 5] + delta[0][ 5]);
324 rkey[ 11] = rotlConstant<17>(rkey[ 5] + delta[1][ 6]);
325 rkey[ 17] = rotlConstant<17>(rkey[ 11] + delta[2][ 7]);
326 rkey[ 23] = rotlConstant<17>(rkey[ 17] + delta[3][ 8]);
327 rkey[ 29] = rotlConstant<17>(rkey[ 23] + delta[4][ 9]);
328 rkey[ 35] = rotlConstant<17>(rkey[ 29] + delta[5][10]);
329 rkey[ 41] = rotlConstant<17>(rkey[ 35] + delta[0][11]);
330 rkey[ 47] = rotlConstant<17>(rkey[ 41] + delta[1][12]);
331 rkey[ 53] = rotlConstant<17>(rkey[ 47] + delta[2][13]);
332 rkey[ 59] = rotlConstant<17>(rkey[ 53] + delta[3][14]);
333 rkey[ 65] = rotlConstant<17>(rkey[ 59] + delta[4][15]);
334 rkey[ 71] = rotlConstant<17>(rkey[ 65] + delta[5][16]);
335 rkey[ 77] = rotlConstant<17>(rkey[ 71] + delta[0][17]);
336 rkey[ 83] = rotlConstant<17>(rkey[ 77] + delta[1][18]);
337 rkey[ 89] = rotlConstant<17>(rkey[ 83] + delta[2][19]);
338 rkey[ 95] = rotlConstant<17>(rkey[ 89] + delta[3][20]);
339 rkey[101] = rotlConstant<17>(rkey[ 95] + delta[4][21]);
340 rkey[107] = rotlConstant<17>(rkey[101] + delta[5][22]);
341 rkey[113] = rotlConstant<17>(rkey[107] + delta[0][23]);
342 rkey[119] = rotlConstant<17>(rkey[113] + delta[1][24]);
343 rkey[125] = rotlConstant<17>(rkey[119] + delta[2][25]);
344 rkey[131] = rotlConstant<17>(rkey[125] + delta[3][26]);
345 rkey[137] = rotlConstant<17>(rkey[131] + delta[4][27]);
346 rkey[143] = rotlConstant<17>(rkey[137] + delta[5][28]);
347 rkey[149] = rotlConstant<17>(rkey[143] + delta[0][29]);
348 rkey[155] = rotlConstant<17>(rkey[149] + delta[1][30]);
349 rkey[161] = rotlConstant<17>(rkey[155] + delta[2][31]);
350 rkey[167] = rotlConstant<17>(rkey[161] + delta[3][ 0]);
351}
352
353inline void SetKey256(word32 rkey[192], const word32 key[8])
354{
355 rkey[ 0] = rotlConstant< 1>( key[ 0] + delta[0][ 0]);
356 rkey[ 8] = rotlConstant< 6>(rkey[ 0] + delta[1][ 3]);
357 rkey[ 16] = rotlConstant<13>(rkey[ 8] + delta[2][ 6]);
358 rkey[ 24] = rotlConstant< 1>(rkey[ 16] + delta[4][ 4]);
359 rkey[ 32] = rotlConstant< 6>(rkey[ 24] + delta[5][ 7]);
360 rkey[ 40] = rotlConstant<13>(rkey[ 32] + delta[6][10]);
361 rkey[ 48] = rotlConstant< 1>(rkey[ 40] + delta[0][ 8]);
362 rkey[ 56] = rotlConstant< 6>(rkey[ 48] + delta[1][11]);
363 rkey[ 64] = rotlConstant<13>(rkey[ 56] + delta[2][14]);
364 rkey[ 72] = rotlConstant< 1>(rkey[ 64] + delta[4][12]);
365 rkey[ 80] = rotlConstant< 6>(rkey[ 72] + delta[5][15]);
366 rkey[ 88] = rotlConstant<13>(rkey[ 80] + delta[6][18]);
367 rkey[ 96] = rotlConstant< 1>(rkey[ 88] + delta[0][16]);
368 rkey[104] = rotlConstant< 6>(rkey[ 96] + delta[1][19]);
369 rkey[112] = rotlConstant<13>(rkey[104] + delta[2][22]);
370 rkey[120] = rotlConstant< 1>(rkey[112] + delta[4][20]);
371 rkey[128] = rotlConstant< 6>(rkey[120] + delta[5][23]);
372 rkey[136] = rotlConstant<13>(rkey[128] + delta[6][26]);
373 rkey[144] = rotlConstant< 1>(rkey[136] + delta[0][24]);
374 rkey[152] = rotlConstant< 6>(rkey[144] + delta[1][27]);
375 rkey[160] = rotlConstant<13>(rkey[152] + delta[2][30]);
376 rkey[168] = rotlConstant< 1>(rkey[160] + delta[4][28]);
377 rkey[176] = rotlConstant< 6>(rkey[168] + delta[5][31]);
378 rkey[184] = rotlConstant<13>(rkey[176] + delta[6][ 2]);
379
380 rkey[ 1] = rotlConstant< 3>( key[ 1] + delta[0][ 1]);
381 rkey[ 9] = rotlConstant<11>(rkey[ 1] + delta[1][ 4]);
382 rkey[ 17] = rotlConstant<17>(rkey[ 9] + delta[2][ 7]);
383 rkey[ 25] = rotlConstant< 3>(rkey[ 17] + delta[4][ 5]);
384 rkey[ 33] = rotlConstant<11>(rkey[ 25] + delta[5][ 8]);
385 rkey[ 41] = rotlConstant<17>(rkey[ 33] + delta[6][11]);
386 rkey[ 49] = rotlConstant< 3>(rkey[ 41] + delta[0][ 9]);
387 rkey[ 57] = rotlConstant<11>(rkey[ 49] + delta[1][12]);
388 rkey[ 65] = rotlConstant<17>(rkey[ 57] + delta[2][15]);
389 rkey[ 73] = rotlConstant< 3>(rkey[ 65] + delta[4][13]);
390 rkey[ 81] = rotlConstant<11>(rkey[ 73] + delta[5][16]);
391 rkey[ 89] = rotlConstant<17>(rkey[ 81] + delta[6][19]);
392 rkey[ 97] = rotlConstant< 3>(rkey[ 89] + delta[0][17]);
393 rkey[105] = rotlConstant<11>(rkey[ 97] + delta[1][20]);
394 rkey[113] = rotlConstant<17>(rkey[105] + delta[2][23]);
395 rkey[121] = rotlConstant< 3>(rkey[113] + delta[4][21]);
396 rkey[129] = rotlConstant<11>(rkey[121] + delta[5][24]);
397 rkey[137] = rotlConstant<17>(rkey[129] + delta[6][27]);
398 rkey[145] = rotlConstant< 3>(rkey[137] + delta[0][25]);
399 rkey[153] = rotlConstant<11>(rkey[145] + delta[1][28]);
400 rkey[161] = rotlConstant<17>(rkey[153] + delta[2][31]);
401 rkey[169] = rotlConstant< 3>(rkey[161] + delta[4][29]);
402 rkey[177] = rotlConstant<11>(rkey[169] + delta[5][ 0]);
403 rkey[185] = rotlConstant<17>(rkey[177] + delta[6][ 3]);
404
405 rkey[ 2] = rotlConstant< 6>( key[ 2] + delta[0][ 2]);
406 rkey[ 10] = rotlConstant<13>(rkey[ 2] + delta[1][ 5]);
407 rkey[ 18] = rotlConstant< 1>(rkey[ 10] + delta[3][ 3]);
408 rkey[ 26] = rotlConstant< 6>(rkey[ 18] + delta[4][ 6]);
409 rkey[ 34] = rotlConstant<13>(rkey[ 26] + delta[5][ 9]);
410 rkey[ 42] = rotlConstant< 1>(rkey[ 34] + delta[7][ 7]);
411 rkey[ 50] = rotlConstant< 6>(rkey[ 42] + delta[0][10]);
412 rkey[ 58] = rotlConstant<13>(rkey[ 50] + delta[1][13]);
413 rkey[ 66] = rotlConstant< 1>(rkey[ 58] + delta[3][11]);
414 rkey[ 74] = rotlConstant< 6>(rkey[ 66] + delta[4][14]);
415 rkey[ 82] = rotlConstant<13>(rkey[ 74] + delta[5][17]);
416 rkey[ 90] = rotlConstant< 1>(rkey[ 82] + delta[7][15]);
417 rkey[ 98] = rotlConstant< 6>(rkey[ 90] + delta[0][18]);
418 rkey[106] = rotlConstant<13>(rkey[ 98] + delta[1][21]);
419 rkey[114] = rotlConstant< 1>(rkey[106] + delta[3][19]);
420 rkey[122] = rotlConstant< 6>(rkey[114] + delta[4][22]);
421 rkey[130] = rotlConstant<13>(rkey[122] + delta[5][25]);
422 rkey[138] = rotlConstant< 1>(rkey[130] + delta[7][23]);
423 rkey[146] = rotlConstant< 6>(rkey[138] + delta[0][26]);
424 rkey[154] = rotlConstant<13>(rkey[146] + delta[1][29]);
425 rkey[162] = rotlConstant< 1>(rkey[154] + delta[3][27]);
426 rkey[170] = rotlConstant< 6>(rkey[162] + delta[4][30]);
427 rkey[178] = rotlConstant<13>(rkey[170] + delta[5][ 1]);
428 rkey[186] = rotlConstant< 1>(rkey[178] + delta[7][31]);
429
430 rkey[ 3] = rotlConstant<11>( key[ 3] + delta[0][ 3]);
431 rkey[ 11] = rotlConstant<17>(rkey[ 3] + delta[1][ 6]);
432 rkey[ 19] = rotlConstant< 3>(rkey[ 11] + delta[3][ 4]);
433 rkey[ 27] = rotlConstant<11>(rkey[ 19] + delta[4][ 7]);
434 rkey[ 35] = rotlConstant<17>(rkey[ 27] + delta[5][10]);
435 rkey[ 43] = rotlConstant< 3>(rkey[ 35] + delta[7][ 8]);
436 rkey[ 51] = rotlConstant<11>(rkey[ 43] + delta[0][11]);
437 rkey[ 59] = rotlConstant<17>(rkey[ 51] + delta[1][14]);
438 rkey[ 67] = rotlConstant< 3>(rkey[ 59] + delta[3][12]);
439 rkey[ 75] = rotlConstant<11>(rkey[ 67] + delta[4][15]);
440 rkey[ 83] = rotlConstant<17>(rkey[ 75] + delta[5][18]);
441 rkey[ 91] = rotlConstant< 3>(rkey[ 83] + delta[7][16]);
442 rkey[ 99] = rotlConstant<11>(rkey[ 91] + delta[0][19]);
443 rkey[107] = rotlConstant<17>(rkey[ 99] + delta[1][22]);
444 rkey[115] = rotlConstant< 3>(rkey[107] + delta[3][20]);
445 rkey[123] = rotlConstant<11>(rkey[115] + delta[4][23]);
446 rkey[131] = rotlConstant<17>(rkey[123] + delta[5][26]);
447 rkey[139] = rotlConstant< 3>(rkey[131] + delta[7][24]);
448 rkey[147] = rotlConstant<11>(rkey[139] + delta[0][27]);
449 rkey[155] = rotlConstant<17>(rkey[147] + delta[1][30]);
450 rkey[163] = rotlConstant< 3>(rkey[155] + delta[3][28]);
451 rkey[171] = rotlConstant<11>(rkey[163] + delta[4][31]);
452 rkey[179] = rotlConstant<17>(rkey[171] + delta[5][ 2]);
453 rkey[187] = rotlConstant< 3>(rkey[179] + delta[7][ 0]);
454
455 rkey[ 4] = rotlConstant<13>( key[ 4] + delta[0][ 4]);
456 rkey[ 12] = rotlConstant< 1>(rkey[ 4] + delta[2][ 2]);
457 rkey[ 20] = rotlConstant< 6>(rkey[ 12] + delta[3][ 5]);
458 rkey[ 28] = rotlConstant<13>(rkey[ 20] + delta[4][ 8]);
459 rkey[ 36] = rotlConstant< 1>(rkey[ 28] + delta[6][ 6]);
460 rkey[ 44] = rotlConstant< 6>(rkey[ 36] + delta[7][ 9]);
461 rkey[ 52] = rotlConstant<13>(rkey[ 44] + delta[0][12]);
462 rkey[ 60] = rotlConstant< 1>(rkey[ 52] + delta[2][10]);
463 rkey[ 68] = rotlConstant< 6>(rkey[ 60] + delta[3][13]);
464 rkey[ 76] = rotlConstant<13>(rkey[ 68] + delta[4][16]);
465 rkey[ 84] = rotlConstant< 1>(rkey[ 76] + delta[6][14]);
466 rkey[ 92] = rotlConstant< 6>(rkey[ 84] + delta[7][17]);
467 rkey[100] = rotlConstant<13>(rkey[ 92] + delta[0][20]);
468 rkey[108] = rotlConstant< 1>(rkey[100] + delta[2][18]);
469 rkey[116] = rotlConstant< 6>(rkey[108] + delta[3][21]);
470 rkey[124] = rotlConstant<13>(rkey[116] + delta[4][24]);
471 rkey[132] = rotlConstant< 1>(rkey[124] + delta[6][22]);
472 rkey[140] = rotlConstant< 6>(rkey[132] + delta[7][25]);
473 rkey[148] = rotlConstant<13>(rkey[140] + delta[0][28]);
474 rkey[156] = rotlConstant< 1>(rkey[148] + delta[2][26]);
475 rkey[164] = rotlConstant< 6>(rkey[156] + delta[3][29]);
476 rkey[172] = rotlConstant<13>(rkey[164] + delta[4][ 0]);
477 rkey[180] = rotlConstant< 1>(rkey[172] + delta[6][30]);
478 rkey[188] = rotlConstant< 6>(rkey[180] + delta[7][ 1]);
479
480 rkey[ 5] = rotlConstant<17>( key[ 5] + delta[0][ 5]);
481 rkey[ 13] = rotlConstant< 3>(rkey[ 5] + delta[2][ 3]);
482 rkey[ 21] = rotlConstant<11>(rkey[ 13] + delta[3][ 6]);
483 rkey[ 29] = rotlConstant<17>(rkey[ 21] + delta[4][ 9]);
484 rkey[ 37] = rotlConstant< 3>(rkey[ 29] + delta[6][ 7]);
485 rkey[ 45] = rotlConstant<11>(rkey[ 37] + delta[7][10]);
486 rkey[ 53] = rotlConstant<17>(rkey[ 45] + delta[0][13]);
487 rkey[ 61] = rotlConstant< 3>(rkey[ 53] + delta[2][11]);
488 rkey[ 69] = rotlConstant<11>(rkey[ 61] + delta[3][14]);
489 rkey[ 77] = rotlConstant<17>(rkey[ 69] + delta[4][17]);
490 rkey[ 85] = rotlConstant< 3>(rkey[ 77] + delta[6][15]);
491 rkey[ 93] = rotlConstant<11>(rkey[ 85] + delta[7][18]);
492 rkey[101] = rotlConstant<17>(rkey[ 93] + delta[0][21]);
493 rkey[109] = rotlConstant< 3>(rkey[101] + delta[2][19]);
494 rkey[117] = rotlConstant<11>(rkey[109] + delta[3][22]);
495 rkey[125] = rotlConstant<17>(rkey[117] + delta[4][25]);
496 rkey[133] = rotlConstant< 3>(rkey[125] + delta[6][23]);
497 rkey[141] = rotlConstant<11>(rkey[133] + delta[7][26]);
498 rkey[149] = rotlConstant<17>(rkey[141] + delta[0][29]);
499 rkey[157] = rotlConstant< 3>(rkey[149] + delta[2][27]);
500 rkey[165] = rotlConstant<11>(rkey[157] + delta[3][30]);
501 rkey[173] = rotlConstant<17>(rkey[165] + delta[4][ 1]);
502 rkey[181] = rotlConstant< 3>(rkey[173] + delta[6][31]);
503 rkey[189] = rotlConstant<11>(rkey[181] + delta[7][ 2]);
504
505 rkey[ 6] = rotlConstant< 1>( key[ 6] + delta[1][ 1]);
506 rkey[ 14] = rotlConstant< 6>(rkey[ 6] + delta[2][ 4]);
507 rkey[ 22] = rotlConstant<13>(rkey[ 14] + delta[3][ 7]);
508 rkey[ 30] = rotlConstant< 1>(rkey[ 22] + delta[5][ 5]);
509 rkey[ 38] = rotlConstant< 6>(rkey[ 30] + delta[6][ 8]);
510 rkey[ 46] = rotlConstant<13>(rkey[ 38] + delta[7][11]);
511 rkey[ 54] = rotlConstant< 1>(rkey[ 46] + delta[1][ 9]);
512 rkey[ 62] = rotlConstant< 6>(rkey[ 54] + delta[2][12]);
513 rkey[ 70] = rotlConstant<13>(rkey[ 62] + delta[3][15]);
514 rkey[ 78] = rotlConstant< 1>(rkey[ 70] + delta[5][13]);
515 rkey[ 86] = rotlConstant< 6>(rkey[ 78] + delta[6][16]);
516 rkey[ 94] = rotlConstant<13>(rkey[ 86] + delta[7][19]);
517 rkey[102] = rotlConstant< 1>(rkey[ 94] + delta[1][17]);
518 rkey[110] = rotlConstant< 6>(rkey[102] + delta[2][20]);
519 rkey[118] = rotlConstant<13>(rkey[110] + delta[3][23]);
520 rkey[126] = rotlConstant< 1>(rkey[118] + delta[5][21]);
521 rkey[134] = rotlConstant< 6>(rkey[126] + delta[6][24]);
522 rkey[142] = rotlConstant<13>(rkey[134] + delta[7][27]);
523 rkey[150] = rotlConstant< 1>(rkey[142] + delta[1][25]);
524 rkey[158] = rotlConstant< 6>(rkey[150] + delta[2][28]);
525 rkey[166] = rotlConstant<13>(rkey[158] + delta[3][31]);
526 rkey[174] = rotlConstant< 1>(rkey[166] + delta[5][29]);
527 rkey[182] = rotlConstant< 6>(rkey[174] + delta[6][ 0]);
528 rkey[190] = rotlConstant<13>(rkey[182] + delta[7][ 3]);
529
530 rkey[ 7] = rotlConstant< 3>( key[ 7] + delta[1][ 2]);
531 rkey[ 15] = rotlConstant<11>(rkey[ 7] + delta[2][ 5]);
532 rkey[ 23] = rotlConstant<17>(rkey[ 15] + delta[3][ 8]);
533 rkey[ 31] = rotlConstant< 3>(rkey[ 23] + delta[5][ 6]);
534 rkey[ 39] = rotlConstant<11>(rkey[ 31] + delta[6][ 9]);
535 rkey[ 47] = rotlConstant<17>(rkey[ 39] + delta[7][12]);
536 rkey[ 55] = rotlConstant< 3>(rkey[ 47] + delta[1][10]);
537 rkey[ 63] = rotlConstant<11>(rkey[ 55] + delta[2][13]);
538 rkey[ 71] = rotlConstant<17>(rkey[ 63] + delta[3][16]);
539 rkey[ 79] = rotlConstant< 3>(rkey[ 71] + delta[5][14]);
540 rkey[ 87] = rotlConstant<11>(rkey[ 79] + delta[6][17]);
541 rkey[ 95] = rotlConstant<17>(rkey[ 87] + delta[7][20]);
542 rkey[103] = rotlConstant< 3>(rkey[ 95] + delta[1][18]);
543 rkey[111] = rotlConstant<11>(rkey[103] + delta[2][21]);
544 rkey[119] = rotlConstant<17>(rkey[111] + delta[3][24]);
545 rkey[127] = rotlConstant< 3>(rkey[119] + delta[5][22]);
546 rkey[135] = rotlConstant<11>(rkey[127] + delta[6][25]);
547 rkey[143] = rotlConstant<17>(rkey[135] + delta[7][28]);
548 rkey[151] = rotlConstant< 3>(rkey[143] + delta[1][26]);
549 rkey[159] = rotlConstant<11>(rkey[151] + delta[2][29]);
550 rkey[167] = rotlConstant<17>(rkey[159] + delta[3][ 0]);
551 rkey[175] = rotlConstant< 3>(rkey[167] + delta[5][30]);
552 rkey[183] = rotlConstant<11>(rkey[175] + delta[6][ 1]);
553 rkey[191] = rotlConstant<17>(rkey[183] + delta[7][ 4]);
554}
555
556NAMESPACE_BEGIN(CryptoPP)
557
558#if CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
559# if defined(CRYPTOPP_SSSE3_AVAILABLE)
560extern size_t LEA_Enc_AdvancedProcessBlocks_SSSE3(const word32* subKeys, size_t rounds,
561 const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
562
563extern size_t LEA_Dec_AdvancedProcessBlocks_SSSE3(const word32* subKeys, size_t rounds,
564 const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
565# endif
566
567# if (CRYPTOPP_ARM_NEON_AVAILABLE)
568extern size_t LEA_Enc_AdvancedProcessBlocks_NEON(const word32* subKeys, size_t rounds,
569 const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
570
571extern size_t LEA_Dec_AdvancedProcessBlocks_NEON(const word32* subKeys, size_t rounds,
572 const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
573# endif
574#endif
575
576std::string LEA::Base::AlgorithmProvider() const
577{
578#if (CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS)
579# if (CRYPTOPP_SSSE3_AVAILABLE)
580 if (HasSSSE3())
581 return "SSSE3";
582# endif
583# if (CRYPTOPP_ARM_NEON_AVAILABLE)
584 if (HasNEON())
585 return "NEON";
586# endif
587#endif
588 return "C++";
589}
590
591void LEA::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
592{
593 CRYPTOPP_UNUSED(params);
594
595 switch(keyLength)
596 {
597 case 16: // 128-bit key
598 {
599 m_rkey.New(144); m_temp.New(4); m_rounds = 24;
600 GetUserKey(LITTLE_ENDIAN_ORDER, m_temp.begin(), 4, userKey, 16);
601 SetKey128(m_rkey, m_temp);
602 break;
603 }
604 case 24: // 192-bit key
605 {
606 m_rkey.New(168); m_temp.New(6); m_rounds = 28;
607 GetUserKey(LITTLE_ENDIAN_ORDER, m_temp.begin(), 6, userKey, 24);
608 SetKey192(m_rkey, m_temp);
609 break;
610 }
611 case 32: // 256-bit key
612 {
613 m_rkey.New(192); m_temp.New(8); m_rounds = 32;
614 GetUserKey(LITTLE_ENDIAN_ORDER, m_temp.begin(), 8, userKey, 32);
615 SetKey256(m_rkey, m_temp);
616 break;
617 }
618 default:
620 }
621}
622
623void LEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
624{
625 // Do not cast the buffer. It will SIGBUS on some ARM and SPARC.
626 GetBlock<word32, LittleEndian> iblock(inBlock);
627 iblock(m_temp[0])(m_temp[1])(m_temp[2])(m_temp[3]);
628
629 m_temp[3] = rotrConstant<3>((m_temp[2] ^ m_rkey[ 4]) + (m_temp[3] ^ m_rkey[ 5]));
630 m_temp[2] = rotrConstant<5>((m_temp[1] ^ m_rkey[ 2]) + (m_temp[2] ^ m_rkey[ 3]));
631 m_temp[1] = rotlConstant<9>((m_temp[0] ^ m_rkey[ 0]) + (m_temp[1] ^ m_rkey[ 1]));
632 m_temp[0] = rotrConstant<3>((m_temp[3] ^ m_rkey[ 10]) + (m_temp[0] ^ m_rkey[ 11]));
633 m_temp[3] = rotrConstant<5>((m_temp[2] ^ m_rkey[ 8]) + (m_temp[3] ^ m_rkey[ 9]));
634 m_temp[2] = rotlConstant<9>((m_temp[1] ^ m_rkey[ 6]) + (m_temp[2] ^ m_rkey[ 7]));
635 m_temp[1] = rotrConstant<3>((m_temp[0] ^ m_rkey[ 16]) + (m_temp[1] ^ m_rkey[ 17]));
636 m_temp[0] = rotrConstant<5>((m_temp[3] ^ m_rkey[ 14]) + (m_temp[0] ^ m_rkey[ 15]));
637 m_temp[3] = rotlConstant<9>((m_temp[2] ^ m_rkey[ 12]) + (m_temp[3] ^ m_rkey[ 13]));
638 m_temp[2] = rotrConstant<3>((m_temp[1] ^ m_rkey[ 22]) + (m_temp[2] ^ m_rkey[ 23]));
639 m_temp[1] = rotrConstant<5>((m_temp[0] ^ m_rkey[ 20]) + (m_temp[1] ^ m_rkey[ 21]));
640 m_temp[0] = rotlConstant<9>((m_temp[3] ^ m_rkey[ 18]) + (m_temp[0] ^ m_rkey[ 19]));
641
642 m_temp[3] = rotrConstant<3>((m_temp[2] ^ m_rkey[ 28]) + (m_temp[3] ^ m_rkey[ 29]));
643 m_temp[2] = rotrConstant<5>((m_temp[1] ^ m_rkey[ 26]) + (m_temp[2] ^ m_rkey[ 27]));
644 m_temp[1] = rotlConstant<9>((m_temp[0] ^ m_rkey[ 24]) + (m_temp[1] ^ m_rkey[ 25]));
645 m_temp[0] = rotrConstant<3>((m_temp[3] ^ m_rkey[ 34]) + (m_temp[0] ^ m_rkey[ 35]));
646 m_temp[3] = rotrConstant<5>((m_temp[2] ^ m_rkey[ 32]) + (m_temp[3] ^ m_rkey[ 33]));
647 m_temp[2] = rotlConstant<9>((m_temp[1] ^ m_rkey[ 30]) + (m_temp[2] ^ m_rkey[ 31]));
648 m_temp[1] = rotrConstant<3>((m_temp[0] ^ m_rkey[ 40]) + (m_temp[1] ^ m_rkey[ 41]));
649 m_temp[0] = rotrConstant<5>((m_temp[3] ^ m_rkey[ 38]) + (m_temp[0] ^ m_rkey[ 39]));
650 m_temp[3] = rotlConstant<9>((m_temp[2] ^ m_rkey[ 36]) + (m_temp[3] ^ m_rkey[ 37]));
651 m_temp[2] = rotrConstant<3>((m_temp[1] ^ m_rkey[ 46]) + (m_temp[2] ^ m_rkey[ 47]));
652 m_temp[1] = rotrConstant<5>((m_temp[0] ^ m_rkey[ 44]) + (m_temp[1] ^ m_rkey[ 45]));
653 m_temp[0] = rotlConstant<9>((m_temp[3] ^ m_rkey[ 42]) + (m_temp[0] ^ m_rkey[ 43]));
654
655 m_temp[3] = rotrConstant<3>((m_temp[2] ^ m_rkey[ 52]) + (m_temp[3] ^ m_rkey[ 53]));
656 m_temp[2] = rotrConstant<5>((m_temp[1] ^ m_rkey[ 50]) + (m_temp[2] ^ m_rkey[ 51]));
657 m_temp[1] = rotlConstant<9>((m_temp[0] ^ m_rkey[ 48]) + (m_temp[1] ^ m_rkey[ 49]));
658 m_temp[0] = rotrConstant<3>((m_temp[3] ^ m_rkey[ 58]) + (m_temp[0] ^ m_rkey[ 59]));
659 m_temp[3] = rotrConstant<5>((m_temp[2] ^ m_rkey[ 56]) + (m_temp[3] ^ m_rkey[ 57]));
660 m_temp[2] = rotlConstant<9>((m_temp[1] ^ m_rkey[ 54]) + (m_temp[2] ^ m_rkey[ 55]));
661 m_temp[1] = rotrConstant<3>((m_temp[0] ^ m_rkey[ 64]) + (m_temp[1] ^ m_rkey[ 65]));
662 m_temp[0] = rotrConstant<5>((m_temp[3] ^ m_rkey[ 62]) + (m_temp[0] ^ m_rkey[ 63]));
663 m_temp[3] = rotlConstant<9>((m_temp[2] ^ m_rkey[ 60]) + (m_temp[3] ^ m_rkey[ 61]));
664 m_temp[2] = rotrConstant<3>((m_temp[1] ^ m_rkey[ 70]) + (m_temp[2] ^ m_rkey[ 71]));
665 m_temp[1] = rotrConstant<5>((m_temp[0] ^ m_rkey[ 68]) + (m_temp[1] ^ m_rkey[ 69]));
666 m_temp[0] = rotlConstant<9>((m_temp[3] ^ m_rkey[ 66]) + (m_temp[0] ^ m_rkey[ 67]));
667
668 m_temp[3] = rotrConstant<3>((m_temp[2] ^ m_rkey[ 76]) + (m_temp[3] ^ m_rkey[ 77]));
669 m_temp[2] = rotrConstant<5>((m_temp[1] ^ m_rkey[ 74]) + (m_temp[2] ^ m_rkey[ 75]));
670 m_temp[1] = rotlConstant<9>((m_temp[0] ^ m_rkey[ 72]) + (m_temp[1] ^ m_rkey[ 73]));
671 m_temp[0] = rotrConstant<3>((m_temp[3] ^ m_rkey[ 82]) + (m_temp[0] ^ m_rkey[ 83]));
672 m_temp[3] = rotrConstant<5>((m_temp[2] ^ m_rkey[ 80]) + (m_temp[3] ^ m_rkey[ 81]));
673 m_temp[2] = rotlConstant<9>((m_temp[1] ^ m_rkey[ 78]) + (m_temp[2] ^ m_rkey[ 79]));
674 m_temp[1] = rotrConstant<3>((m_temp[0] ^ m_rkey[ 88]) + (m_temp[1] ^ m_rkey[ 89]));
675 m_temp[0] = rotrConstant<5>((m_temp[3] ^ m_rkey[ 86]) + (m_temp[0] ^ m_rkey[ 87]));
676 m_temp[3] = rotlConstant<9>((m_temp[2] ^ m_rkey[ 84]) + (m_temp[3] ^ m_rkey[ 85]));
677 m_temp[2] = rotrConstant<3>((m_temp[1] ^ m_rkey[ 94]) + (m_temp[2] ^ m_rkey[ 95]));
678 m_temp[1] = rotrConstant<5>((m_temp[0] ^ m_rkey[ 92]) + (m_temp[1] ^ m_rkey[ 93]));
679 m_temp[0] = rotlConstant<9>((m_temp[3] ^ m_rkey[ 90]) + (m_temp[0] ^ m_rkey[ 91]));
680
681 m_temp[3] = rotrConstant<3>((m_temp[2] ^ m_rkey[100]) + (m_temp[3] ^ m_rkey[101]));
682 m_temp[2] = rotrConstant<5>((m_temp[1] ^ m_rkey[ 98]) + (m_temp[2] ^ m_rkey[ 99]));
683 m_temp[1] = rotlConstant<9>((m_temp[0] ^ m_rkey[ 96]) + (m_temp[1] ^ m_rkey[ 97]));
684 m_temp[0] = rotrConstant<3>((m_temp[3] ^ m_rkey[106]) + (m_temp[0] ^ m_rkey[107]));
685 m_temp[3] = rotrConstant<5>((m_temp[2] ^ m_rkey[104]) + (m_temp[3] ^ m_rkey[105]));
686 m_temp[2] = rotlConstant<9>((m_temp[1] ^ m_rkey[102]) + (m_temp[2] ^ m_rkey[103]));
687 m_temp[1] = rotrConstant<3>((m_temp[0] ^ m_rkey[112]) + (m_temp[1] ^ m_rkey[113]));
688 m_temp[0] = rotrConstant<5>((m_temp[3] ^ m_rkey[110]) + (m_temp[0] ^ m_rkey[111]));
689 m_temp[3] = rotlConstant<9>((m_temp[2] ^ m_rkey[108]) + (m_temp[3] ^ m_rkey[109]));
690 m_temp[2] = rotrConstant<3>((m_temp[1] ^ m_rkey[118]) + (m_temp[2] ^ m_rkey[119]));
691 m_temp[1] = rotrConstant<5>((m_temp[0] ^ m_rkey[116]) + (m_temp[1] ^ m_rkey[117]));
692 m_temp[0] = rotlConstant<9>((m_temp[3] ^ m_rkey[114]) + (m_temp[0] ^ m_rkey[115]));
693
694 m_temp[3] = rotrConstant<3>((m_temp[2] ^ m_rkey[124]) + (m_temp[3] ^ m_rkey[125]));
695 m_temp[2] = rotrConstant<5>((m_temp[1] ^ m_rkey[122]) + (m_temp[2] ^ m_rkey[123]));
696 m_temp[1] = rotlConstant<9>((m_temp[0] ^ m_rkey[120]) + (m_temp[1] ^ m_rkey[121]));
697 m_temp[0] = rotrConstant<3>((m_temp[3] ^ m_rkey[130]) + (m_temp[0] ^ m_rkey[131]));
698 m_temp[3] = rotrConstant<5>((m_temp[2] ^ m_rkey[128]) + (m_temp[3] ^ m_rkey[129]));
699 m_temp[2] = rotlConstant<9>((m_temp[1] ^ m_rkey[126]) + (m_temp[2] ^ m_rkey[127]));
700 m_temp[1] = rotrConstant<3>((m_temp[0] ^ m_rkey[136]) + (m_temp[1] ^ m_rkey[137]));
701 m_temp[0] = rotrConstant<5>((m_temp[3] ^ m_rkey[134]) + (m_temp[0] ^ m_rkey[135]));
702 m_temp[3] = rotlConstant<9>((m_temp[2] ^ m_rkey[132]) + (m_temp[3] ^ m_rkey[133]));
703 m_temp[2] = rotrConstant<3>((m_temp[1] ^ m_rkey[142]) + (m_temp[2] ^ m_rkey[143]));
704 m_temp[1] = rotrConstant<5>((m_temp[0] ^ m_rkey[140]) + (m_temp[1] ^ m_rkey[141]));
705 m_temp[0] = rotlConstant<9>((m_temp[3] ^ m_rkey[138]) + (m_temp[0] ^ m_rkey[139]));
706
707 if(m_rounds > 24)
708 {
709 m_temp[3] = rotrConstant<3>((m_temp[2] ^ m_rkey[148]) + (m_temp[3] ^ m_rkey[149]));
710 m_temp[2] = rotrConstant<5>((m_temp[1] ^ m_rkey[146]) + (m_temp[2] ^ m_rkey[147]));
711 m_temp[1] = rotlConstant<9>((m_temp[0] ^ m_rkey[144]) + (m_temp[1] ^ m_rkey[145]));
712 m_temp[0] = rotrConstant<3>((m_temp[3] ^ m_rkey[154]) + (m_temp[0] ^ m_rkey[155]));
713 m_temp[3] = rotrConstant<5>((m_temp[2] ^ m_rkey[152]) + (m_temp[3] ^ m_rkey[153]));
714 m_temp[2] = rotlConstant<9>((m_temp[1] ^ m_rkey[150]) + (m_temp[2] ^ m_rkey[151]));
715 m_temp[1] = rotrConstant<3>((m_temp[0] ^ m_rkey[160]) + (m_temp[1] ^ m_rkey[161]));
716 m_temp[0] = rotrConstant<5>((m_temp[3] ^ m_rkey[158]) + (m_temp[0] ^ m_rkey[159]));
717 m_temp[3] = rotlConstant<9>((m_temp[2] ^ m_rkey[156]) + (m_temp[3] ^ m_rkey[157]));
718 m_temp[2] = rotrConstant<3>((m_temp[1] ^ m_rkey[166]) + (m_temp[2] ^ m_rkey[167]));
719 m_temp[1] = rotrConstant<5>((m_temp[0] ^ m_rkey[164]) + (m_temp[1] ^ m_rkey[165]));
720 m_temp[0] = rotlConstant<9>((m_temp[3] ^ m_rkey[162]) + (m_temp[0] ^ m_rkey[163]));
721 }
722
723 if(m_rounds > 28)
724 {
725 m_temp[3] = rotrConstant<3>((m_temp[2] ^ m_rkey[172]) + (m_temp[3] ^ m_rkey[173]));
726 m_temp[2] = rotrConstant<5>((m_temp[1] ^ m_rkey[170]) + (m_temp[2] ^ m_rkey[171]));
727 m_temp[1] = rotlConstant<9>((m_temp[0] ^ m_rkey[168]) + (m_temp[1] ^ m_rkey[169]));
728 m_temp[0] = rotrConstant<3>((m_temp[3] ^ m_rkey[178]) + (m_temp[0] ^ m_rkey[179]));
729 m_temp[3] = rotrConstant<5>((m_temp[2] ^ m_rkey[176]) + (m_temp[3] ^ m_rkey[177]));
730 m_temp[2] = rotlConstant<9>((m_temp[1] ^ m_rkey[174]) + (m_temp[2] ^ m_rkey[175]));
731 m_temp[1] = rotrConstant<3>((m_temp[0] ^ m_rkey[184]) + (m_temp[1] ^ m_rkey[185]));
732 m_temp[0] = rotrConstant<5>((m_temp[3] ^ m_rkey[182]) + (m_temp[0] ^ m_rkey[183]));
733 m_temp[3] = rotlConstant<9>((m_temp[2] ^ m_rkey[180]) + (m_temp[3] ^ m_rkey[181]));
734 m_temp[2] = rotrConstant<3>((m_temp[1] ^ m_rkey[190]) + (m_temp[2] ^ m_rkey[191]));
735 m_temp[1] = rotrConstant<5>((m_temp[0] ^ m_rkey[188]) + (m_temp[1] ^ m_rkey[189]));
736 m_temp[0] = rotlConstant<9>((m_temp[3] ^ m_rkey[186]) + (m_temp[0] ^ m_rkey[187]));
737 }
738
739 PutBlock<word32, LittleEndian> oblock(xorBlock, outBlock);
740 oblock(m_temp[0])(m_temp[1])(m_temp[2])(m_temp[3]);
741}
742
743void LEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
744{
745 // Do not cast the buffer. It will SIGBUS on some ARM and SPARC.
746 GetBlock<word32, LittleEndian> iblock(inBlock);
747 iblock(m_temp[0])(m_temp[1])(m_temp[2])(m_temp[3]);
748
749 if(m_rounds > 28)
750 {
751 m_temp[0] = (rotrConstant<9>(m_temp[0]) - (m_temp[3] ^ m_rkey[186])) ^ m_rkey[187];
752 m_temp[1] = (rotlConstant<5>(m_temp[1]) - (m_temp[0] ^ m_rkey[188])) ^ m_rkey[189];
753 m_temp[2] = (rotlConstant<3>(m_temp[2]) - (m_temp[1] ^ m_rkey[190])) ^ m_rkey[191];
754 m_temp[3] = (rotrConstant<9>(m_temp[3]) - (m_temp[2] ^ m_rkey[180])) ^ m_rkey[181];
755 m_temp[0] = (rotlConstant<5>(m_temp[0]) - (m_temp[3] ^ m_rkey[182])) ^ m_rkey[183];
756 m_temp[1] = (rotlConstant<3>(m_temp[1]) - (m_temp[0] ^ m_rkey[184])) ^ m_rkey[185];
757 m_temp[2] = (rotrConstant<9>(m_temp[2]) - (m_temp[1] ^ m_rkey[174])) ^ m_rkey[175];
758 m_temp[3] = (rotlConstant<5>(m_temp[3]) - (m_temp[2] ^ m_rkey[176])) ^ m_rkey[177];
759 m_temp[0] = (rotlConstant<3>(m_temp[0]) - (m_temp[3] ^ m_rkey[178])) ^ m_rkey[179];
760 m_temp[1] = (rotrConstant<9>(m_temp[1]) - (m_temp[0] ^ m_rkey[168])) ^ m_rkey[169];
761 m_temp[2] = (rotlConstant<5>(m_temp[2]) - (m_temp[1] ^ m_rkey[170])) ^ m_rkey[171];
762 m_temp[3] = (rotlConstant<3>(m_temp[3]) - (m_temp[2] ^ m_rkey[172])) ^ m_rkey[173];
763 }
764
765 if(m_rounds > 24)
766 {
767 m_temp[0] = (rotrConstant<9>(m_temp[0]) - (m_temp[3] ^ m_rkey[162])) ^ m_rkey[163];
768 m_temp[1] = (rotlConstant<5>(m_temp[1]) - (m_temp[0] ^ m_rkey[164])) ^ m_rkey[165];
769 m_temp[2] = (rotlConstant<3>(m_temp[2]) - (m_temp[1] ^ m_rkey[166])) ^ m_rkey[167];
770 m_temp[3] = (rotrConstant<9>(m_temp[3]) - (m_temp[2] ^ m_rkey[156])) ^ m_rkey[157];
771 m_temp[0] = (rotlConstant<5>(m_temp[0]) - (m_temp[3] ^ m_rkey[158])) ^ m_rkey[159];
772 m_temp[1] = (rotlConstant<3>(m_temp[1]) - (m_temp[0] ^ m_rkey[160])) ^ m_rkey[161];
773 m_temp[2] = (rotrConstant<9>(m_temp[2]) - (m_temp[1] ^ m_rkey[150])) ^ m_rkey[151];
774 m_temp[3] = (rotlConstant<5>(m_temp[3]) - (m_temp[2] ^ m_rkey[152])) ^ m_rkey[153];
775 m_temp[0] = (rotlConstant<3>(m_temp[0]) - (m_temp[3] ^ m_rkey[154])) ^ m_rkey[155];
776 m_temp[1] = (rotrConstant<9>(m_temp[1]) - (m_temp[0] ^ m_rkey[144])) ^ m_rkey[145];
777 m_temp[2] = (rotlConstant<5>(m_temp[2]) - (m_temp[1] ^ m_rkey[146])) ^ m_rkey[147];
778 m_temp[3] = (rotlConstant<3>(m_temp[3]) - (m_temp[2] ^ m_rkey[148])) ^ m_rkey[149];
779 }
780
781 m_temp[0] = (rotrConstant<9>(m_temp[0]) - (m_temp[3] ^ m_rkey[138])) ^ m_rkey[139];
782 m_temp[1] = (rotlConstant<5>(m_temp[1]) - (m_temp[0] ^ m_rkey[140])) ^ m_rkey[141];
783 m_temp[2] = (rotlConstant<3>(m_temp[2]) - (m_temp[1] ^ m_rkey[142])) ^ m_rkey[143];
784 m_temp[3] = (rotrConstant<9>(m_temp[3]) - (m_temp[2] ^ m_rkey[132])) ^ m_rkey[133];
785 m_temp[0] = (rotlConstant<5>(m_temp[0]) - (m_temp[3] ^ m_rkey[134])) ^ m_rkey[135];
786 m_temp[1] = (rotlConstant<3>(m_temp[1]) - (m_temp[0] ^ m_rkey[136])) ^ m_rkey[137];
787 m_temp[2] = (rotrConstant<9>(m_temp[2]) - (m_temp[1] ^ m_rkey[126])) ^ m_rkey[127];
788 m_temp[3] = (rotlConstant<5>(m_temp[3]) - (m_temp[2] ^ m_rkey[128])) ^ m_rkey[129];
789 m_temp[0] = (rotlConstant<3>(m_temp[0]) - (m_temp[3] ^ m_rkey[130])) ^ m_rkey[131];
790 m_temp[1] = (rotrConstant<9>(m_temp[1]) - (m_temp[0] ^ m_rkey[120])) ^ m_rkey[121];
791 m_temp[2] = (rotlConstant<5>(m_temp[2]) - (m_temp[1] ^ m_rkey[122])) ^ m_rkey[123];
792 m_temp[3] = (rotlConstant<3>(m_temp[3]) - (m_temp[2] ^ m_rkey[124])) ^ m_rkey[125];
793
794 m_temp[0] = (rotrConstant<9>(m_temp[0]) - (m_temp[3] ^ m_rkey[114])) ^ m_rkey[115];
795 m_temp[1] = (rotlConstant<5>(m_temp[1]) - (m_temp[0] ^ m_rkey[116])) ^ m_rkey[117];
796 m_temp[2] = (rotlConstant<3>(m_temp[2]) - (m_temp[1] ^ m_rkey[118])) ^ m_rkey[119];
797 m_temp[3] = (rotrConstant<9>(m_temp[3]) - (m_temp[2] ^ m_rkey[108])) ^ m_rkey[109];
798 m_temp[0] = (rotlConstant<5>(m_temp[0]) - (m_temp[3] ^ m_rkey[110])) ^ m_rkey[111];
799 m_temp[1] = (rotlConstant<3>(m_temp[1]) - (m_temp[0] ^ m_rkey[112])) ^ m_rkey[113];
800 m_temp[2] = (rotrConstant<9>(m_temp[2]) - (m_temp[1] ^ m_rkey[102])) ^ m_rkey[103];
801 m_temp[3] = (rotlConstant<5>(m_temp[3]) - (m_temp[2] ^ m_rkey[104])) ^ m_rkey[105];
802 m_temp[0] = (rotlConstant<3>(m_temp[0]) - (m_temp[3] ^ m_rkey[106])) ^ m_rkey[107];
803 m_temp[1] = (rotrConstant<9>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 96])) ^ m_rkey[ 97];
804 m_temp[2] = (rotlConstant<5>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 98])) ^ m_rkey[ 99];
805 m_temp[3] = (rotlConstant<3>(m_temp[3]) - (m_temp[2] ^ m_rkey[100])) ^ m_rkey[101];
806
807 m_temp[0] = (rotrConstant<9>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 90])) ^ m_rkey[ 91];
808 m_temp[1] = (rotlConstant<5>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 92])) ^ m_rkey[ 93];
809 m_temp[2] = (rotlConstant<3>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 94])) ^ m_rkey[ 95];
810 m_temp[3] = (rotrConstant<9>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 84])) ^ m_rkey[ 85];
811 m_temp[0] = (rotlConstant<5>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 86])) ^ m_rkey[ 87];
812 m_temp[1] = (rotlConstant<3>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 88])) ^ m_rkey[ 89];
813 m_temp[2] = (rotrConstant<9>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 78])) ^ m_rkey[ 79];
814 m_temp[3] = (rotlConstant<5>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 80])) ^ m_rkey[ 81];
815 m_temp[0] = (rotlConstant<3>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 82])) ^ m_rkey[ 83];
816 m_temp[1] = (rotrConstant<9>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 72])) ^ m_rkey[ 73];
817 m_temp[2] = (rotlConstant<5>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 74])) ^ m_rkey[ 75];
818 m_temp[3] = (rotlConstant<3>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 76])) ^ m_rkey[ 77];
819
820 m_temp[0] = (rotrConstant<9>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 66])) ^ m_rkey[ 67];
821 m_temp[1] = (rotlConstant<5>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 68])) ^ m_rkey[ 69];
822 m_temp[2] = (rotlConstant<3>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 70])) ^ m_rkey[ 71];
823 m_temp[3] = (rotrConstant<9>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 60])) ^ m_rkey[ 61];
824 m_temp[0] = (rotlConstant<5>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 62])) ^ m_rkey[ 63];
825 m_temp[1] = (rotlConstant<3>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 64])) ^ m_rkey[ 65];
826 m_temp[2] = (rotrConstant<9>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 54])) ^ m_rkey[ 55];
827 m_temp[3] = (rotlConstant<5>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 56])) ^ m_rkey[ 57];
828 m_temp[0] = (rotlConstant<3>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 58])) ^ m_rkey[ 59];
829 m_temp[1] = (rotrConstant<9>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 48])) ^ m_rkey[ 49];
830 m_temp[2] = (rotlConstant<5>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 50])) ^ m_rkey[ 51];
831 m_temp[3] = (rotlConstant<3>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 52])) ^ m_rkey[ 53];
832
833 m_temp[0] = (rotrConstant<9>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 42])) ^ m_rkey[ 43];
834 m_temp[1] = (rotlConstant<5>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 44])) ^ m_rkey[ 45];
835 m_temp[2] = (rotlConstant<3>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 46])) ^ m_rkey[ 47];
836 m_temp[3] = (rotrConstant<9>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 36])) ^ m_rkey[ 37];
837 m_temp[0] = (rotlConstant<5>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 38])) ^ m_rkey[ 39];
838 m_temp[1] = (rotlConstant<3>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 40])) ^ m_rkey[ 41];
839 m_temp[2] = (rotrConstant<9>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 30])) ^ m_rkey[ 31];
840 m_temp[3] = (rotlConstant<5>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 32])) ^ m_rkey[ 33];
841 m_temp[0] = (rotlConstant<3>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 34])) ^ m_rkey[ 35];
842 m_temp[1] = (rotrConstant<9>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 24])) ^ m_rkey[ 25];
843 m_temp[2] = (rotlConstant<5>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 26])) ^ m_rkey[ 27];
844 m_temp[3] = (rotlConstant<3>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 28])) ^ m_rkey[ 29];
845
846 m_temp[0] = (rotrConstant<9>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 18])) ^ m_rkey[ 19];
847 m_temp[1] = (rotlConstant<5>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 20])) ^ m_rkey[ 21];
848 m_temp[2] = (rotlConstant<3>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 22])) ^ m_rkey[ 23];
849 m_temp[3] = (rotrConstant<9>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 12])) ^ m_rkey[ 13];
850 m_temp[0] = (rotlConstant<5>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 14])) ^ m_rkey[ 15];
851 m_temp[1] = (rotlConstant<3>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 16])) ^ m_rkey[ 17];
852 m_temp[2] = (rotrConstant<9>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 6])) ^ m_rkey[ 7];
853 m_temp[3] = (rotlConstant<5>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 8])) ^ m_rkey[ 9];
854 m_temp[0] = (rotlConstant<3>(m_temp[0]) - (m_temp[3] ^ m_rkey[ 10])) ^ m_rkey[ 11];
855 m_temp[1] = (rotrConstant<9>(m_temp[1]) - (m_temp[0] ^ m_rkey[ 0])) ^ m_rkey[ 1];
856 m_temp[2] = (rotlConstant<5>(m_temp[2]) - (m_temp[1] ^ m_rkey[ 2])) ^ m_rkey[ 3];
857 m_temp[3] = (rotlConstant<3>(m_temp[3]) - (m_temp[2] ^ m_rkey[ 4])) ^ m_rkey[ 5];
858
859 PutBlock<word32, LittleEndian> oblock(xorBlock, outBlock);
860 oblock(m_temp[0])(m_temp[1])(m_temp[2])(m_temp[3]);
861}
862
863#if CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
864size_t LEA::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks,
865 byte *outBlocks, size_t length, word32 flags) const
866{
867#if defined(CRYPTOPP_SSSE3_AVAILABLE)
868 if (HasSSSE3()) {
869 return LEA_Enc_AdvancedProcessBlocks_SSSE3(m_rkey, m_rounds,
870 inBlocks, xorBlocks, outBlocks, length, flags);
871 }
872#endif
873#if (CRYPTOPP_ARM_NEON_AVAILABLE)
874 if (HasNEON())
875 return LEA_Enc_AdvancedProcessBlocks_NEON(m_rkey, (size_t)m_rounds,
876 inBlocks, xorBlocks, outBlocks, length, flags);
877#endif
878 return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
879}
880
881size_t LEA::Dec::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks,
882 byte *outBlocks, size_t length, word32 flags) const
883{
884#if defined(CRYPTOPP_SSSE3_AVAILABLE)
885 if (HasSSSE3()) {
886 return LEA_Dec_AdvancedProcessBlocks_SSSE3(m_rkey, m_rounds,
887 inBlocks, xorBlocks, outBlocks, length, flags);
888 }
889#endif
890#if (CRYPTOPP_ARM_NEON_AVAILABLE)
891 if (HasNEON())
892 return LEA_Dec_AdvancedProcessBlocks_NEON(m_rkey, (size_t)m_rounds,
893 inBlocks, xorBlocks, outBlocks, length, flags);
894#endif
895 return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
896}
897#endif // CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
898
899NAMESPACE_END
virtual size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const
Encrypt and xor multiple blocks using additional flags.
Access a block of memory.
Definition misc.h:2975
Interface for retrieving values given their names.
Definition cryptlib.h:327
Access a block of memory.
Definition misc.h:3016
Library configuration file.
unsigned int word32
32-bit unsigned datatype
Definition config_int.h:72
Functions for CPU features and intrinsics.
@ LITTLE_ENDIAN_ORDER
byte order is little-endian
Definition cryptlib.h:150
Classes for the LEA block cipher.
Utility functions for the Crypto++ library.
void GetUserKey(ByteOrder order, T *out, size_t outlen, const byte *in, size_t inlen)
Copy bytes in a buffer to an array of elements in big-endian order.
Definition misc.h:2500
Crypto++ library namespace.
Precompiled header file.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition trap.h:68