1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Serpent Cipher 8-way parallel algorithm (x86_64/AVX)
5 * Copyright (C) 2012 Johannes Goetzfried
6 * <Johannes.Goetzfried@informatik.stud.uni-erlangen.de>
8 * Copyright © 2011-2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
11 #include <linux/linkage.h>
12 #include <asm/frame.h>
13 #include "glue_helper-asm-avx.S"
15 .file "serpent-avx-x86_64-asm_64.S"
17 .section .rodata.cst16.bswap128_mask, "aM", @progbits, 16
20 .byte 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
21 .section .rodata.cst16.xts_gf128mul_and_shl1_mask, "aM", @progbits, 16
23 .Lxts_gf128mul_and_shl1_mask:
24 .byte 0x87, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0
30 /**********************************************************************
32 **********************************************************************/
55 #define S0_1(x0, x1, x2, x3, x4) \
64 #define S0_2(x0, x1, x2, x3, x4) \
74 #define S1_1(x0, x1, x2, x3, x4) \
83 #define S1_2(x0, x1, x2, x3, x4) \
94 #define S2_1(x0, x1, x2, x3, x4) \
103 #define S2_2(x0, x1, x2, x3, x4) \
107 vpxor RNOT, tp, tp; \
113 #define S3_1(x0, x1, x2, x3, x4) \
123 #define S3_2(x0, x1, x2, x3, x4) \
134 #define S4_1(x0, x1, x2, x3, x4) \
143 #define S4_2(x0, x1, x2, x3, x4) \
150 vpxor RNOT, x1, x1; \
153 #define S5_1(x0, x1, x2, x3, x4) \
156 vpxor RNOT, x3, x3; \
162 #define S5_2(x0, x1, x2, x3, x4) \
172 #define S6_1(x0, x1, x2, x3, x4) \
178 vpxor RNOT, x1, x4; \
181 #define S6_2(x0, x1, x2, x3, x4) \
191 #define S7_1(x0, x1, x2, x3, x4) \
192 vpxor RNOT, x1, tp; \
193 vpxor RNOT, x0, x0; \
201 #define S7_2(x0, x1, x2, x3, x4) \
212 #define SI0_1(x0, x1, x2, x3, x4) \
216 vpxor RNOT, x0, x0; \
221 #define SI0_2(x0, x1, x2, x3, x4) \
231 #define SI1_1(x0, x1, x2, x3, x4) \
234 vpxor RNOT, x2, x2; \
240 #define SI1_2(x0, x1, x2, x3, x4) \
250 #define SI2_1(x0, x1, x2, x3, x4) \
252 vpxor RNOT, x3, tp; \
259 #define SI2_2(x0, x1, x2, x3, x4) \
269 #define SI3_1(x0, x1, x2, x3, x4) \
278 #define SI3_2(x0, x1, x2, x3, x4) \
289 #define SI4_1(x0, x1, x2, x3, x4) \
294 vpxor RNOT, x0, x4; \
298 #define SI4_2(x0, x1, x2, x3, x4) \
309 #define SI5_1(x0, x1, x2, x3, x4) \
316 vpxor RNOT, x0, x0; \
319 #define SI5_2(x0, x1, x2, x3, x4) \
331 #define SI6_1(x0, x1, x2, x3, x4) \
340 #define SI6_2(x0, x1, x2, x3, x4) \
341 vpxor RNOT, tp, tp; \
350 #define SI7_1(x0, x1, x2, x3, x4) \
355 vpxor RNOT, x0, x0; \
360 #define SI7_2(x0, x1, x2, x3, x4) \
371 #define get_key(i, j, t) \
372 vbroadcastss (4*(i)+(j))*4(CTX), t;
374 #define K2(x0, x1, x2, x3, x4, i) \
375 get_key(i, 0, RK0); \
376 get_key(i, 1, RK1); \
377 get_key(i, 2, RK2); \
378 get_key(i, 3, RK3); \
379 vpxor RK0, x0 ## 1, x0 ## 1; \
380 vpxor RK1, x1 ## 1, x1 ## 1; \
381 vpxor RK2, x2 ## 1, x2 ## 1; \
382 vpxor RK3, x3 ## 1, x3 ## 1; \
383 vpxor RK0, x0 ## 2, x0 ## 2; \
384 vpxor RK1, x1 ## 2, x1 ## 2; \
385 vpxor RK2, x2 ## 2, x2 ## 2; \
386 vpxor RK3, x3 ## 2, x3 ## 2;
388 #define LK2(x0, x1, x2, x3, x4, i) \
389 vpslld $13, x0 ## 1, x4 ## 1; \
390 vpsrld $(32 - 13), x0 ## 1, x0 ## 1; \
391 vpor x4 ## 1, x0 ## 1, x0 ## 1; \
392 vpxor x0 ## 1, x1 ## 1, x1 ## 1; \
393 vpslld $3, x2 ## 1, x4 ## 1; \
394 vpsrld $(32 - 3), x2 ## 1, x2 ## 1; \
395 vpor x4 ## 1, x2 ## 1, x2 ## 1; \
396 vpxor x2 ## 1, x1 ## 1, x1 ## 1; \
397 vpslld $13, x0 ## 2, x4 ## 2; \
398 vpsrld $(32 - 13), x0 ## 2, x0 ## 2; \
399 vpor x4 ## 2, x0 ## 2, x0 ## 2; \
400 vpxor x0 ## 2, x1 ## 2, x1 ## 2; \
401 vpslld $3, x2 ## 2, x4 ## 2; \
402 vpsrld $(32 - 3), x2 ## 2, x2 ## 2; \
403 vpor x4 ## 2, x2 ## 2, x2 ## 2; \
404 vpxor x2 ## 2, x1 ## 2, x1 ## 2; \
405 vpslld $1, x1 ## 1, x4 ## 1; \
406 vpsrld $(32 - 1), x1 ## 1, x1 ## 1; \
407 vpor x4 ## 1, x1 ## 1, x1 ## 1; \
408 vpslld $3, x0 ## 1, x4 ## 1; \
409 vpxor x2 ## 1, x3 ## 1, x3 ## 1; \
410 vpxor x4 ## 1, x3 ## 1, x3 ## 1; \
411 get_key(i, 1, RK1); \
412 vpslld $1, x1 ## 2, x4 ## 2; \
413 vpsrld $(32 - 1), x1 ## 2, x1 ## 2; \
414 vpor x4 ## 2, x1 ## 2, x1 ## 2; \
415 vpslld $3, x0 ## 2, x4 ## 2; \
416 vpxor x2 ## 2, x3 ## 2, x3 ## 2; \
417 vpxor x4 ## 2, x3 ## 2, x3 ## 2; \
418 get_key(i, 3, RK3); \
419 vpslld $7, x3 ## 1, x4 ## 1; \
420 vpsrld $(32 - 7), x3 ## 1, x3 ## 1; \
421 vpor x4 ## 1, x3 ## 1, x3 ## 1; \
422 vpslld $7, x1 ## 1, x4 ## 1; \
423 vpxor x1 ## 1, x0 ## 1, x0 ## 1; \
424 vpxor x3 ## 1, x0 ## 1, x0 ## 1; \
425 vpxor x3 ## 1, x2 ## 1, x2 ## 1; \
426 vpxor x4 ## 1, x2 ## 1, x2 ## 1; \
427 get_key(i, 0, RK0); \
428 vpslld $7, x3 ## 2, x4 ## 2; \
429 vpsrld $(32 - 7), x3 ## 2, x3 ## 2; \
430 vpor x4 ## 2, x3 ## 2, x3 ## 2; \
431 vpslld $7, x1 ## 2, x4 ## 2; \
432 vpxor x1 ## 2, x0 ## 2, x0 ## 2; \
433 vpxor x3 ## 2, x0 ## 2, x0 ## 2; \
434 vpxor x3 ## 2, x2 ## 2, x2 ## 2; \
435 vpxor x4 ## 2, x2 ## 2, x2 ## 2; \
436 get_key(i, 2, RK2); \
437 vpxor RK1, x1 ## 1, x1 ## 1; \
438 vpxor RK3, x3 ## 1, x3 ## 1; \
439 vpslld $5, x0 ## 1, x4 ## 1; \
440 vpsrld $(32 - 5), x0 ## 1, x0 ## 1; \
441 vpor x4 ## 1, x0 ## 1, x0 ## 1; \
442 vpslld $22, x2 ## 1, x4 ## 1; \
443 vpsrld $(32 - 22), x2 ## 1, x2 ## 1; \
444 vpor x4 ## 1, x2 ## 1, x2 ## 1; \
445 vpxor RK0, x0 ## 1, x0 ## 1; \
446 vpxor RK2, x2 ## 1, x2 ## 1; \
447 vpxor RK1, x1 ## 2, x1 ## 2; \
448 vpxor RK3, x3 ## 2, x3 ## 2; \
449 vpslld $5, x0 ## 2, x4 ## 2; \
450 vpsrld $(32 - 5), x0 ## 2, x0 ## 2; \
451 vpor x4 ## 2, x0 ## 2, x0 ## 2; \
452 vpslld $22, x2 ## 2, x4 ## 2; \
453 vpsrld $(32 - 22), x2 ## 2, x2 ## 2; \
454 vpor x4 ## 2, x2 ## 2, x2 ## 2; \
455 vpxor RK0, x0 ## 2, x0 ## 2; \
456 vpxor RK2, x2 ## 2, x2 ## 2;
458 #define KL2(x0, x1, x2, x3, x4, i) \
459 vpxor RK0, x0 ## 1, x0 ## 1; \
460 vpxor RK2, x2 ## 1, x2 ## 1; \
461 vpsrld $5, x0 ## 1, x4 ## 1; \
462 vpslld $(32 - 5), x0 ## 1, x0 ## 1; \
463 vpor x4 ## 1, x0 ## 1, x0 ## 1; \
464 vpxor RK3, x3 ## 1, x3 ## 1; \
465 vpxor RK1, x1 ## 1, x1 ## 1; \
466 vpsrld $22, x2 ## 1, x4 ## 1; \
467 vpslld $(32 - 22), x2 ## 1, x2 ## 1; \
468 vpor x4 ## 1, x2 ## 1, x2 ## 1; \
469 vpxor x3 ## 1, x2 ## 1, x2 ## 1; \
470 vpxor RK0, x0 ## 2, x0 ## 2; \
471 vpxor RK2, x2 ## 2, x2 ## 2; \
472 vpsrld $5, x0 ## 2, x4 ## 2; \
473 vpslld $(32 - 5), x0 ## 2, x0 ## 2; \
474 vpor x4 ## 2, x0 ## 2, x0 ## 2; \
475 vpxor RK3, x3 ## 2, x3 ## 2; \
476 vpxor RK1, x1 ## 2, x1 ## 2; \
477 vpsrld $22, x2 ## 2, x4 ## 2; \
478 vpslld $(32 - 22), x2 ## 2, x2 ## 2; \
479 vpor x4 ## 2, x2 ## 2, x2 ## 2; \
480 vpxor x3 ## 2, x2 ## 2, x2 ## 2; \
481 vpxor x3 ## 1, x0 ## 1, x0 ## 1; \
482 vpslld $7, x1 ## 1, x4 ## 1; \
483 vpxor x1 ## 1, x0 ## 1, x0 ## 1; \
484 vpxor x4 ## 1, x2 ## 1, x2 ## 1; \
485 vpsrld $1, x1 ## 1, x4 ## 1; \
486 vpslld $(32 - 1), x1 ## 1, x1 ## 1; \
487 vpor x4 ## 1, x1 ## 1, x1 ## 1; \
488 vpxor x3 ## 2, x0 ## 2, x0 ## 2; \
489 vpslld $7, x1 ## 2, x4 ## 2; \
490 vpxor x1 ## 2, x0 ## 2, x0 ## 2; \
491 vpxor x4 ## 2, x2 ## 2, x2 ## 2; \
492 vpsrld $1, x1 ## 2, x4 ## 2; \
493 vpslld $(32 - 1), x1 ## 2, x1 ## 2; \
494 vpor x4 ## 2, x1 ## 2, x1 ## 2; \
495 vpsrld $7, x3 ## 1, x4 ## 1; \
496 vpslld $(32 - 7), x3 ## 1, x3 ## 1; \
497 vpor x4 ## 1, x3 ## 1, x3 ## 1; \
498 vpxor x0 ## 1, x1 ## 1, x1 ## 1; \
499 vpslld $3, x0 ## 1, x4 ## 1; \
500 vpxor x4 ## 1, x3 ## 1, x3 ## 1; \
501 vpsrld $7, x3 ## 2, x4 ## 2; \
502 vpslld $(32 - 7), x3 ## 2, x3 ## 2; \
503 vpor x4 ## 2, x3 ## 2, x3 ## 2; \
504 vpxor x0 ## 2, x1 ## 2, x1 ## 2; \
505 vpslld $3, x0 ## 2, x4 ## 2; \
506 vpxor x4 ## 2, x3 ## 2, x3 ## 2; \
507 vpsrld $13, x0 ## 1, x4 ## 1; \
508 vpslld $(32 - 13), x0 ## 1, x0 ## 1; \
509 vpor x4 ## 1, x0 ## 1, x0 ## 1; \
510 vpxor x2 ## 1, x1 ## 1, x1 ## 1; \
511 vpxor x2 ## 1, x3 ## 1, x3 ## 1; \
512 vpsrld $3, x2 ## 1, x4 ## 1; \
513 vpslld $(32 - 3), x2 ## 1, x2 ## 1; \
514 vpor x4 ## 1, x2 ## 1, x2 ## 1; \
515 vpsrld $13, x0 ## 2, x4 ## 2; \
516 vpslld $(32 - 13), x0 ## 2, x0 ## 2; \
517 vpor x4 ## 2, x0 ## 2, x0 ## 2; \
518 vpxor x2 ## 2, x1 ## 2, x1 ## 2; \
519 vpxor x2 ## 2, x3 ## 2, x3 ## 2; \
520 vpsrld $3, x2 ## 2, x4 ## 2; \
521 vpslld $(32 - 3), x2 ## 2, x2 ## 2; \
522 vpor x4 ## 2, x2 ## 2, x2 ## 2;
524 #define S(SBOX, x0, x1, x2, x3, x4) \
525 SBOX ## _1(x0 ## 1, x1 ## 1, x2 ## 1, x3 ## 1, x4 ## 1); \
526 SBOX ## _2(x0 ## 1, x1 ## 1, x2 ## 1, x3 ## 1, x4 ## 1); \
527 SBOX ## _1(x0 ## 2, x1 ## 2, x2 ## 2, x3 ## 2, x4 ## 2); \
528 SBOX ## _2(x0 ## 2, x1 ## 2, x2 ## 2, x3 ## 2, x4 ## 2);
530 #define SP(SBOX, x0, x1, x2, x3, x4, i) \
531 get_key(i, 0, RK0); \
532 SBOX ## _1(x0 ## 1, x1 ## 1, x2 ## 1, x3 ## 1, x4 ## 1); \
533 get_key(i, 2, RK2); \
534 SBOX ## _2(x0 ## 1, x1 ## 1, x2 ## 1, x3 ## 1, x4 ## 1); \
535 get_key(i, 3, RK3); \
536 SBOX ## _1(x0 ## 2, x1 ## 2, x2 ## 2, x3 ## 2, x4 ## 2); \
537 get_key(i, 1, RK1); \
538 SBOX ## _2(x0 ## 2, x1 ## 2, x2 ## 2, x3 ## 2, x4 ## 2); \
540 #define transpose_4x4(x0, x1, x2, x3, t0, t1, t2) \
541 vpunpckldq x1, x0, t0; \
542 vpunpckhdq x1, x0, t2; \
543 vpunpckldq x3, x2, t1; \
544 vpunpckhdq x3, x2, x3; \
546 vpunpcklqdq t1, t0, x0; \
547 vpunpckhqdq t1, t0, x1; \
548 vpunpcklqdq x3, t2, x2; \
549 vpunpckhqdq x3, t2, x3;
551 #define read_blocks(x0, x1, x2, x3, t0, t1, t2) \
552 transpose_4x4(x0, x1, x2, x3, t0, t1, t2)
554 #define write_blocks(x0, x1, x2, x3, t0, t1, t2) \
555 transpose_4x4(x0, x1, x2, x3, t0, t1, t2)
558 SYM_FUNC_START_LOCAL(__serpent_enc_blk8_avx)
561 * RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: blocks
563 * RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: encrypted blocks
566 vpcmpeqd RNOT, RNOT, RNOT;
568 read_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
569 read_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
571 K2(RA, RB, RC, RD, RE, 0);
572 S(S0, RA, RB, RC, RD, RE); LK2(RC, RB, RD, RA, RE, 1);
573 S(S1, RC, RB, RD, RA, RE); LK2(RE, RD, RA, RC, RB, 2);
574 S(S2, RE, RD, RA, RC, RB); LK2(RB, RD, RE, RC, RA, 3);
575 S(S3, RB, RD, RE, RC, RA); LK2(RC, RA, RD, RB, RE, 4);
576 S(S4, RC, RA, RD, RB, RE); LK2(RA, RD, RB, RE, RC, 5);
577 S(S5, RA, RD, RB, RE, RC); LK2(RC, RA, RD, RE, RB, 6);
578 S(S6, RC, RA, RD, RE, RB); LK2(RD, RB, RA, RE, RC, 7);
579 S(S7, RD, RB, RA, RE, RC); LK2(RC, RA, RE, RD, RB, 8);
580 S(S0, RC, RA, RE, RD, RB); LK2(RE, RA, RD, RC, RB, 9);
581 S(S1, RE, RA, RD, RC, RB); LK2(RB, RD, RC, RE, RA, 10);
582 S(S2, RB, RD, RC, RE, RA); LK2(RA, RD, RB, RE, RC, 11);
583 S(S3, RA, RD, RB, RE, RC); LK2(RE, RC, RD, RA, RB, 12);
584 S(S4, RE, RC, RD, RA, RB); LK2(RC, RD, RA, RB, RE, 13);
585 S(S5, RC, RD, RA, RB, RE); LK2(RE, RC, RD, RB, RA, 14);
586 S(S6, RE, RC, RD, RB, RA); LK2(RD, RA, RC, RB, RE, 15);
587 S(S7, RD, RA, RC, RB, RE); LK2(RE, RC, RB, RD, RA, 16);
588 S(S0, RE, RC, RB, RD, RA); LK2(RB, RC, RD, RE, RA, 17);
589 S(S1, RB, RC, RD, RE, RA); LK2(RA, RD, RE, RB, RC, 18);
590 S(S2, RA, RD, RE, RB, RC); LK2(RC, RD, RA, RB, RE, 19);
591 S(S3, RC, RD, RA, RB, RE); LK2(RB, RE, RD, RC, RA, 20);
592 S(S4, RB, RE, RD, RC, RA); LK2(RE, RD, RC, RA, RB, 21);
593 S(S5, RE, RD, RC, RA, RB); LK2(RB, RE, RD, RA, RC, 22);
594 S(S6, RB, RE, RD, RA, RC); LK2(RD, RC, RE, RA, RB, 23);
595 S(S7, RD, RC, RE, RA, RB); LK2(RB, RE, RA, RD, RC, 24);
596 S(S0, RB, RE, RA, RD, RC); LK2(RA, RE, RD, RB, RC, 25);
597 S(S1, RA, RE, RD, RB, RC); LK2(RC, RD, RB, RA, RE, 26);
598 S(S2, RC, RD, RB, RA, RE); LK2(RE, RD, RC, RA, RB, 27);
599 S(S3, RE, RD, RC, RA, RB); LK2(RA, RB, RD, RE, RC, 28);
600 S(S4, RA, RB, RD, RE, RC); LK2(RB, RD, RE, RC, RA, 29);
601 S(S5, RB, RD, RE, RC, RA); LK2(RA, RB, RD, RC, RE, 30);
602 S(S6, RA, RB, RD, RC, RE); LK2(RD, RE, RB, RC, RA, 31);
603 S(S7, RD, RE, RB, RC, RA); K2(RA, RB, RC, RD, RE, 32);
605 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
606 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
609 SYM_FUNC_END(__serpent_enc_blk8_avx)
612 SYM_FUNC_START_LOCAL(__serpent_dec_blk8_avx)
615 * RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: encrypted blocks
617 * RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2: decrypted blocks
620 vpcmpeqd RNOT, RNOT, RNOT;
622 read_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
623 read_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
625 K2(RA, RB, RC, RD, RE, 32);
626 SP(SI7, RA, RB, RC, RD, RE, 31); KL2(RB, RD, RA, RE, RC, 31);
627 SP(SI6, RB, RD, RA, RE, RC, 30); KL2(RA, RC, RE, RB, RD, 30);
628 SP(SI5, RA, RC, RE, RB, RD, 29); KL2(RC, RD, RA, RE, RB, 29);
629 SP(SI4, RC, RD, RA, RE, RB, 28); KL2(RC, RA, RB, RE, RD, 28);
630 SP(SI3, RC, RA, RB, RE, RD, 27); KL2(RB, RC, RD, RE, RA, 27);
631 SP(SI2, RB, RC, RD, RE, RA, 26); KL2(RC, RA, RE, RD, RB, 26);
632 SP(SI1, RC, RA, RE, RD, RB, 25); KL2(RB, RA, RE, RD, RC, 25);
633 SP(SI0, RB, RA, RE, RD, RC, 24); KL2(RE, RC, RA, RB, RD, 24);
634 SP(SI7, RE, RC, RA, RB, RD, 23); KL2(RC, RB, RE, RD, RA, 23);
635 SP(SI6, RC, RB, RE, RD, RA, 22); KL2(RE, RA, RD, RC, RB, 22);
636 SP(SI5, RE, RA, RD, RC, RB, 21); KL2(RA, RB, RE, RD, RC, 21);
637 SP(SI4, RA, RB, RE, RD, RC, 20); KL2(RA, RE, RC, RD, RB, 20);
638 SP(SI3, RA, RE, RC, RD, RB, 19); KL2(RC, RA, RB, RD, RE, 19);
639 SP(SI2, RC, RA, RB, RD, RE, 18); KL2(RA, RE, RD, RB, RC, 18);
640 SP(SI1, RA, RE, RD, RB, RC, 17); KL2(RC, RE, RD, RB, RA, 17);
641 SP(SI0, RC, RE, RD, RB, RA, 16); KL2(RD, RA, RE, RC, RB, 16);
642 SP(SI7, RD, RA, RE, RC, RB, 15); KL2(RA, RC, RD, RB, RE, 15);
643 SP(SI6, RA, RC, RD, RB, RE, 14); KL2(RD, RE, RB, RA, RC, 14);
644 SP(SI5, RD, RE, RB, RA, RC, 13); KL2(RE, RC, RD, RB, RA, 13);
645 SP(SI4, RE, RC, RD, RB, RA, 12); KL2(RE, RD, RA, RB, RC, 12);
646 SP(SI3, RE, RD, RA, RB, RC, 11); KL2(RA, RE, RC, RB, RD, 11);
647 SP(SI2, RA, RE, RC, RB, RD, 10); KL2(RE, RD, RB, RC, RA, 10);
648 SP(SI1, RE, RD, RB, RC, RA, 9); KL2(RA, RD, RB, RC, RE, 9);
649 SP(SI0, RA, RD, RB, RC, RE, 8); KL2(RB, RE, RD, RA, RC, 8);
650 SP(SI7, RB, RE, RD, RA, RC, 7); KL2(RE, RA, RB, RC, RD, 7);
651 SP(SI6, RE, RA, RB, RC, RD, 6); KL2(RB, RD, RC, RE, RA, 6);
652 SP(SI5, RB, RD, RC, RE, RA, 5); KL2(RD, RA, RB, RC, RE, 5);
653 SP(SI4, RD, RA, RB, RC, RE, 4); KL2(RD, RB, RE, RC, RA, 4);
654 SP(SI3, RD, RB, RE, RC, RA, 3); KL2(RE, RD, RA, RC, RB, 3);
655 SP(SI2, RE, RD, RA, RC, RB, 2); KL2(RD, RB, RC, RA, RE, 2);
656 SP(SI1, RD, RB, RC, RA, RE, 1); KL2(RE, RB, RC, RA, RD, 1);
657 S(SI0, RE, RB, RC, RA, RD); K2(RC, RD, RB, RE, RA, 0);
659 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
660 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
663 SYM_FUNC_END(__serpent_dec_blk8_avx)
665 SYM_FUNC_START(serpent_ecb_enc_8way_avx)
673 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
675 call __serpent_enc_blk8_avx;
677 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
681 SYM_FUNC_END(serpent_ecb_enc_8way_avx)
683 SYM_FUNC_START(serpent_ecb_dec_8way_avx)
691 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
693 call __serpent_dec_blk8_avx;
695 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
699 SYM_FUNC_END(serpent_ecb_dec_8way_avx)
701 SYM_FUNC_START(serpent_cbc_dec_8way_avx)
709 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
711 call __serpent_dec_blk8_avx;
713 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
717 SYM_FUNC_END(serpent_cbc_dec_8way_avx)
719 SYM_FUNC_START(serpent_ctr_8way_avx)
724 * %rcx: iv (little endian, 128bit)
728 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
731 call __serpent_enc_blk8_avx;
733 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
737 SYM_FUNC_END(serpent_ctr_8way_avx)
739 SYM_FUNC_START(serpent_xts_enc_8way_avx)
744 * %rcx: iv (t ⊕ αⁿ ∈ GF(2¹²⁸))
748 /* regs <= src, dst <= IVs, regs <= regs xor IVs */
749 load_xts_8way(%rcx, %rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2,
750 RK0, RK1, RK2, .Lxts_gf128mul_and_shl1_mask);
752 call __serpent_enc_blk8_avx;
754 /* dst <= regs xor IVs(in dst) */
755 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
759 SYM_FUNC_END(serpent_xts_enc_8way_avx)
761 SYM_FUNC_START(serpent_xts_dec_8way_avx)
766 * %rcx: iv (t ⊕ αⁿ ∈ GF(2¹²⁸))
770 /* regs <= src, dst <= IVs, regs <= regs xor IVs */
771 load_xts_8way(%rcx, %rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2,
772 RK0, RK1, RK2, .Lxts_gf128mul_and_shl1_mask);
774 call __serpent_dec_blk8_avx;
776 /* dst <= regs xor IVs(in dst) */
777 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
781 SYM_FUNC_END(serpent_xts_dec_8way_avx)