21 NAMESPACE_BEGIN(KalynaTab)
24 extern const word64 T[8][256];
25 extern const word64 IT[8][256];
26 extern const byte S[4][256];
27 extern const byte IS[4][256];
32 ANONYMOUS_NAMESPACE_BEGIN
35 typedef unsigned char byte;
37 using CryptoPP::word64;
38 using CryptoPP::KalynaTab::T;
39 using CryptoPP::KalynaTab::S;
40 using CryptoPP::KalynaTab::IT;
41 using CryptoPP::KalynaTab::IS;
43 template <
unsigned int NB>
44 inline void MakeOddKey(
const word64 evenkey[NB], word64 oddkey[NB])
46 #if (CRYPTOPP_BIG_ENDIAN) 49 oddkey[0] = (evenkey[1] << 8) | (evenkey[0] >> 56);
50 oddkey[1] = (evenkey[0] << 8) | (evenkey[1] >> 56);
54 oddkey[0] = (evenkey[2] << 40) | (evenkey[1] >> 24);
55 oddkey[1] = (evenkey[3] << 40) | (evenkey[2] >> 24);
56 oddkey[2] = (evenkey[0] << 40) | (evenkey[3] >> 24);
57 oddkey[3] = (evenkey[1] << 40) | (evenkey[0] >> 24);
61 oddkey[0] = (evenkey[3] << 40) | (evenkey[2] >> 24);
62 oddkey[1] = (evenkey[4] << 40) | (evenkey[3] >> 24);
63 oddkey[2] = (evenkey[5] << 40) | (evenkey[4] >> 24);
64 oddkey[3] = (evenkey[6] << 40) | (evenkey[5] >> 24);
66 oddkey[4] = (evenkey[7] << 40) | (evenkey[6] >> 24);
67 oddkey[5] = (evenkey[0] << 40) | (evenkey[7] >> 24);
68 oddkey[6] = (evenkey[1] << 40) | (evenkey[0] >> 24);
69 oddkey[7] = (evenkey[2] << 40) | (evenkey[1] >> 24);
76 static const unsigned int U = (NB == 2) ? 16 : (NB == 4) ? 32 : (NB == 8) ? 64 : -1;
77 static const unsigned int V = (NB == 2) ? 7 : (NB == 4) ? 11 : (NB == 8) ? 19 : -1;
79 const byte* even =
reinterpret_cast<const byte*
>(evenkey);
80 byte* odd =
reinterpret_cast<byte*
>(oddkey);
82 memcpy(odd, even + V, U - V);
83 memcpy(odd + U - V, even, V);
87 template <
unsigned int NB>
88 inline void SwapBlocks(word64 k[NB])
90 const word64 t = k[0];
110 template <
unsigned int NB>
111 inline void AddKey(
const word64 x[NB], word64 y[NB],
const word64 k[NB])
131 template <
unsigned int NB>
132 inline void SubKey(
const word64 x[NB], word64 y[NB],
const word64 k[NB])
152 template <
unsigned int NB>
153 static inline void AddConstant(word64 src[NB], word64 dst[NB], word64 constant)
155 dst[0] = src[0] + constant;
156 dst[1] = src[1] + constant;
160 dst[2] = src[2] + constant;
161 dst[3] = src[3] + constant;
166 dst[4] = src[4] + constant;
167 dst[5] = src[5] + constant;
168 dst[6] = src[6] + constant;
169 dst[7] = src[7] + constant;
173 inline void G0128(
const word64 x[2], word64 y[2])
175 y[0] = T[0][(byte)x[0]] ^ T[1][(byte)(x[0] >> 8)] ^ T[2][(byte)(x[0] >> 16)] ^ T[3][(byte)(x[0] >> 24)] ^
176 T[4][(byte)(x[1] >> 32)] ^ T[5][(byte)(x[1] >> 40)] ^ T[6][(byte)(x[1] >> 48)] ^ T[7][(byte)(x[1] >> 56)];
177 y[1] = T[0][(byte)x[1]] ^ T[1][(byte)(x[1] >> 8)] ^ T[2][(byte)(x[1] >> 16)] ^ T[3][(byte)(x[1] >> 24)] ^
178 T[4][(byte)(x[0] >> 32)] ^ T[5][(byte)(x[0] >> 40)] ^ T[6][(byte)(x[0] >> 48)] ^ T[7][(byte)(x[0] >> 56)];
181 inline void G0256(
const word64 x[4], word64 y[4])
183 y[0] = T[0][(byte)x[0]] ^ T[1][(byte)(x[0] >> 8)] ^ T[2][(byte)(x[3] >> 16)] ^ T[3][(byte)(x[3] >> 24)] ^
184 T[4][(byte)(x[2] >> 32)] ^ T[5][(byte)(x[2] >> 40)] ^ T[6][(byte)(x[1] >> 48)] ^ T[7][(byte)(x[1] >> 56)];
185 y[1] = T[0][(byte)x[1]] ^ T[1][(byte)(x[1] >> 8)] ^ T[2][(byte)(x[0] >> 16)] ^ T[3][(byte)(x[0] >> 24)] ^
186 T[4][(byte)(x[3] >> 32)] ^ T[5][(byte)(x[3] >> 40)] ^ T[6][(byte)(x[2] >> 48)] ^ T[7][(byte)(x[2] >> 56)];
187 y[2] = T[0][(byte)x[2]] ^ T[1][(byte)(x[2] >> 8)] ^ T[2][(byte)(x[1] >> 16)] ^ T[3][(byte)(x[1] >> 24)] ^
188 T[4][(byte)(x[0] >> 32)] ^ T[5][(byte)(x[0] >> 40)] ^ T[6][(byte)(x[3] >> 48)] ^ T[7][(byte)(x[3] >> 56)];
189 y[3] = T[0][(byte)x[3]] ^ T[1][(byte)(x[3] >> 8)] ^ T[2][(byte)(x[2] >> 16)] ^ T[3][(byte)(x[2] >> 24)] ^
190 T[4][(byte)(x[1] >> 32)] ^ T[5][(byte)(x[1] >> 40)] ^ T[6][(byte)(x[0] >> 48)] ^ T[7][(byte)(x[0] >> 56)];
193 inline void G0512(
const word64 x[8], word64 y[8])
195 y[0] = T[0][(byte)x[0]] ^ T[1][(byte)(x[7] >> 8)] ^ T[2][(byte)(x[6] >> 16)] ^ T[3][(byte)(x[5] >> 24)] ^
196 T[4][(byte)(x[4] >> 32)] ^ T[5][(byte)(x[3] >> 40)] ^ T[6][(byte)(x[2] >> 48)] ^ T[7][(byte)(x[1] >> 56)];
197 y[1] = T[0][(byte)x[1]] ^ T[1][(byte)(x[0] >> 8)] ^ T[2][(byte)(x[7] >> 16)] ^ T[3][(byte)(x[6] >> 24)] ^
198 T[4][(byte)(x[5] >> 32)] ^ T[5][(byte)(x[4] >> 40)] ^ T[6][(byte)(x[3] >> 48)] ^ T[7][(byte)(x[2] >> 56)];
199 y[2] = T[0][(byte)x[2]] ^ T[1][(byte)(x[1] >> 8)] ^ T[2][(byte)(x[0] >> 16)] ^ T[3][(byte)(x[7] >> 24)] ^
200 T[4][(byte)(x[6] >> 32)] ^ T[5][(byte)(x[5] >> 40)] ^ T[6][(byte)(x[4] >> 48)] ^ T[7][(byte)(x[3] >> 56)];
201 y[3] = T[0][(byte)x[3]] ^ T[1][(byte)(x[2] >> 8)] ^ T[2][(byte)(x[1] >> 16)] ^ T[3][(byte)(x[0] >> 24)] ^
202 T[4][(byte)(x[7] >> 32)] ^ T[5][(byte)(x[6] >> 40)] ^ T[6][(byte)(x[5] >> 48)] ^ T[7][(byte)(x[4] >> 56)];
203 y[4] = T[0][(byte)x[4]] ^ T[1][(byte)(x[3] >> 8)] ^ T[2][(byte)(x[2] >> 16)] ^ T[3][(byte)(x[1] >> 24)] ^
204 T[4][(byte)(x[0] >> 32)] ^ T[5][(byte)(x[7] >> 40)] ^ T[6][(byte)(x[6] >> 48)] ^ T[7][(byte)(x[5] >> 56)];
205 y[5] = T[0][(byte)x[5]] ^ T[1][(byte)(x[4] >> 8)] ^ T[2][(byte)(x[3] >> 16)] ^ T[3][(byte)(x[2] >> 24)] ^
206 T[4][(byte)(x[1] >> 32)] ^ T[5][(byte)(x[0] >> 40)] ^ T[6][(byte)(x[7] >> 48)] ^ T[7][(byte)(x[6] >> 56)];
207 y[6] = T[0][(byte)x[6]] ^ T[1][(byte)(x[5] >> 8)] ^ T[2][(byte)(x[4] >> 16)] ^ T[3][(byte)(x[3] >> 24)] ^
208 T[4][(byte)(x[2] >> 32)] ^ T[5][(byte)(x[1] >> 40)] ^ T[6][(byte)(x[0] >> 48)] ^ T[7][(byte)(x[7] >> 56)];
209 y[7] = T[0][(byte)x[7]] ^ T[1][(byte)(x[6] >> 8)] ^ T[2][(byte)(x[5] >> 16)] ^ T[3][(byte)(x[4] >> 24)] ^
210 T[4][(byte)(x[3] >> 32)] ^ T[5][(byte)(x[2] >> 40)] ^ T[6][(byte)(x[1] >> 48)] ^ T[7][(byte)(x[0] >> 56)];
213 inline void GL128(
const word64 x[2], word64 y[2],
const word64 k[2])
215 y[0] = k[0] + (T[0][(byte)x[0]] ^ T[1][(byte)(x[0] >> 8)] ^ T[2][(byte)(x[0] >> 16)] ^ T[3][(byte)(x[0] >> 24)] ^
216 T[4][(byte)(x[1] >> 32)] ^ T[5][(byte)(x[1] >> 40)] ^ T[6][(byte)(x[1] >> 48)] ^ T[7][(byte)(x[1] >> 56)]);
217 y[1] = k[1] + (T[0][(byte)x[1]] ^ T[1][(byte)(x[1] >> 8)] ^ T[2][(byte)(x[1] >> 16)] ^ T[3][(byte)(x[1] >> 24)] ^
218 T[4][(byte)(x[0] >> 32)] ^ T[5][(byte)(x[0] >> 40)] ^ T[6][(byte)(x[0] >> 48)] ^ T[7][(byte)(x[0] >> 56)]);
221 inline void GL256(
const word64 x[4], word64 y[4],
const word64 k[4])
223 y[0] = k[0] + (T[0][(byte)x[0]] ^ T[1][(byte)(x[0] >> 8)] ^ T[2][(byte)(x[3] >> 16)] ^ T[3][(byte)(x[3] >> 24)] ^
224 T[4][(byte)(x[2] >> 32)] ^ T[5][(byte)(x[2] >> 40)] ^ T[6][(byte)(x[1] >> 48)] ^ T[7][(byte)(x[1] >> 56)]);
225 y[1] = k[1] + (T[0][(byte)x[1]] ^ T[1][(byte)(x[1] >> 8)] ^ T[2][(byte)(x[0] >> 16)] ^ T[3][(byte)(x[0] >> 24)] ^
226 T[4][(byte)(x[3] >> 32)] ^ T[5][(byte)(x[3] >> 40)] ^ T[6][(byte)(x[2] >> 48)] ^ T[7][(byte)(x[2] >> 56)]);
227 y[2] = k[2] + (T[0][(byte)x[2]] ^ T[1][(byte)(x[2] >> 8)] ^ T[2][(byte)(x[1] >> 16)] ^ T[3][(byte)(x[1] >> 24)] ^
228 T[4][(byte)(x[0] >> 32)] ^ T[5][(byte)(x[0] >> 40)] ^ T[6][(byte)(x[3] >> 48)] ^ T[7][(byte)(x[3] >> 56)]);
229 y[3] = k[3] + (T[0][(byte)x[3]] ^ T[1][(byte)(x[3] >> 8)] ^ T[2][(byte)(x[2] >> 16)] ^ T[3][(byte)(x[2] >> 24)] ^
230 T[4][(byte)(x[1] >> 32)] ^ T[5][(byte)(x[1] >> 40)] ^ T[6][(byte)(x[0] >> 48)] ^ T[7][(byte)(x[0] >> 56)]);
233 inline void GL512(
const word64 x[8], word64 y[8],
const word64 k[8])
235 y[0] = k[0] + (T[0][(byte)x[0]] ^ T[1][(byte)(x[7] >> 8)] ^ T[2][(byte)(x[6] >> 16)] ^ T[3][(byte)(x[5] >> 24)] ^
236 T[4][(byte)(x[4] >> 32)] ^ T[5][(byte)(x[3] >> 40)] ^ T[6][(byte)(x[2] >> 48)] ^ T[7][(byte)(x[1] >> 56)]);
237 y[1] = k[1] + (T[0][(byte)x[1]] ^ T[1][(byte)(x[0] >> 8)] ^ T[2][(byte)(x[7] >> 16)] ^ T[3][(byte)(x[6] >> 24)] ^
238 T[4][(byte)(x[5] >> 32)] ^ T[5][(byte)(x[4] >> 40)] ^ T[6][(byte)(x[3] >> 48)] ^ T[7][(byte)(x[2] >> 56)]);
239 y[2] = k[2] + (T[0][(byte)x[2]] ^ T[1][(byte)(x[1] >> 8)] ^ T[2][(byte)(x[0] >> 16)] ^ T[3][(byte)(x[7] >> 24)] ^
240 T[4][(byte)(x[6] >> 32)] ^ T[5][(byte)(x[5] >> 40)] ^ T[6][(byte)(x[4] >> 48)] ^ T[7][(byte)(x[3] >> 56)]);
241 y[3] = k[3] + (T[0][(byte)x[3]] ^ T[1][(byte)(x[2] >> 8)] ^ T[2][(byte)(x[1] >> 16)] ^ T[3][(byte)(x[0] >> 24)] ^
242 T[4][(byte)(x[7] >> 32)] ^ T[5][(byte)(x[6] >> 40)] ^ T[6][(byte)(x[5] >> 48)] ^ T[7][(byte)(x[4] >> 56)]);
243 y[4] = k[4] + (T[0][(byte)x[4]] ^ T[1][(byte)(x[3] >> 8)] ^ T[2][(byte)(x[2] >> 16)] ^ T[3][(byte)(x[1] >> 24)] ^
244 T[4][(byte)(x[0] >> 32)] ^ T[5][(byte)(x[7] >> 40)] ^ T[6][(byte)(x[6] >> 48)] ^ T[7][(byte)(x[5] >> 56)]);
245 y[5] = k[5] + (T[0][(byte)x[5]] ^ T[1][(byte)(x[4] >> 8)] ^ T[2][(byte)(x[3] >> 16)] ^ T[3][(byte)(x[2] >> 24)] ^
246 T[4][(byte)(x[1] >> 32)] ^ T[5][(byte)(x[0] >> 40)] ^ T[6][(byte)(x[7] >> 48)] ^ T[7][(byte)(x[6] >> 56)]);
247 y[6] = k[6] + (T[0][(byte)x[6]] ^ T[1][(byte)(x[5] >> 8)] ^ T[2][(byte)(x[4] >> 16)] ^ T[3][(byte)(x[3] >> 24)] ^
248 T[4][(byte)(x[2] >> 32)] ^ T[5][(byte)(x[1] >> 40)] ^ T[6][(byte)(x[0] >> 48)] ^ T[7][(byte)(x[7] >> 56)]);
249 y[7] = k[7] + (T[0][(byte)x[7]] ^ T[1][(byte)(x[6] >> 8)] ^ T[2][(byte)(x[5] >> 16)] ^ T[3][(byte)(x[4] >> 24)] ^
250 T[4][(byte)(x[3] >> 32)] ^ T[5][(byte)(x[2] >> 40)] ^ T[6][(byte)(x[1] >> 48)] ^ T[7][(byte)(x[0] >> 56)]);
253 inline void IMC128(word64 x[2])
255 x[0] = IT[0][S[0][(byte)x[0]]] ^ IT[1][S[1][(byte)(x[0] >> 8)]] ^ IT[2][S[2][(byte)(x[0] >> 16)]] ^ IT[3][S[3][(byte)(x[0] >> 24)]] ^
256 IT[4][S[0][(byte)(x[0] >> 32)]] ^ IT[5][S[1][(byte)(x[0] >> 40)]] ^ IT[6][S[2][(byte)(x[0] >> 48)]] ^ IT[7][S[3][(byte)(x[0] >> 56)]];
257 x[1] = IT[0][S[0][(byte)x[1]]] ^ IT[1][S[1][(byte)(x[1] >> 8)]] ^ IT[2][S[2][(byte)(x[1] >> 16)]] ^ IT[3][S[3][(byte)(x[1] >> 24)]] ^
258 IT[4][S[0][(byte)(x[1] >> 32)]] ^ IT[5][S[1][(byte)(x[1] >> 40)]] ^ IT[6][S[2][(byte)(x[1] >> 48)]] ^ IT[7][S[3][(byte)(x[1] >> 56)]];
261 inline void IMC256(word64 x[4])
263 x[0] = IT[0][S[0][(byte)x[0]]] ^ IT[1][S[1][(byte)(x[0] >> 8)]] ^ IT[2][S[2][(byte)(x[0] >> 16)]] ^ IT[3][S[3][(byte)(x[0] >> 24)]] ^
264 IT[4][S[0][(byte)(x[0] >> 32)]] ^ IT[5][S[1][(byte)(x[0] >> 40)]] ^ IT[6][S[2][(byte)(x[0] >> 48)]] ^ IT[7][S[3][(byte)(x[0] >> 56)]];
265 x[1] = IT[0][S[0][(byte)x[1]]] ^ IT[1][S[1][(byte)(x[1] >> 8)]] ^ IT[2][S[2][(byte)(x[1] >> 16)]] ^ IT[3][S[3][(byte)(x[1] >> 24)]] ^
266 IT[4][S[0][(byte)(x[1] >> 32)]] ^ IT[5][S[1][(byte)(x[1] >> 40)]] ^ IT[6][S[2][(byte)(x[1] >> 48)]] ^ IT[7][S[3][(byte)(x[1] >> 56)]];
267 x[2] = IT[0][S[0][(byte)x[2]]] ^ IT[1][S[1][(byte)(x[2] >> 8)]] ^ IT[2][S[2][(byte)(x[2] >> 16)]] ^ IT[3][S[3][(byte)(x[2] >> 24)]] ^
268 IT[4][S[0][(byte)(x[2] >> 32)]] ^ IT[5][S[1][(byte)(x[2] >> 40)]] ^ IT[6][S[2][(byte)(x[2] >> 48)]] ^ IT[7][S[3][(byte)(x[2] >> 56)]];
269 x[3] = IT[0][S[0][(byte)x[3]]] ^ IT[1][S[1][(byte)(x[3] >> 8)]] ^ IT[2][S[2][(byte)(x[3] >> 16)]] ^ IT[3][S[3][(byte)(x[3] >> 24)]] ^
270 IT[4][S[0][(byte)(x[3] >> 32)]] ^ IT[5][S[1][(byte)(x[3] >> 40)]] ^ IT[6][S[2][(byte)(x[3] >> 48)]] ^ IT[7][S[3][(byte)(x[3] >> 56)]];
273 inline void IMC512(word64 x[8])
275 x[0] = IT[0][S[0][(byte)x[0]]] ^ IT[1][S[1][(byte)(x[0] >> 8)]] ^ IT[2][S[2][(byte)(x[0] >> 16)]] ^ IT[3][S[3][(byte)(x[0] >> 24)]] ^
276 IT[4][S[0][(byte)(x[0] >> 32)]] ^ IT[5][S[1][(byte)(x[0] >> 40)]] ^ IT[6][S[2][(byte)(x[0] >> 48)]] ^ IT[7][S[3][(byte)(x[0] >> 56)]];
277 x[1] = IT[0][S[0][(byte)x[1]]] ^ IT[1][S[1][(byte)(x[1] >> 8)]] ^ IT[2][S[2][(byte)(x[1] >> 16)]] ^ IT[3][S[3][(byte)(x[1] >> 24)]] ^
278 IT[4][S[0][(byte)(x[1] >> 32)]] ^ IT[5][S[1][(byte)(x[1] >> 40)]] ^ IT[6][S[2][(byte)(x[1] >> 48)]] ^ IT[7][S[3][(byte)(x[1] >> 56)]];
279 x[2] = IT[0][S[0][(byte)x[2]]] ^ IT[1][S[1][(byte)(x[2] >> 8)]] ^ IT[2][S[2][(byte)(x[2] >> 16)]] ^ IT[3][S[3][(byte)(x[2] >> 24)]] ^
280 IT[4][S[0][(byte)(x[2] >> 32)]] ^ IT[5][S[1][(byte)(x[2] >> 40)]] ^ IT[6][S[2][(byte)(x[2] >> 48)]] ^ IT[7][S[3][(byte)(x[2] >> 56)]];
281 x[3] = IT[0][S[0][(byte)x[3]]] ^ IT[1][S[1][(byte)(x[3] >> 8)]] ^ IT[2][S[2][(byte)(x[3] >> 16)]] ^ IT[3][S[3][(byte)(x[3] >> 24)]] ^
282 IT[4][S[0][(byte)(x[3] >> 32)]] ^ IT[5][S[1][(byte)(x[3] >> 40)]] ^ IT[6][S[2][(byte)(x[3] >> 48)]] ^ IT[7][S[3][(byte)(x[3] >> 56)]];
283 x[4] = IT[0][S[0][(byte)x[4]]] ^ IT[1][S[1][(byte)(x[4] >> 8)]] ^ IT[2][S[2][(byte)(x[4] >> 16)]] ^ IT[3][S[3][(byte)(x[4] >> 24)]] ^
284 IT[4][S[0][(byte)(x[4] >> 32)]] ^ IT[5][S[1][(byte)(x[4] >> 40)]] ^ IT[6][S[2][(byte)(x[4] >> 48)]] ^ IT[7][S[3][(byte)(x[4] >> 56)]];
285 x[5] = IT[0][S[0][(byte)x[5]]] ^ IT[1][S[1][(byte)(x[5] >> 8)]] ^ IT[2][S[2][(byte)(x[5] >> 16)]] ^ IT[3][S[3][(byte)(x[5] >> 24)]] ^
286 IT[4][S[0][(byte)(x[5] >> 32)]] ^ IT[5][S[1][(byte)(x[5] >> 40)]] ^ IT[6][S[2][(byte)(x[5] >> 48)]] ^ IT[7][S[3][(byte)(x[5] >> 56)]];
287 x[6] = IT[0][S[0][(byte)x[6]]] ^ IT[1][S[1][(byte)(x[6] >> 8)]] ^ IT[2][S[2][(byte)(x[6] >> 16)]] ^ IT[3][S[3][(byte)(x[6] >> 24)]] ^
288 IT[4][S[0][(byte)(x[6] >> 32)]] ^ IT[5][S[1][(byte)(x[6] >> 40)]] ^ IT[6][S[2][(byte)(x[6] >> 48)]] ^ IT[7][S[3][(byte)(x[6] >> 56)]];
289 x[7] = IT[0][S[0][(byte)x[7]]] ^ IT[1][S[1][(byte)(x[7] >> 8)]] ^ IT[2][S[2][(byte)(x[7] >> 16)]] ^ IT[3][S[3][(byte)(x[7] >> 24)]] ^
290 IT[4][S[0][(byte)(x[7] >> 32)]] ^ IT[5][S[1][(byte)(x[7] >> 40)]] ^ IT[6][S[2][(byte)(x[7] >> 48)]] ^ IT[7][S[3][(byte)(x[7] >> 56)]];
293 inline void IG128(
const word64 x[2], word64 y[2],
const word64 k[2])
295 y[0] = k[0] ^ IT[0][(byte)x[0]] ^ IT[1][(byte)(x[0] >> 8)] ^ IT[2][(byte)(x[0] >> 16)] ^ IT[3][(byte)(x[0] >> 24)] ^
296 IT[4][(byte)(x[1] >> 32)] ^ IT[5][(byte)(x[1] >> 40)] ^ IT[6][(byte)(x[1] >> 48)] ^ IT[7][(byte)(x[1] >> 56)];
297 y[1] = k[1] ^ IT[0][(byte)x[1]] ^ IT[1][(byte)(x[1] >> 8)] ^ IT[2][(byte)(x[1] >> 16)] ^ IT[3][(byte)(x[1] >> 24)] ^
298 IT[4][(byte)(x[0] >> 32)] ^ IT[5][(byte)(x[0] >> 40)] ^ IT[6][(byte)(x[0] >> 48)] ^ IT[7][(byte)(x[0] >> 56)];
301 inline void IG256(
const word64 x[4], word64 y[4],
const word64 k[4])
303 y[0] = k[0] ^ IT[0][(byte)x[0]] ^ IT[1][(byte)(x[0] >> 8)] ^ IT[2][(byte)(x[1] >> 16)] ^ IT[3][(byte)(x[1] >> 24)] ^
304 IT[4][(byte)(x[2] >> 32)] ^ IT[5][(byte)(x[2] >> 40)] ^ IT[6][(byte)(x[3] >> 48)] ^ IT[7][(byte)(x[3] >> 56)];
305 y[1] = k[1] ^ IT[0][(byte)x[1]] ^ IT[1][(byte)(x[1] >> 8)] ^ IT[2][(byte)(x[2] >> 16)] ^ IT[3][(byte)(x[2] >> 24)] ^
306 IT[4][(byte)(x[3] >> 32)] ^ IT[5][(byte)(x[3] >> 40)] ^ IT[6][(byte)(x[0] >> 48)] ^ IT[7][(byte)(x[0] >> 56)];
307 y[2] = k[2] ^ IT[0][(byte)x[2]] ^ IT[1][(byte)(x[2] >> 8)] ^ IT[2][(byte)(x[3] >> 16)] ^ IT[3][(byte)(x[3] >> 24)] ^
308 IT[4][(byte)(x[0] >> 32)] ^ IT[5][(byte)(x[0] >> 40)] ^ IT[6][(byte)(x[1] >> 48)] ^ IT[7][(byte)(x[1] >> 56)];
309 y[3] = k[3] ^ IT[0][(byte)x[3]] ^ IT[1][(byte)(x[3] >> 8)] ^ IT[2][(byte)(x[0] >> 16)] ^ IT[3][(byte)(x[0] >> 24)] ^
310 IT[4][(byte)(x[1] >> 32)] ^ IT[5][(byte)(x[1] >> 40)] ^ IT[6][(byte)(x[2] >> 48)] ^ IT[7][(byte)(x[2] >> 56)];
313 inline void IG512(
const word64 x[8], word64 y[8],
const word64 k[8])
315 y[0] = k[0] ^ IT[0][(byte)x[0]] ^ IT[1][(byte)(x[1] >> 8)] ^ IT[2][(byte)(x[2] >> 16)] ^ IT[3][(byte)(x[3] >> 24)] ^
316 IT[4][(byte)(x[4] >> 32)] ^ IT[5][(byte)(x[5] >> 40)] ^ IT[6][(byte)(x[6] >> 48)] ^ IT[7][(byte)(x[7] >> 56)];
317 y[1] = k[1] ^ IT[0][(byte)x[1]] ^ IT[1][(byte)(x[2] >> 8)] ^ IT[2][(byte)(x[3] >> 16)] ^ IT[3][(byte)(x[4] >> 24)] ^
318 IT[4][(byte)(x[5] >> 32)] ^ IT[5][(byte)(x[6] >> 40)] ^ IT[6][(byte)(x[7] >> 48)] ^ IT[7][(byte)(x[0] >> 56)];
319 y[2] = k[2] ^ IT[0][(byte)x[2]] ^ IT[1][(byte)(x[3] >> 8)] ^ IT[2][(byte)(x[4] >> 16)] ^ IT[3][(byte)(x[5] >> 24)] ^
320 IT[4][(byte)(x[6] >> 32)] ^ IT[5][(byte)(x[7] >> 40)] ^ IT[6][(byte)(x[0] >> 48)] ^ IT[7][(byte)(x[1] >> 56)];
321 y[3] = k[3] ^ IT[0][(byte)x[3]] ^ IT[1][(byte)(x[4] >> 8)] ^ IT[2][(byte)(x[5] >> 16)] ^ IT[3][(byte)(x[6] >> 24)] ^
322 IT[4][(byte)(x[7] >> 32)] ^ IT[5][(byte)(x[0] >> 40)] ^ IT[6][(byte)(x[1] >> 48)] ^ IT[7][(byte)(x[2] >> 56)];
323 y[4] = k[4] ^ IT[0][(byte)x[4]] ^ IT[1][(byte)(x[5] >> 8)] ^ IT[2][(byte)(x[6] >> 16)] ^ IT[3][(byte)(x[7] >> 24)] ^
324 IT[4][(byte)(x[0] >> 32)] ^ IT[5][(byte)(x[1] >> 40)] ^ IT[6][(byte)(x[2] >> 48)] ^ IT[7][(byte)(x[3] >> 56)];
325 y[5] = k[5] ^ IT[0][(byte)x[5]] ^ IT[1][(byte)(x[6] >> 8)] ^ IT[2][(byte)(x[7] >> 16)] ^ IT[3][(byte)(x[0] >> 24)] ^
326 IT[4][(byte)(x[1] >> 32)] ^ IT[5][(byte)(x[2] >> 40)] ^ IT[6][(byte)(x[3] >> 48)] ^ IT[7][(byte)(x[4] >> 56)];
327 y[6] = k[6] ^ IT[0][(byte)x[6]] ^ IT[1][(byte)(x[7] >> 8)] ^ IT[2][(byte)(x[0] >> 16)] ^ IT[3][(byte)(x[1] >> 24)] ^
328 IT[4][(byte)(x[2] >> 32)] ^ IT[5][(byte)(x[3] >> 40)] ^ IT[6][(byte)(x[4] >> 48)] ^ IT[7][(byte)(x[5] >> 56)];
329 y[7] = k[7] ^ IT[0][(byte)x[7]] ^ IT[1][(byte)(x[0] >> 8)] ^ IT[2][(byte)(x[1] >> 16)] ^ IT[3][(byte)(x[2] >> 24)] ^
330 IT[4][(byte)(x[3] >> 32)] ^ IT[5][(byte)(x[4] >> 40)] ^ IT[6][(byte)(x[5] >> 48)] ^ IT[7][(byte)(x[6] >> 56)];
333 inline void IGL128(
const word64 x[2], word64 y[2],
const word64 k[2])
335 y[0] = (word64(IS[0][(byte)x[0]]) ^ word64(IS[1][(byte)(x[0] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[0] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[0] >> 24)]) << 24 ^
336 word64(IS[0][(byte)(x[1] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[1] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[1] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[1] >> 56)]) << 56) - k[0];
337 y[1] = (word64(IS[0][(byte)x[1]]) ^ word64(IS[1][(byte)(x[1] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[1] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[1] >> 24)]) << 24 ^
338 word64(IS[0][(byte)(x[0] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[0] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[0] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[0] >> 56)]) << 56) - k[1];
341 inline void IGL256(
const word64 x[4], word64 y[4],
const word64 k[4])
343 y[0] = (word64(IS[0][(byte)x[0]]) ^ word64(IS[1][(byte)(x[0] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[1] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[1] >> 24)]) << 24 ^
344 word64(IS[0][(byte)(x[2] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[2] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[3] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[3] >> 56)]) << 56) - k[0];
345 y[1] = (word64(IS[0][(byte)x[1]]) ^ word64(IS[1][(byte)(x[1] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[2] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[2] >> 24)]) << 24 ^
346 word64(IS[0][(byte)(x[3] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[3] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[0] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[0] >> 56)]) << 56) - k[1];
347 y[2] = (word64(IS[0][(byte)x[2]]) ^ word64(IS[1][(byte)(x[2] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[3] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[3] >> 24)]) << 24 ^
348 word64(IS[0][(byte)(x[0] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[0] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[1] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[1] >> 56)]) << 56) - k[2];
349 y[3] = (word64(IS[0][(byte)x[3]]) ^ word64(IS[1][(byte)(x[3] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[0] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[0] >> 24)]) << 24 ^
350 word64(IS[0][(byte)(x[1] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[1] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[2] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[2] >> 56)]) << 56) - k[3];
353 inline void IGL512(
const word64 x[8], word64 y[8],
const word64 k[8])
355 y[0] = (word64(IS[0][(byte)x[0]]) ^ word64(IS[1][(byte)(x[1] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[2] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[3] >> 24)]) << 24 ^
356 word64(IS[0][(byte)(x[4] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[5] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[6] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[7] >> 56)]) << 56) - k[0];
357 y[1] = (word64(IS[0][(byte)x[1]]) ^ word64(IS[1][(byte)(x[2] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[3] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[4] >> 24)]) << 24 ^
358 word64(IS[0][(byte)(x[5] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[6] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[7] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[0] >> 56)]) << 56) - k[1];
359 y[2] = (word64(IS[0][(byte)x[2]]) ^ word64(IS[1][(byte)(x[3] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[4] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[5] >> 24)]) << 24 ^
360 word64(IS[0][(byte)(x[6] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[7] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[0] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[1] >> 56)]) << 56) - k[2];
361 y[3] = (word64(IS[0][(byte)x[3]]) ^ word64(IS[1][(byte)(x[4] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[5] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[6] >> 24)]) << 24 ^
362 word64(IS[0][(byte)(x[7] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[0] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[1] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[2] >> 56)]) << 56) - k[3];
363 y[4] = (word64(IS[0][(byte)x[4]]) ^ word64(IS[1][(byte)(x[5] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[6] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[7] >> 24)]) << 24 ^
364 word64(IS[0][(byte)(x[0] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[1] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[2] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[3] >> 56)]) << 56) - k[4];
365 y[5] = (word64(IS[0][(byte)x[5]]) ^ word64(IS[1][(byte)(x[6] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[7] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[0] >> 24)]) << 24 ^
366 word64(IS[0][(byte)(x[1] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[2] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[3] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[4] >> 56)]) << 56) - k[5];
367 y[6] = (word64(IS[0][(byte)x[6]]) ^ word64(IS[1][(byte)(x[7] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[0] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[1] >> 24)]) << 24 ^
368 word64(IS[0][(byte)(x[2] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[3] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[4] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[5] >> 56)]) << 56) - k[6];
369 y[7] = (word64(IS[0][(byte)x[7]]) ^ word64(IS[1][(byte)(x[0] >> 8)]) << 8 ^ word64(IS[2][(byte)(x[1] >> 16)]) << 16 ^ word64(IS[3][(byte)(x[2] >> 24)]) << 24 ^
370 word64(IS[0][(byte)(x[3] >> 32)]) << 32 ^ word64(IS[1][(byte)(x[4] >> 40)]) << 40 ^ word64(IS[2][(byte)(x[5] >> 48)]) << 48 ^ word64(IS[3][(byte)(x[6] >> 56)]) << 56) - k[7];
373 inline void G128(
const word64 x[2], word64 y[2],
const word64 k[2])
375 y[0] = k[0] ^ T[0][(byte)x[0]] ^ T[1][(byte)(x[0] >> 8)] ^ T[2][(byte)(x[0] >> 16)] ^ T[3][(byte)(x[0] >> 24)] ^
376 T[4][(byte)(x[1] >> 32)] ^ T[5][(byte)(x[1] >> 40)] ^ T[6][(byte)(x[1] >> 48)] ^ T[7][(byte)(x[1] >> 56)];
377 y[1] = k[1] ^ T[0][(byte)x[1]] ^ T[1][(byte)(x[1] >> 8)] ^ T[2][(byte)(x[1] >> 16)] ^ T[3][(byte)(x[1] >> 24)] ^
378 T[4][(byte)(x[0] >> 32)] ^ T[5][(byte)(x[0] >> 40)] ^ T[6][(byte)(x[0] >> 48)] ^ T[7][(byte)(x[0] >> 56)];
381 inline void G256(
const word64 x[4], word64 y[4],
const word64 k[4])
383 y[0] = k[0] ^ T[0][(byte)x[0]] ^ T[1][(byte)(x[0] >> 8)] ^ T[2][(byte)(x[3] >> 16)] ^ T[3][(byte)(x[3] >> 24)] ^
384 T[4][(byte)(x[2] >> 32)] ^ T[5][(byte)(x[2] >> 40)] ^ T[6][(byte)(x[1] >> 48)] ^ T[7][(byte)(x[1] >> 56)];
385 y[1] = k[1] ^ T[0][(byte)x[1]] ^ T[1][(byte)(x[1] >> 8)] ^ T[2][(byte)(x[0] >> 16)] ^ T[3][(byte)(x[0] >> 24)] ^
386 T[4][(byte)(x[3] >> 32)] ^ T[5][(byte)(x[3] >> 40)] ^ T[6][(byte)(x[2] >> 48)] ^ T[7][(byte)(x[2] >> 56)];
387 y[2] = k[2] ^ T[0][(byte)x[2]] ^ T[1][(byte)(x[2] >> 8)] ^ T[2][(byte)(x[1] >> 16)] ^ T[3][(byte)(x[1] >> 24)] ^
388 T[4][(byte)(x[0] >> 32)] ^ T[5][(byte)(x[0] >> 40)] ^ T[6][(byte)(x[3] >> 48)] ^ T[7][(byte)(x[3] >> 56)];
389 y[3] = k[3] ^ T[0][(byte)x[3]] ^ T[1][(byte)(x[3] >> 8)] ^ T[2][(byte)(x[2] >> 16)] ^ T[3][(byte)(x[2] >> 24)] ^
390 T[4][(byte)(x[1] >> 32)] ^ T[5][(byte)(x[1] >> 40)] ^ T[6][(byte)(x[0] >> 48)] ^ T[7][(byte)(x[0] >> 56)];
393 inline void G512(
const word64 x[8], word64 y[8],
const word64 k[8])
395 y[0] = k[0] ^ T[0][(byte)x[0]] ^ T[1][(byte)(x[7] >> 8)] ^ T[2][(byte)(x[6] >> 16)] ^ T[3][(byte)(x[5] >> 24)] ^
396 T[4][(byte)(x[4] >> 32)] ^ T[5][(byte)(x[3] >> 40)] ^ T[6][(byte)(x[2] >> 48)] ^ T[7][(byte)(x[1] >> 56)];
397 y[1] = k[1] ^ T[0][(byte)x[1]] ^ T[1][(byte)(x[0] >> 8)] ^ T[2][(byte)(x[7] >> 16)] ^ T[3][(byte)(x[6] >> 24)] ^
398 T[4][(byte)(x[5] >> 32)] ^ T[5][(byte)(x[4] >> 40)] ^ T[6][(byte)(x[3] >> 48)] ^ T[7][(byte)(x[2] >> 56)];
399 y[2] = k[2] ^ T[0][(byte)x[2]] ^ T[1][(byte)(x[1] >> 8)] ^ T[2][(byte)(x[0] >> 16)] ^ T[3][(byte)(x[7] >> 24)] ^
400 T[4][(byte)(x[6] >> 32)] ^ T[5][(byte)(x[5] >> 40)] ^ T[6][(byte)(x[4] >> 48)] ^ T[7][(byte)(x[3] >> 56)];
401 y[3] = k[3] ^ T[0][(byte)x[3]] ^ T[1][(byte)(x[2] >> 8)] ^ T[2][(byte)(x[1] >> 16)] ^ T[3][(byte)(x[0] >> 24)] ^
402 T[4][(byte)(x[7] >> 32)] ^ T[5][(byte)(x[6] >> 40)] ^ T[6][(byte)(x[5] >> 48)] ^ T[7][(byte)(x[4] >> 56)];
403 y[4] = k[4] ^ T[0][(byte)x[4]] ^ T[1][(byte)(x[3] >> 8)] ^ T[2][(byte)(x[2] >> 16)] ^ T[3][(byte)(x[1] >> 24)] ^
404 T[4][(byte)(x[0] >> 32)] ^ T[5][(byte)(x[7] >> 40)] ^ T[6][(byte)(x[6] >> 48)] ^ T[7][(byte)(x[5] >> 56)];
405 y[5] = k[5] ^ T[0][(byte)x[5]] ^ T[1][(byte)(x[4] >> 8)] ^ T[2][(byte)(x[3] >> 16)] ^ T[3][(byte)(x[2] >> 24)] ^
406 T[4][(byte)(x[1] >> 32)] ^ T[5][(byte)(x[0] >> 40)] ^ T[6][(byte)(x[7] >> 48)] ^ T[7][(byte)(x[6] >> 56)];
407 y[6] = k[6] ^ T[0][(byte)x[6]] ^ T[1][(byte)(x[5] >> 8)] ^ T[2][(byte)(x[4] >> 16)] ^ T[3][(byte)(x[3] >> 24)] ^
408 T[4][(byte)(x[2] >> 32)] ^ T[5][(byte)(x[1] >> 40)] ^ T[6][(byte)(x[0] >> 48)] ^ T[7][(byte)(x[7] >> 56)];
409 y[7] = k[7] ^ T[0][(byte)x[7]] ^ T[1][(byte)(x[6] >> 8)] ^ T[2][(byte)(x[5] >> 16)] ^ T[3][(byte)(x[4] >> 24)] ^
410 T[4][(byte)(x[3] >> 32)] ^ T[5][(byte)(x[2] >> 40)] ^ T[6][(byte)(x[1] >> 48)] ^ T[7][(byte)(x[0] >> 56)];
413 ANONYMOUS_NAMESPACE_END
419 void Kalyna128::Base::SetKey_22(
const word64 key[2])
421 word64 *ks = m_wspace+0, *ksc = m_wspace+2, *t1 = m_wspace+4;
422 word64 *t2 = m_wspace+6, *k = m_wspace+8, *kswapped = m_wspace+10;
425 t1[0] = (128 + 128 + 64) / 64;
427 AddKey<2>(t1, t2, key);
432 word64 constant = W64LIT(0x0001000100010001);
439 AddConstant<2>(ks, ksc, constant);
440 AddKey<2>(k, t2, ksc);
442 GL128(t1, &m_rkeys[0], ksc);
443 MakeOddKey<2>(&m_rkeys[0], &m_rkeys[2]);
447 AddConstant<2>(ks, ksc, constant);
448 AddKey<2>(kswapped, t2, ksc);
450 GL128(t1, &m_rkeys[4], ksc);
451 MakeOddKey<2>(&m_rkeys[4], &m_rkeys[6]);
455 AddConstant<2>(ks, ksc, constant);
456 AddKey<2>(k, t2, ksc);
458 GL128(t1, &m_rkeys[8], ksc);
459 MakeOddKey<2>(&m_rkeys[8], &m_rkeys[10]);
463 AddConstant<2>(ks, ksc, constant);
464 AddKey<2>(kswapped, t2, ksc);
466 GL128(t1, &m_rkeys[12], ksc);
467 MakeOddKey<2>(&m_rkeys[12], &m_rkeys[14]);
471 AddConstant<2>(ks, ksc, constant);
472 AddKey<2>(k, t2, ksc);
474 GL128(t1, &m_rkeys[16], ksc);
475 MakeOddKey<2>(&m_rkeys[16], &m_rkeys[18]);
479 AddConstant<2>(ks, ksc, constant);
480 AddKey<2>(kswapped, t2, ksc);
482 GL128(t1, &m_rkeys[20], ksc);
484 if (!IsForwardTransformation())
486 IMC128(&m_rkeys[18]); IMC128(&m_rkeys[16]);
487 IMC128(&m_rkeys[14]); IMC128(&m_rkeys[12]);
488 IMC128(&m_rkeys[10]); IMC128(&m_rkeys[ 8]);
489 IMC128(&m_rkeys[ 6]); IMC128(&m_rkeys[ 4]);
490 IMC128(&m_rkeys[ 2]);
494 void Kalyna128::Base::SetKey_24(
const word64 key[4])
496 word64 *ks = m_wspace+0, *ksc = m_wspace+2, *t1 = m_wspace+4, *t2 = m_wspace+6;
497 word64 *k = m_wspace+8, *ka = m_wspace+12, *ko = m_wspace+14;
500 t1[0] = (128 + 256 + 64) / 64;
502 memcpy(ko, key + 2, 16);
504 AddKey<2>(t1, t2, ka);
509 word64 constant = W64LIT(0x0001000100010001);
512 memcpy(k, key, 256 / 8);
513 AddConstant<2>(ks, ksc, constant);
514 AddKey<2>(k, t2, ksc);
516 GL128(t1, &m_rkeys[0], ksc);
517 MakeOddKey<2>(&m_rkeys[0], &m_rkeys[2]);
521 AddConstant<2>(ks, ksc, constant);
522 AddKey<2>(k + 2, t2, ksc);
524 GL128(t1, &m_rkeys[4], ksc);
525 MakeOddKey<2>(&m_rkeys[4], &m_rkeys[6]);
530 AddConstant<2>(ks, ksc, constant);
531 AddKey<2>(k, t2, ksc);
533 GL128(t1, &m_rkeys[8], ksc);
534 MakeOddKey<2>(&m_rkeys[8], &m_rkeys[10]);
538 AddConstant<2>(ks, ksc, constant);
539 AddKey<2>(k + 2, t2, ksc);
541 GL128(t1, &m_rkeys[12], ksc);
542 MakeOddKey<2>(&m_rkeys[12], &m_rkeys[14]);
547 AddConstant<2>(ks, ksc, constant);
548 AddKey<2>(k, t2, ksc);
550 GL128(t1, &m_rkeys[16], ksc);
551 MakeOddKey<2>(&m_rkeys[16], &m_rkeys[18]);
555 AddConstant<2>(ks, ksc, constant);
556 AddKey<2>(k + 2, t2, ksc);
558 GL128(t1, &m_rkeys[20], ksc);
559 MakeOddKey<2>(&m_rkeys[20], &m_rkeys[22]);
564 AddConstant<2>(ks, ksc, constant);
565 AddKey<2>(k, t2, ksc);
567 GL128(t1, &m_rkeys[24], ksc);
568 MakeOddKey<2>(&m_rkeys[24], &m_rkeys[26]);
572 AddConstant<2>(ks, ksc, constant);
573 AddKey<2>(k + 2, t2, ksc);
575 GL128(t1, &m_rkeys[28], ksc);
577 if (!IsForwardTransformation())
579 IMC128(&m_rkeys[26]);
580 IMC128(&m_rkeys[24]);
581 IMC128(&m_rkeys[22]);
582 IMC128(&m_rkeys[20]);
583 IMC128(&m_rkeys[18]);
584 IMC128(&m_rkeys[16]);
585 IMC128(&m_rkeys[14]);
586 IMC128(&m_rkeys[12]);
587 IMC128(&m_rkeys[10]);
595 void Kalyna256::Base::SetKey_44(
const word64 key[4])
597 word64 *ks = m_wspace+0, *ksc = m_wspace+4, *t1 = m_wspace+8;
598 word64 *t2 = m_wspace+12, *k = m_wspace+16;
601 t1[0] = (256 + 256 + 64) / 64;
603 AddKey<4>(t1, t2, key);
608 word64 constant = W64LIT(0x0001000100010001);
612 AddConstant<4>(ks, ksc, constant);
613 AddKey<4>(k, t2, ksc);
615 GL256(t1, &m_rkeys[0], ksc);
616 MakeOddKey<4>(&m_rkeys[0], &m_rkeys[4]);
621 AddConstant<4>(ks, ksc, constant);
622 AddKey<4>(k, t2, ksc);
624 GL256(t1, &m_rkeys[8], ksc);
625 MakeOddKey<4>(&m_rkeys[8], &m_rkeys[12]);
630 AddConstant<4>(ks, ksc, constant);
631 AddKey<4>(k, t2, ksc);
633 GL256(t1, &m_rkeys[16], ksc);
634 MakeOddKey<4>(&m_rkeys[16], &m_rkeys[20]);
639 AddConstant<4>(ks, ksc, constant);
640 AddKey<4>(k, t2, ksc);
642 GL256(t1, &m_rkeys[24], ksc);
643 MakeOddKey<4>(&m_rkeys[24], &m_rkeys[28]);
648 AddConstant<4>(ks, ksc, constant);
649 AddKey<4>(k, t2, ksc);
651 GL256(t1, &m_rkeys[32], ksc);
652 MakeOddKey<4>(&m_rkeys[32], &m_rkeys[36]);
657 AddConstant<4>(ks, ksc, constant);
658 AddKey<4>(k, t2, ksc);
660 GL256(t1, &m_rkeys[40], ksc);
661 MakeOddKey<4>(&m_rkeys[40], &m_rkeys[44]);
666 AddConstant<4>(ks, ksc, constant);
667 AddKey<4>(k, t2, ksc);
669 GL256(t1, &m_rkeys[48], ksc);
670 MakeOddKey<4>(&m_rkeys[48], &m_rkeys[52]);
675 AddConstant<4>(ks, ksc, constant);
676 AddKey<4>(k, t2, ksc);
678 GL256(t1, &m_rkeys[56], ksc);
680 if (!IsForwardTransformation())
682 IMC256(&m_rkeys[52]);
683 IMC256(&m_rkeys[48]);
684 IMC256(&m_rkeys[44]);
685 IMC256(&m_rkeys[40]);
686 IMC256(&m_rkeys[36]);
687 IMC256(&m_rkeys[32]);
688 IMC256(&m_rkeys[28]);
689 IMC256(&m_rkeys[24]);
690 IMC256(&m_rkeys[20]);
691 IMC256(&m_rkeys[16]);
692 IMC256(&m_rkeys[12]);
698 void Kalyna256::Base::SetKey_48(
const word64 key[8])
700 word64 *ks = m_wspace+0, *ksc = m_wspace+4, *t1 = m_wspace+8, *t2 = m_wspace+12;
701 word64 *k = m_wspace+16, *ka = m_wspace+24, *ko = m_wspace+28;
704 t1[0] = (512 + 256 + 64) / 64;
706 memcpy(ko, key+4, 32);
708 AddKey<4>(t1, t2, ka);
713 word64 constant = W64LIT(0x0001000100010001);
716 memcpy(k, key, 512 / 8);
717 AddConstant<4>(ks, ksc, constant);
718 AddKey<4>(k, t2, ksc);
720 GL256(t1, &m_rkeys[0], ksc);
721 MakeOddKey<4>(&m_rkeys[0], &m_rkeys[4]);
725 AddConstant<4>(ks, ksc, constant);
726 AddKey<4>(k+4, t2, ksc);
728 GL256(t1, &m_rkeys[8], ksc);
729 MakeOddKey<4>(&m_rkeys[8], &m_rkeys[12]);
734 AddConstant<4>(ks, ksc, constant);
735 AddKey<4>(k, t2, ksc);
737 GL256(t1, &m_rkeys[16], ksc);
738 MakeOddKey<4>(&m_rkeys[16], &m_rkeys[20]);
742 AddConstant<4>(ks, ksc, constant);
743 AddKey<4>(k+4, t2, ksc);
745 GL256(t1, &m_rkeys[24], ksc);
746 MakeOddKey<4>(&m_rkeys[24], &m_rkeys[28]);
751 AddConstant<4>(ks, ksc, constant);
752 AddKey<4>(k, t2, ksc);
754 GL256(t1, &m_rkeys[32], ksc);
755 MakeOddKey<4>(&m_rkeys[32], &m_rkeys[36]);
759 AddConstant<4>(ks, ksc, constant);
760 AddKey<4>(k+4, t2, ksc);
762 GL256(t1, &m_rkeys[40], ksc);
763 MakeOddKey<4>(&m_rkeys[40], &m_rkeys[44]);
768 AddConstant<4>(ks, ksc, constant);
769 AddKey<4>(k, t2, ksc);
771 GL256(t1, &m_rkeys[48], ksc);
772 MakeOddKey<4>(&m_rkeys[48], &m_rkeys[52]);
776 AddConstant<4>(ks, ksc, constant);
777 AddKey<4>(k+4, t2, ksc);
779 GL256(t1, &m_rkeys[56], ksc);
780 MakeOddKey<4>(&m_rkeys[56], &m_rkeys[60]);
785 AddConstant<4>(ks, ksc, constant);
786 AddKey<4>(k, t2, ksc);
788 GL256(t1, &m_rkeys[64], ksc);
789 MakeOddKey<4>(&m_rkeys[64], &m_rkeys[68]);
793 AddConstant<4>(ks, ksc, constant);
794 AddKey<4>(k+4, t2, ksc);
796 GL256(t1, &m_rkeys[72], ksc);
798 if (!IsForwardTransformation())
800 IMC256(&m_rkeys[68]);
801 IMC256(&m_rkeys[64]);
802 IMC256(&m_rkeys[60]);
803 IMC256(&m_rkeys[56]);
804 IMC256(&m_rkeys[52]);
805 IMC256(&m_rkeys[48]);
806 IMC256(&m_rkeys[44]);
807 IMC256(&m_rkeys[40]);
808 IMC256(&m_rkeys[36]);
809 IMC256(&m_rkeys[32]);
810 IMC256(&m_rkeys[28]);
811 IMC256(&m_rkeys[24]);
812 IMC256(&m_rkeys[20]);
813 IMC256(&m_rkeys[16]);
814 IMC256(&m_rkeys[12]);
820 void Kalyna512::Base::SetKey_88(
const word64 key[8])
822 word64 *ks = m_wspace+0, *ksc = m_wspace+8, *t1 = m_wspace+16;
823 word64 *t2 = m_wspace+24, *k = m_wspace+32;
826 t1[0] = (512 + 512 + 64) / 64;
828 AddKey<8>(t1, t2, key);
833 word64 constant = W64LIT(0x0001000100010001);
836 memcpy(k, key, 512 / 8);
837 AddConstant<8>(ks, ksc, constant);
838 AddKey<8>(k, t2, ksc);
840 GL512(t1, &m_rkeys[0], ksc);
841 MakeOddKey<8>(&m_rkeys[0], &m_rkeys[8]);
846 AddConstant<8>(ks, ksc, constant);
847 AddKey<8>(k, t2, ksc);
849 GL512(t1, &m_rkeys[16], ksc);
850 MakeOddKey<8>(&m_rkeys[16], &m_rkeys[24]);
855 AddConstant<8>(ks, ksc, constant);
856 AddKey<8>(k, t2, ksc);
858 GL512(t1, &m_rkeys[32], ksc);
859 MakeOddKey<8>(&m_rkeys[32], &m_rkeys[40]);
864 AddConstant<8>(ks, ksc, constant);
865 AddKey<8>(k, t2, ksc);
867 GL512(t1, &m_rkeys[48], ksc);
868 MakeOddKey<8>(&m_rkeys[48], &m_rkeys[56]);
873 AddConstant<8>(ks, ksc, constant);
874 AddKey<8>(k, t2, ksc);
876 GL512(t1, &m_rkeys[64], ksc);
877 MakeOddKey<8>(&m_rkeys[64], &m_rkeys[72]);
882 AddConstant<8>(ks, ksc, constant);
883 AddKey<8>(k, t2, ksc);
885 GL512(t1, &m_rkeys[80], ksc);
886 MakeOddKey<8>(&m_rkeys[80], &m_rkeys[88]);
891 AddConstant<8>(ks, ksc, constant);
892 AddKey<8>(k, t2, ksc);
894 GL512(t1, &m_rkeys[96], ksc);
895 MakeOddKey<8>(&m_rkeys[96], &m_rkeys[104]);
900 AddConstant<8>(ks, ksc, constant);
901 AddKey<8>(k, t2, ksc);
903 GL512(t1, &m_rkeys[112], ksc);
904 MakeOddKey<8>(&m_rkeys[112], &m_rkeys[120]);
909 AddConstant<8>(ks, ksc, constant);
910 AddKey<8>(k, t2, ksc);
912 GL512(t1, &m_rkeys[128], ksc);
913 MakeOddKey<8>(&m_rkeys[128], &m_rkeys[136]);
918 AddConstant<8>(ks, ksc, constant);
919 AddKey<8>(k, t2, ksc);
921 GL512(t1, &m_rkeys[144], ksc);
923 if (!IsForwardTransformation())
925 IMC512(&m_rkeys[136]); IMC512(&m_rkeys[128]); IMC512(&m_rkeys[120]); IMC512(&m_rkeys[112]);
926 IMC512(&m_rkeys[104]); IMC512(&m_rkeys[ 96]); IMC512(&m_rkeys[ 88]); IMC512(&m_rkeys[ 80]);
927 IMC512(&m_rkeys[ 72]); IMC512(&m_rkeys[ 64]); IMC512(&m_rkeys[ 56]); IMC512(&m_rkeys[ 48]);
928 IMC512(&m_rkeys[ 40]); IMC512(&m_rkeys[ 32]); IMC512(&m_rkeys[ 24]); IMC512(&m_rkeys[ 16]);
929 IMC512(&m_rkeys[ 8]);
935 void Kalyna128::Base::ProcessBlock_22(
const word64 inBlock[2],
const word64 xorBlock[2], word64 outBlock[2])
const 937 word64 *t1 = m_wspace+0, *t2 = m_wspace+2, *msg = m_wspace+4;
941 InBlock iblk(inBlock);
942 iblk(msg[0])(msg[1]);
945 if (IsForwardTransformation())
947 AddKey<2>(inBlock, t1, m_rkeys);
948 G128(t1, t2, &m_rkeys[2]);
949 G128(t2, t1, &m_rkeys[4]);
950 G128(t1, t2, &m_rkeys[6]);
951 G128(t2, t1, &m_rkeys[8]);
952 G128(t1, t2, &m_rkeys[10]);
953 G128(t2, t1, &m_rkeys[12]);
954 G128(t1, t2, &m_rkeys[14]);
955 G128(t2, t1, &m_rkeys[16]);
956 G128(t1, t2, &m_rkeys[18]);
957 GL128(t2, t1, &m_rkeys[20]);
961 SubKey<2>(inBlock, t1, &m_rkeys[20]);
963 IG128(t1, t2, &m_rkeys[18]);
964 IG128(t2, t1, &m_rkeys[16]);
965 IG128(t1, t2, &m_rkeys[14]);
966 IG128(t2, t1, &m_rkeys[12]);
967 IG128(t1, t2, &m_rkeys[10]);
968 IG128(t2, t1, &m_rkeys[8]);
969 IG128(t1, t2, &m_rkeys[6]);
970 IG128(t2, t1, &m_rkeys[4]);
971 IG128(t1, t2, &m_rkeys[2]);
972 IGL128(t2, t1, &m_rkeys[0]);
977 OutBlock oblk(xorBlock, outBlock);
981 void Kalyna128::Base::ProcessBlock_24(
const word64 inBlock[2],
const word64 xorBlock[2], word64 outBlock[2])
const 983 word64 *t1 = m_wspace+0, *t2 = m_wspace+2, *msg = m_wspace+4;
987 InBlock iblk(inBlock);
988 iblk(msg[0])(msg[1]);
991 if (IsForwardTransformation())
993 AddKey<2>(inBlock, t1, m_rkeys);
994 G128(t1, t2, &m_rkeys[ 2]);
995 G128(t2, t1, &m_rkeys[ 4]);
996 G128(t1, t2, &m_rkeys[ 6]);
997 G128(t2, t1, &m_rkeys[ 8]);
998 G128(t1, t2, &m_rkeys[10]);
999 G128(t2, t1, &m_rkeys[12]);
1000 G128(t1, t2, &m_rkeys[14]);
1001 G128(t2, t1, &m_rkeys[16]);
1002 G128(t1, t2, &m_rkeys[18]);
1003 G128(t2, t1, &m_rkeys[20]);
1004 G128(t1, t2, &m_rkeys[22]);
1005 G128(t2, t1, &m_rkeys[24]);
1006 G128(t1, t2, &m_rkeys[26]);
1007 GL128(t2, t1, &m_rkeys[28]);
1011 SubKey<2>(inBlock, t1, &m_rkeys[28]);
1013 IG128(t1, t2, &m_rkeys[26]);
1014 IG128(t2, t1, &m_rkeys[24]);
1015 IG128(t1, t2, &m_rkeys[22]);
1016 IG128(t2, t1, &m_rkeys[20]);
1017 IG128(t1, t2, &m_rkeys[18]);
1018 IG128(t2, t1, &m_rkeys[16]);
1019 IG128(t1, t2, &m_rkeys[14]);
1020 IG128(t2, t1, &m_rkeys[12]);
1021 IG128(t1, t2, &m_rkeys[10]);
1022 IG128(t2, t1, &m_rkeys[8]);
1023 IG128(t1, t2, &m_rkeys[6]);
1024 IG128(t2, t1, &m_rkeys[4]);
1025 IG128(t1, t2, &m_rkeys[2]);
1026 IGL128(t2, t1, &m_rkeys[0]);
1031 OutBlock oblk(xorBlock, outBlock);
1035 void Kalyna256::Base::ProcessBlock_44(
const word64 inBlock[4],
const word64 xorBlock[4], word64 outBlock[4])
const 1037 word64 *t1 = m_wspace+0, *t2 = m_wspace+4, *msg = m_wspace+8;
1041 InBlock iblk(inBlock);
1042 iblk(msg[0])(msg[1])(msg[2])(msg[3]);
1045 if (IsForwardTransformation())
1047 AddKey<4>(inBlock, t1, m_rkeys);
1048 G256(t1, t2, &m_rkeys[4]);
1049 G256(t2, t1, &m_rkeys[8]);
1050 G256(t1, t2, &m_rkeys[12]);
1051 G256(t2, t1, &m_rkeys[16]);
1052 G256(t1, t2, &m_rkeys[20]);
1053 G256(t2, t1, &m_rkeys[24]);
1054 G256(t1, t2, &m_rkeys[28]);
1055 G256(t2, t1, &m_rkeys[32]);
1056 G256(t1, t2, &m_rkeys[36]);
1057 G256(t2, t1, &m_rkeys[40]);
1058 G256(t1, t2, &m_rkeys[44]);
1059 G256(t2, t1, &m_rkeys[48]);
1060 G256(t1, t2, &m_rkeys[52]);
1061 GL256(t2, t1, &m_rkeys[56]);
1065 SubKey<4>(inBlock, t1, &m_rkeys[56]);
1067 IG256(t1, t2, &m_rkeys[52]);
1068 IG256(t2, t1, &m_rkeys[48]);
1069 IG256(t1, t2, &m_rkeys[44]);
1070 IG256(t2, t1, &m_rkeys[40]);
1071 IG256(t1, t2, &m_rkeys[36]);
1072 IG256(t2, t1, &m_rkeys[32]);
1073 IG256(t1, t2, &m_rkeys[28]);
1074 IG256(t2, t1, &m_rkeys[24]);
1075 IG256(t1, t2, &m_rkeys[20]);
1076 IG256(t2, t1, &m_rkeys[16]);
1077 IG256(t1, t2, &m_rkeys[12]);
1078 IG256(t2, t1, &m_rkeys[8]);
1079 IG256(t1, t2, &m_rkeys[4]);
1080 IGL256(t2, t1, &m_rkeys[0]);
1085 OutBlock oblk(xorBlock, outBlock);
1086 oblk(t1[0])(t1[1])(t1[2])(t1[3]);
1089 void Kalyna256::Base::ProcessBlock_48(
const word64 inBlock[4],
const word64 xorBlock[4], word64 outBlock[4])
const 1091 word64 *t1 = m_wspace+0, *t2 = m_wspace+4, *msg = m_wspace+8;
1095 InBlock iblk(inBlock);
1096 iblk(msg[0])(msg[1])(msg[2])(msg[3]);
1099 if (IsForwardTransformation())
1101 AddKey<4>(inBlock, t1, m_rkeys);
1102 G256(t1, t2, &m_rkeys[4]);
1103 G256(t2, t1, &m_rkeys[8]);
1104 G256(t1, t2, &m_rkeys[12]);
1105 G256(t2, t1, &m_rkeys[16]);
1106 G256(t1, t2, &m_rkeys[20]);
1107 G256(t2, t1, &m_rkeys[24]);
1108 G256(t1, t2, &m_rkeys[28]);
1109 G256(t2, t1, &m_rkeys[32]);
1110 G256(t1, t2, &m_rkeys[36]);
1111 G256(t2, t1, &m_rkeys[40]);
1112 G256(t1, t2, &m_rkeys[44]);
1113 G256(t2, t1, &m_rkeys[48]);
1114 G256(t1, t2, &m_rkeys[52]);
1115 G256(t2, t1, &m_rkeys[56]);
1116 G256(t1, t2, &m_rkeys[60]);
1117 G256(t2, t1, &m_rkeys[64]);
1118 G256(t1, t2, &m_rkeys[68]);
1119 GL256(t2, t1, &m_rkeys[72]);
1123 SubKey<4>(inBlock, t1, &m_rkeys[72]);
1125 IG256(t1, t2, &m_rkeys[68]);
1126 IG256(t2, t1, &m_rkeys[64]);
1127 IG256(t1, t2, &m_rkeys[60]);
1128 IG256(t2, t1, &m_rkeys[56]);
1129 IG256(t1, t2, &m_rkeys[52]);
1130 IG256(t2, t1, &m_rkeys[48]);
1131 IG256(t1, t2, &m_rkeys[44]);
1132 IG256(t2, t1, &m_rkeys[40]);
1133 IG256(t1, t2, &m_rkeys[36]);
1134 IG256(t2, t1, &m_rkeys[32]);
1135 IG256(t1, t2, &m_rkeys[28]);
1136 IG256(t2, t1, &m_rkeys[24]);
1137 IG256(t1, t2, &m_rkeys[20]);
1138 IG256(t2, t1, &m_rkeys[16]);
1139 IG256(t1, t2, &m_rkeys[12]);
1140 IG256(t2, t1, &m_rkeys[8]);
1141 IG256(t1, t2, &m_rkeys[4]);
1142 IGL256(t2, t1, &m_rkeys[0]);
1147 OutBlock oblk(xorBlock, outBlock);
1148 oblk(t1[0])(t1[1])(t1[2])(t1[3]);
1151 void Kalyna512::Base::ProcessBlock_88(
const word64 inBlock[8],
const word64 xorBlock[8], word64 outBlock[8])
const 1153 word64 *t1 = m_wspace+0, *t2 = m_wspace+8, *msg = m_wspace+16;
1157 InBlock iblk(inBlock);
1158 iblk(msg[0])(msg[1])(msg[2])(msg[3])(msg[4])(msg[5])(msg[6])(msg[7]);
1161 if (IsForwardTransformation())
1163 AddKey<8>(inBlock, t1, m_rkeys);
1164 G512(t1, t2, &m_rkeys[8]);
1165 G512(t2, t1, &m_rkeys[16]);
1166 G512(t1, t2, &m_rkeys[24]);
1167 G512(t2, t1, &m_rkeys[32]);
1168 G512(t1, t2, &m_rkeys[40]);
1169 G512(t2, t1, &m_rkeys[48]);
1170 G512(t1, t2, &m_rkeys[56]);
1171 G512(t2, t1, &m_rkeys[64]);
1172 G512(t1, t2, &m_rkeys[72]);
1173 G512(t2, t1, &m_rkeys[80]);
1174 G512(t1, t2, &m_rkeys[88]);
1175 G512(t2, t1, &m_rkeys[96]);
1176 G512(t1, t2, &m_rkeys[104]);
1177 G512(t2, t1, &m_rkeys[112]);
1178 G512(t1, t2, &m_rkeys[120]);
1179 G512(t2, t1, &m_rkeys[128]);
1180 G512(t1, t2, &m_rkeys[136]);
1181 GL512(t2, t1, &m_rkeys[144]);
1185 SubKey<8>(inBlock, t1, &m_rkeys[144]);
1187 IG512(t1, t2, &m_rkeys[136]);
1188 IG512(t2, t1, &m_rkeys[128]);
1189 IG512(t1, t2, &m_rkeys[120]);
1190 IG512(t2, t1, &m_rkeys[112]);
1191 IG512(t1, t2, &m_rkeys[104]);
1192 IG512(t2, t1, &m_rkeys[96]);
1193 IG512(t1, t2, &m_rkeys[88]);
1194 IG512(t2, t1, &m_rkeys[80]);
1195 IG512(t1, t2, &m_rkeys[72]);
1196 IG512(t2, t1, &m_rkeys[64]);
1197 IG512(t1, t2, &m_rkeys[56]);
1198 IG512(t2, t1, &m_rkeys[48]);
1199 IG512(t1, t2, &m_rkeys[40]);
1200 IG512(t2, t1, &m_rkeys[32]);
1201 IG512(t1, t2, &m_rkeys[24]);
1202 IG512(t2, t1, &m_rkeys[16]);
1203 IG512(t1, t2, &m_rkeys[8]);
1204 IGL512(t2, t1, &m_rkeys[0]);
1209 OutBlock oblk(xorBlock, outBlock);
1210 oblk(t1[0])(t1[1])(t1[2])(t1[3])(t1[4])(t1[5])(t1[6])(t1[7]);
1215 void Kalyna128::Base::UncheckedSetKey(
const byte *key,
unsigned int keylen,
const NameValuePairs ¶ms)
1217 CRYPTOPP_UNUSED(params);
1218 m_nb =
static_cast<unsigned int>(16U /
sizeof(word64));
1219 m_nk =
static_cast<unsigned int>(keylen /
sizeof(word64));
1230 SetKey_22(m_mkey.begin());
1236 m_wspace.New(6*2+4);
1239 SetKey_24(m_mkey.begin());
1246 void Kalyna128::Base::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 1250 volatile word64 _u = 0;
1253 const byte* p =
reinterpret_cast<const byte*
>(KalynaTab::S);
1254 for (
unsigned int i=0; i<256; i+=cacheLineSize)
1255 u ^= *reinterpret_cast<const word64*>(p+i);
1258 switch ((m_nb << 8) | m_nk)
1261 ProcessBlock_22(reinterpret_cast<const word64*>(inBlock),
1262 reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
1265 ProcessBlock_24(reinterpret_cast<const word64*>(inBlock),
1266 reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
1273 void Kalyna256::Base::UncheckedSetKey(
const byte *key,
unsigned int keylen,
const NameValuePairs ¶ms)
1275 CRYPTOPP_UNUSED(params);
1276 m_nb =
static_cast<unsigned int>(32U /
sizeof(word64));
1277 m_nk =
static_cast<unsigned int>(keylen /
sizeof(word64));
1288 SetKey_44(m_mkey.begin());
1294 m_wspace.New(6*4+8);
1297 SetKey_48(m_mkey.begin());
1304 void Kalyna256::Base::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 1308 volatile word64 _u = 0;
1311 const byte* p =
reinterpret_cast<const byte*
>(KalynaTab::S);
1312 for (
unsigned int i=0; i<256; i+=cacheLineSize)
1313 u ^= *reinterpret_cast<const word64*>(p+i);
1316 switch ((m_nb << 8) | m_nk)
1319 ProcessBlock_44(reinterpret_cast<const word64*>(inBlock),
1320 reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
1323 ProcessBlock_48(reinterpret_cast<const word64*>(inBlock),
1324 reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
1331 void Kalyna512::Base::UncheckedSetKey(
const byte *key,
unsigned int keylen,
const NameValuePairs ¶ms)
1333 CRYPTOPP_UNUSED(params);
1334 m_nb =
static_cast<unsigned int>(64U /
sizeof(word64));
1335 m_nk =
static_cast<unsigned int>(keylen /
sizeof(word64));
1341 m_nb =
static_cast<unsigned int>(64U /
sizeof(word64));
1342 m_nk =
static_cast<unsigned int>(keylen /
sizeof(word64));
1349 SetKey_88(m_mkey.begin());
1356 void Kalyna512::Base::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 1360 volatile word64 _u = 0;
1363 const byte* p =
reinterpret_cast<const byte*
>(KalynaTab::S);
1364 for (
unsigned int i=0; i<256; i+=cacheLineSize)
1365 u ^= *reinterpret_cast<const word64*>(p+i);
1368 ProcessBlock_88(reinterpret_cast<const word64*>(inBlock),
1369 reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
Standard names for retrieving values by name when working with NameValuePairs.
Utility functions for the Crypto++ library.
Library configuration file.
int GetCacheLineSize()
Provides the cache line size.
byte order is little-endian
Classes for the Kalyna block cipher.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Functions for CPU features and intrinsics.
Access a block of memory.
Access a block of memory.
Crypto++ library namespace.
Interface for retrieving values given their names.