7#include <botan/internal/serpent.h>
8#include <botan/internal/serpent_sbox.h>
9#include <botan/internal/simd_avx512.h>
16 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0xb9>(
b, d, c);
17 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0xe2>(a,
b, d);
18 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0x36>(a,
b, d);
19 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x26>(t0, d,
b);
20 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t3);
21 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0x96>(t1, c, o0);
22 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0xa9>(o0, o1, t2);
23 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x3c>(t2, c, t0);
31 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0xe5>(d,
b, c);
32 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x26>(c, d,
b);
33 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0xa6>(a,
b, c);
34 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x2b>(a,
b, d);
35 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
36 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x83>(t2, d, t0);
37 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x69>(t3, c, o1);
38 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0x65>(o3, o1, t2);
46 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0x96>(c,
b, d);
47 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0xda>(a,
b, c);
48 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0x66>(d, t0, c);
49 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x94>(a,
b, t0);
50 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0xa1>(a, d, t0);
51 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t2);
52 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0xd2>(t3, d, o0);
53 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x2d>(t4,
b, c);
54 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x2d>(t1, d, t2);
62 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0x92>(d, c,
b);
63 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x3b>(d,
b, c);
64 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0xbc>(a, c, t0);
65 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x68>(t2, d, t1);
66 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x6e>(a, c, o2);
67 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0xb9>(a, d, t3);
68 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
69 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0x6d>(t4,
b, t2);
70 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x38>(t3,
b, t0);
78 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0xc2>(c,
b, d);
79 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x79>(
b, c, d);
80 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0x71>(a,
b, d);
81 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x6b>(a,
b, d);
82 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0xc2>(a, t0, t3);
83 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
84 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0x3c>(t2, c, t0);
85 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x49>(t3, c, t0);
86 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0xd6>(t4,
b, t1);
94 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0xa9>(
b, d, c);
95 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x93>(
b, c, d);
96 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0xc3>(a,
b, c);
97 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x27>(a,
b, d);
98 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0x85>(a, c, t1);
99 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
100 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0x2d>(t2, d, o0);
101 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x7a>(t4,
b, t0);
102 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x87>(t3, t0, o0);
110 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0x61>(d, c,
b);
111 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x9c>(
b, d, t0);
112 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0x93>(a,
b, d);
113 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0xb5>(a,
b, c);
114 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
115 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0x3c>(t2, c, t0);
116 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0x7c>(a,
b, o1);
117 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x1e>(t4, d, t0);
118 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x29>(t3, t0, t1);
126 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0x9b>(
b, c, d);
127 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x61>(c,
b, d);
128 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0xe3>(a, d, t1);
129 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x83>(
b, c, d);
130 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0x49>(a,
b, c);
131 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
132 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0xe1>(t2,
b, c);
133 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0xd1>(t3, a, t1);
134 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x87>(t4, d, t2);
142 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0x67>(c, d,
b);
143 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x49>(
b, d, c);
144 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
145 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0xa9>(a,
b, c);
146 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x3c>(t2, d, t0);
147 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x4d>(a,
b, d);
148 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x69>(t3, c, o0);
149 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0x56>(o3, o0, t2);
157 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0x73>(d,
b, c);
158 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x68>(c, d,
b);
159 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0xc5>(a,
b, d);
160 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x2d>(a,
b, d);
161 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
162 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0x96>(t2, c, o0);
163 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0xd2>(t3, o0, o1);
164 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x99>(o0, t3, c);
172 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0xc6>(d,
b, c);
173 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x9c>(d, c,
b);
174 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0xe1>(a,
b, c);
175 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0x87>(t2, d, t0);
176 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
177 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0xd1>(t0, a, t1);
178 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x9b>(a, c, o2);
179 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x5b>(t3,
b, d);
187 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0x94>(c, d,
b);
188 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x99>(
b, d, t0);
189 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
190 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0x97>(a,
b, d);
191 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x4b>(t2, c, o0);
192 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x94>(c, d, t2);
193 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0x0e>(t3,
b, t0);
194 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0x1c>(a,
b, t0);
195 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0xb4>(t4, c, d);
203 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0xa9>(d, c,
b);
204 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0xa6>(d,
b, c);
205 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0xb5>(a,
b, d);
206 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x5e>(a,
b, d);
207 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0x50>(a,
b, t0);
208 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
209 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0x96>(t4, c, d);
210 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x4b>(t3, c, t4);
211 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x5a>(t2, c, t0);
219 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0xc9>(a,
b, c);
220 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x65>(a,
b, c);
221 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0x25>(a,
b, d);
222 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x63>(c, d, t0);
223 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0x86>(a,
b, t3);
224 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0x87>(t2, c, t0);
225 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0xc3>(t4, c, d);
226 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x47>(t1, d, t0);
227 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0xac>(a, t0, t3);
235 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0x07>(d,
b, c);
236 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x9e>(c, d,
b);
237 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0xc6>(a,
b, c);
238 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x34>(a,
b, d);
239 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0x2b>(a, c, d);
240 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t1);
241 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0xcb>(t2, d, t0);
242 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0x4b>(t3, c, t0);
243 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x69>(t4,
b, o0);
251 const SIMD_16x32 t0 = SIMD_16x32::ternary_fn<0x67>(
b, d, c);
252 const SIMD_16x32 t1 = SIMD_16x32::ternary_fn<0x3e>(a, c, d);
253 const SIMD_16x32 t2 = SIMD_16x32::ternary_fn<0x1c>(a,
b, d);
254 const SIMD_16x32 t3 = SIMD_16x32::ternary_fn<0x87>(t0, d,
b);
255 const SIMD_16x32 t4 = SIMD_16x32::ternary_fn<0x7d>(a,
b, t1);
256 const SIMD_16x32 o0 = SIMD_16x32::ternary_fn<0xac>(a, t0, t3);
257 const SIMD_16x32 o1 = SIMD_16x32::ternary_fn<0x96>(t1,
b, t0);
258 const SIMD_16x32 o2 = SIMD_16x32::ternary_fn<0xd2>(t2, c, t1);
259 const SIMD_16x32 o3 = SIMD_16x32::ternary_fn<0x6d>(t4, c, d);
269void Serpent::avx512_encrypt_16(
const uint8_t in[16 * 16], uint8_t out[16 * 16])
const {
274 SIMD_16x32 B2 = SIMD_16x32::load_le(in + 128);
275 SIMD_16x32 B3 = SIMD_16x32::load_le(in + 192);
277 SIMD_16x32::transpose(B0, B1, B2, B3);
281 key_xor(0, B0, B1, B2, B3);
284 key_xor(1, B0, B1, B2, B3);
287 key_xor(2, B0, B1, B2, B3);
290 key_xor(3, B0, B1, B2, B3);
293 key_xor(4, B0, B1, B2, B3);
296 key_xor(5, B0, B1, B2, B3);
299 key_xor(6, B0, B1, B2, B3);
302 key_xor(7, B0, B1, B2, B3);
306 key_xor(8, B0, B1, B2, B3);
309 key_xor(9, B0, B1, B2, B3);
312 key_xor(10, B0, B1, B2, B3);
315 key_xor(11, B0, B1, B2, B3);
318 key_xor(12, B0, B1, B2, B3);
321 key_xor(13, B0, B1, B2, B3);
324 key_xor(14, B0, B1, B2, B3);
327 key_xor(15, B0, B1, B2, B3);
331 key_xor(16, B0, B1, B2, B3);
334 key_xor(17, B0, B1, B2, B3);
337 key_xor(18, B0, B1, B2, B3);
340 key_xor(19, B0, B1, B2, B3);
343 key_xor(20, B0, B1, B2, B3);
346 key_xor(21, B0, B1, B2, B3);
349 key_xor(22, B0, B1, B2, B3);
352 key_xor(23, B0, B1, B2, B3);
356 key_xor(24, B0, B1, B2, B3);
359 key_xor(25, B0, B1, B2, B3);
362 key_xor(26, B0, B1, B2, B3);
365 key_xor(27, B0, B1, B2, B3);
368 key_xor(28, B0, B1, B2, B3);
371 key_xor(29, B0, B1, B2, B3);
374 key_xor(30, B0, B1, B2, B3);
377 key_xor(31, B0, B1, B2, B3);
379 key_xor(32, B0, B1, B2, B3);
381 SIMD_16x32::transpose(B0, B1, B2, B3);
383 B1.store_le(out + 64);
384 B2.store_le(out + 128);
385 B3.store_le(out + 192);
387 SIMD_16x32::zero_registers();
391void Serpent::avx512_decrypt_16(
const uint8_t in[16 * 16], uint8_t out[16 * 16])
const {
396 SIMD_16x32 B2 = SIMD_16x32::load_le(in + 128);
397 SIMD_16x32 B3 = SIMD_16x32::load_le(in + 192);
399 SIMD_16x32::transpose(B0, B1, B2, B3);
403 key_xor(32, B0, B1, B2, B3);
405 key_xor(31, B0, B1, B2, B3);
408 key_xor(30, B0, B1, B2, B3);
411 key_xor(29, B0, B1, B2, B3);
414 key_xor(28, B0, B1, B2, B3);
417 key_xor(27, B0, B1, B2, B3);
420 key_xor(26, B0, B1, B2, B3);
423 key_xor(25, B0, B1, B2, B3);
426 key_xor(24, B0, B1, B2, B3);
430 key_xor(23, B0, B1, B2, B3);
433 key_xor(22, B0, B1, B2, B3);
436 key_xor(21, B0, B1, B2, B3);
439 key_xor(20, B0, B1, B2, B3);
442 key_xor(19, B0, B1, B2, B3);
445 key_xor(18, B0, B1, B2, B3);
448 key_xor(17, B0, B1, B2, B3);
451 key_xor(16, B0, B1, B2, B3);
455 key_xor(15, B0, B1, B2, B3);
458 key_xor(14, B0, B1, B2, B3);
461 key_xor(13, B0, B1, B2, B3);
464 key_xor(12, B0, B1, B2, B3);
467 key_xor(11, B0, B1, B2, B3);
470 key_xor(10, B0, B1, B2, B3);
473 key_xor(9, B0, B1, B2, B3);
476 key_xor(8, B0, B1, B2, B3);
480 key_xor(7, B0, B1, B2, B3);
483 key_xor(6, B0, B1, B2, B3);
486 key_xor(5, B0, B1, B2, B3);
489 key_xor(4, B0, B1, B2, B3);
492 key_xor(3, B0, B1, B2, B3);
495 key_xor(2, B0, B1, B2, B3);
498 key_xor(1, B0, B1, B2, B3);
501 key_xor(0, B0, B1, B2, B3);
503 SIMD_16x32::transpose(B0, B1, B2, B3);
506 B1.store_le(out + 64);
507 B2.store_le(out + 128);
508 B3.store_le(out + 192);
510 SIMD_16x32::zero_registers();
#define BOTAN_FORCE_INLINE
BOTAN_FORCE_INLINE void transform(T &B0, T &B1, T &B2, T &B3)
BOTAN_FORCE_INLINE void SBoxD5(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxD4(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxE0(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxE1(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxE3(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxD0(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxE5(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxD6(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxD3(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void i_transform(T &B0, T &B1, T &B2, T &B3)
BOTAN_FORCE_INLINE void SBoxD2(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxE6(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxE2(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxE4(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxD1(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxE7(T &a, T &b, T &c, T &d)
BOTAN_FORCE_INLINE void SBoxD7(T &a, T &b, T &c, T &d)