2 * Serpent Cipher 8-way parallel algorithm (x86_64/AVX)
4 * Copyright (C) 2012 Johannes Goetzfried
5 * <Johannes.Goetzfried@informatik.stud.uni-erlangen.de>
7 * Copyright © 2011-2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <linux/linkage.h>
27 #include "glue_helper-asm-avx.S"
29 .file "serpent-avx-x86_64-asm_64.S"
35 .byte 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
36 .Lxts_gf128mul_and_shl1_mask:
37 .byte 0x87, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0
43 /**********************************************************************
45 **********************************************************************/
68 #define S0_1(x0, x1, x2, x3, x4) \
77 #define S0_2(x0, x1, x2, x3, x4) \
87 #define S1_1(x0, x1, x2, x3, x4) \
96 #define S1_2(x0, x1, x2, x3, x4) \
103 vpxor RNOT, x0, x0; \
107 #define S2_1(x0, x1, x2, x3, x4) \
108 vpxor RNOT, x3, x3; \
116 #define S2_2(x0, x1, x2, x3, x4) \
120 vpxor RNOT, tp, tp; \
126 #define S3_1(x0, x1, x2, x3, x4) \
136 #define S3_2(x0, x1, x2, x3, x4) \
147 #define S4_1(x0, x1, x2, x3, x4) \
156 #define S4_2(x0, x1, x2, x3, x4) \
163 vpxor RNOT, x1, x1; \
166 #define S5_1(x0, x1, x2, x3, x4) \
169 vpxor RNOT, x3, x3; \
175 #define S5_2(x0, x1, x2, x3, x4) \
185 #define S6_1(x0, x1, x2, x3, x4) \
191 vpxor RNOT, x1, x4; \
194 #define S6_2(x0, x1, x2, x3, x4) \
204 #define S7_1(x0, x1, x2, x3, x4) \
205 vpxor RNOT, x1, tp; \
206 vpxor RNOT, x0, x0; \
214 #define S7_2(x0, x1, x2, x3, x4) \
225 #define SI0_1(x0, x1, x2, x3, x4) \
229 vpxor RNOT, x0, x0; \
234 #define SI0_2(x0, x1, x2, x3, x4) \
244 #define SI1_1(x0, x1, x2, x3, x4) \
247 vpxor RNOT, x2, x2; \
253 #define SI1_2(x0, x1, x2, x3, x4) \
263 #define SI2_1(x0, x1, x2, x3, x4) \
265 vpxor RNOT, x3, tp; \
272 #define SI2_2(x0, x1, x2, x3, x4) \
282 #define SI3_1(x0, x1, x2, x3, x4) \
291 #define SI3_2(x0, x1, x2, x3, x4) \
302 #define SI4_1(x0, x1, x2, x3, x4) \
307 vpxor RNOT, x0, x4; \
311 #define SI4_2(x0, x1, x2, x3, x4) \
322 #define SI5_1(x0, x1, x2, x3, x4) \
329 vpxor RNOT, x0, x0; \
332 #define SI5_2(x0, x1, x2, x3, x4) \
344 #define SI6_1(x0, x1, x2, x3, x4) \
353 #define SI6_2(x0, x1, x2, x3, x4) \
354 vpxor RNOT, tp, tp; \
363 #define SI7_1(x0, x1, x2, x3, x4) \
368 vpxor RNOT, x0, x0; \
373 #define SI7_2(x0, x1, x2, x3, x4) \
384 #define get_key(i, j, t) \
385 vbroadcastss (4*(i)+(j))*4(CTX), t;
387 #define K2(x0, x1, x2, x3, x4, i) \
388 get_key(i, 0, RK0); \
389 get_key(i, 1, RK1); \
390 get_key(i, 2, RK2); \
391 get_key(i, 3, RK3); \
392 vpxor RK0, x0 ## 1, x0 ## 1; \
393 vpxor RK1, x1 ## 1, x1 ## 1; \
394 vpxor RK2, x2 ## 1, x2 ## 1; \
395 vpxor RK3, x3 ## 1, x3 ## 1; \
396 vpxor RK0, x0 ## 2, x0 ## 2; \
397 vpxor RK1, x1 ## 2, x1 ## 2; \
398 vpxor RK2, x2 ## 2, x2 ## 2; \
399 vpxor RK3, x3 ## 2, x3 ## 2;
401 #define LK2(x0, x1, x2, x3, x4, i) \
402 vpslld $13, x0 ## 1, x4 ## 1; \
403 vpsrld $(32 - 13), x0 ## 1, x0 ## 1; \
404 vpor x4 ## 1, x0 ## 1, x0 ## 1; \
405 vpxor x0 ## 1, x1 ## 1, x1 ## 1; \
406 vpslld $3, x2 ## 1, x4 ## 1; \
407 vpsrld $(32 - 3), x2 ## 1, x2 ## 1; \
408 vpor x4 ## 1, x2 ## 1, x2 ## 1; \
409 vpxor x2 ## 1, x1 ## 1, x1 ## 1; \
410 vpslld $13, x0 ## 2, x4 ## 2; \
411 vpsrld $(32 - 13), x0 ## 2, x0 ## 2; \
412 vpor x4 ## 2, x0 ## 2, x0 ## 2; \
413 vpxor x0 ## 2, x1 ## 2, x1 ## 2; \
414 vpslld $3, x2 ## 2, x4 ## 2; \
415 vpsrld $(32 - 3), x2 ## 2, x2 ## 2; \
416 vpor x4 ## 2, x2 ## 2, x2 ## 2; \
417 vpxor x2 ## 2, x1 ## 2, x1 ## 2; \
418 vpslld $1, x1 ## 1, x4 ## 1; \
419 vpsrld $(32 - 1), x1 ## 1, x1 ## 1; \
420 vpor x4 ## 1, x1 ## 1, x1 ## 1; \
421 vpslld $3, x0 ## 1, x4 ## 1; \
422 vpxor x2 ## 1, x3 ## 1, x3 ## 1; \
423 vpxor x4 ## 1, x3 ## 1, x3 ## 1; \
424 get_key(i, 1, RK1); \
425 vpslld $1, x1 ## 2, x4 ## 2; \
426 vpsrld $(32 - 1), x1 ## 2, x1 ## 2; \
427 vpor x4 ## 2, x1 ## 2, x1 ## 2; \
428 vpslld $3, x0 ## 2, x4 ## 2; \
429 vpxor x2 ## 2, x3 ## 2, x3 ## 2; \
430 vpxor x4 ## 2, x3 ## 2, x3 ## 2; \
431 get_key(i, 3, RK3); \
432 vpslld $7, x3 ## 1, x4 ## 1; \
433 vpsrld $(32 - 7), x3 ## 1, x3 ## 1; \
434 vpor x4 ## 1, x3 ## 1, x3 ## 1; \
435 vpslld $7, x1 ## 1, x4 ## 1; \
436 vpxor x1 ## 1, x0 ## 1, x0 ## 1; \
437 vpxor x3 ## 1, x0 ## 1, x0 ## 1; \
438 vpxor x3 ## 1, x2 ## 1, x2 ## 1; \
439 vpxor x4 ## 1, x2 ## 1, x2 ## 1; \
440 get_key(i, 0, RK0); \
441 vpslld $7, x3 ## 2, x4 ## 2; \
442 vpsrld $(32 - 7), x3 ## 2, x3 ## 2; \
443 vpor x4 ## 2, x3 ## 2, x3 ## 2; \
444 vpslld $7, x1 ## 2, x4 ## 2; \
445 vpxor x1 ## 2, x0 ## 2, x0 ## 2; \
446 vpxor x3 ## 2, x0 ## 2, x0 ## 2; \
447 vpxor x3 ## 2, x2 ## 2, x2 ## 2; \
448 vpxor x4 ## 2, x2 ## 2, x2 ## 2; \
449 get_key(i, 2, RK2); \
450 vpxor RK1, x1 ## 1, x1 ## 1; \
451 vpxor RK3, x3 ## 1, x3 ## 1; \
452 vpslld $5, x0 ## 1, x4 ## 1; \
453 vpsrld $(32 - 5), x0 ## 1, x0 ## 1; \
454 vpor x4 ## 1, x0 ## 1, x0 ## 1; \
455 vpslld $22, x2 ## 1, x4 ## 1; \
456 vpsrld $(32 - 22), x2 ## 1, x2 ## 1; \
457 vpor x4 ## 1, x2 ## 1, x2 ## 1; \
458 vpxor RK0, x0 ## 1, x0 ## 1; \
459 vpxor RK2, x2 ## 1, x2 ## 1; \
460 vpxor RK1, x1 ## 2, x1 ## 2; \
461 vpxor RK3, x3 ## 2, x3 ## 2; \
462 vpslld $5, x0 ## 2, x4 ## 2; \
463 vpsrld $(32 - 5), x0 ## 2, x0 ## 2; \
464 vpor x4 ## 2, x0 ## 2, x0 ## 2; \
465 vpslld $22, x2 ## 2, x4 ## 2; \
466 vpsrld $(32 - 22), x2 ## 2, x2 ## 2; \
467 vpor x4 ## 2, x2 ## 2, x2 ## 2; \
468 vpxor RK0, x0 ## 2, x0 ## 2; \
469 vpxor RK2, x2 ## 2, x2 ## 2;
471 #define KL2(x0, x1, x2, x3, x4, i) \
472 vpxor RK0, x0 ## 1, x0 ## 1; \
473 vpxor RK2, x2 ## 1, x2 ## 1; \
474 vpsrld $5, x0 ## 1, x4 ## 1; \
475 vpslld $(32 - 5), x0 ## 1, x0 ## 1; \
476 vpor x4 ## 1, x0 ## 1, x0 ## 1; \
477 vpxor RK3, x3 ## 1, x3 ## 1; \
478 vpxor RK1, x1 ## 1, x1 ## 1; \
479 vpsrld $22, x2 ## 1, x4 ## 1; \
480 vpslld $(32 - 22), x2 ## 1, x2 ## 1; \
481 vpor x4 ## 1, x2 ## 1, x2 ## 1; \
482 vpxor x3 ## 1, x2 ## 1, x2 ## 1; \
483 vpxor RK0, x0 ## 2, x0 ## 2; \
484 vpxor RK2, x2 ## 2, x2 ## 2; \
485 vpsrld $5, x0 ## 2, x4 ## 2; \
486 vpslld $(32 - 5), x0 ## 2, x0 ## 2; \
487 vpor x4 ## 2, x0 ## 2, x0 ## 2; \
488 vpxor RK3, x3 ## 2, x3 ## 2; \
489 vpxor RK1, x1 ## 2, x1 ## 2; \
490 vpsrld $22, x2 ## 2, x4 ## 2; \
491 vpslld $(32 - 22), x2 ## 2, x2 ## 2; \
492 vpor x4 ## 2, x2 ## 2, x2 ## 2; \
493 vpxor x3 ## 2, x2 ## 2, x2 ## 2; \
494 vpxor x3 ## 1, x0 ## 1, x0 ## 1; \
495 vpslld $7, x1 ## 1, x4 ## 1; \
496 vpxor x1 ## 1, x0 ## 1, x0 ## 1; \
497 vpxor x4 ## 1, x2 ## 1, x2 ## 1; \
498 vpsrld $1, x1 ## 1, x4 ## 1; \
499 vpslld $(32 - 1), x1 ## 1, x1 ## 1; \
500 vpor x4 ## 1, x1 ## 1, x1 ## 1; \
501 vpxor x3 ## 2, x0 ## 2, x0 ## 2; \
502 vpslld $7, x1 ## 2, x4 ## 2; \
503 vpxor x1 ## 2, x0 ## 2, x0 ## 2; \
504 vpxor x4 ## 2, x2 ## 2, x2 ## 2; \
505 vpsrld $1, x1 ## 2, x4 ## 2; \
506 vpslld $(32 - 1), x1 ## 2, x1 ## 2; \
507 vpor x4 ## 2, x1 ## 2, x1 ## 2; \
508 vpsrld $7, x3 ## 1, x4 ## 1; \
509 vpslld $(32 - 7), x3 ## 1, x3 ## 1; \
510 vpor x4 ## 1, x3 ## 1, x3 ## 1; \
511 vpxor x0 ## 1, x1 ## 1, x1 ## 1; \
512 vpslld $3, x0 ## 1, x4 ## 1; \
513 vpxor x4 ## 1, x3 ## 1, x3 ## 1; \
514 vpsrld $7, x3 ## 2, x4 ## 2; \
515 vpslld $(32 - 7), x3 ## 2, x3 ## 2; \
516 vpor x4 ## 2, x3 ## 2, x3 ## 2; \
517 vpxor x0 ## 2, x1 ## 2, x1 ## 2; \
518 vpslld $3, x0 ## 2, x4 ## 2; \
519 vpxor x4 ## 2, x3 ## 2, x3 ## 2; \
520 vpsrld $13, x0 ## 1, x4 ## 1; \
521 vpslld $(32 - 13), x0 ## 1, x0 ## 1; \
522 vpor x4 ## 1, x0 ## 1, x0 ## 1; \
523 vpxor x2 ## 1, x1 ## 1, x1 ## 1; \
524 vpxor x2 ## 1, x3 ## 1, x3 ## 1; \
525 vpsrld $3, x2 ## 1, x4 ## 1; \
526 vpslld $(32 - 3), x2 ## 1, x2 ## 1; \
527 vpor x4 ## 1, x2 ## 1, x2 ## 1; \
528 vpsrld $13, x0 ## 2, x4 ## 2; \
529 vpslld $(32 - 13), x0 ## 2, x0 ## 2; \
530 vpor x4 ## 2, x0 ## 2, x0 ## 2; \
531 vpxor x2 ## 2, x1 ## 2, x1 ## 2; \
532 vpxor x2 ## 2, x3 ## 2, x3 ## 2; \
533 vpsrld $3, x2 ## 2, x4 ## 2; \
534 vpslld $(32 - 3), x2 ## 2, x2 ## 2; \
535 vpor x4 ## 2, x2 ## 2, x2 ## 2;
537 #define S(SBOX, x0, x1, x2, x3, x4) \
538 SBOX ## _1(x0 ## 1, x1 ## 1, x2 ## 1, x3 ## 1, x4 ## 1); \
539 SBOX ## _2(x0 ## 1, x1 ## 1, x2 ## 1, x3 ## 1, x4 ## 1); \
540 SBOX ## _1(x0 ## 2, x1 ## 2, x2 ## 2, x3 ## 2, x4 ## 2); \
541 SBOX ## _2(x0 ## 2, x1 ## 2, x2 ## 2, x3 ## 2, x4 ## 2);
543 #define SP(SBOX, x0, x1, x2, x3, x4, i) \
544 get_key(i, 0, RK0); \
545 SBOX ## _1(x0 ## 1, x1 ## 1, x2 ## 1, x3 ## 1, x4 ## 1); \
546 get_key(i, 2, RK2); \
547 SBOX ## _2(x0 ## 1, x1 ## 1, x2 ## 1, x3 ## 1, x4 ## 1); \
548 get_key(i, 3, RK3); \
549 SBOX ## _1(x0 ## 2, x1 ## 2, x2 ## 2, x3 ## 2, x4 ## 2); \
550 get_key(i, 1, RK1); \
551 SBOX ## _2(x0 ## 2, x1 ## 2, x2 ## 2, x3 ## 2, x4 ## 2); \
553 #define transpose_4x4(x0, x1, x2, x3, t0, t1, t2) \
554 vpunpckldq x1, x0, t0; \
555 vpunpckhdq x1, x0, t2; \
556 vpunpckldq x3, x2, t1; \
557 vpunpckhdq x3, x2, x3; \
559 vpunpcklqdq t1, t0, x0; \
560 vpunpckhqdq t1, t0, x1; \
561 vpunpcklqdq x3, t2, x2; \
562 vpunpckhqdq x3, t2, x3;
564 #define read_blocks(x0, x1, x2, x3, t0, t1, t2) \
565 transpose_4x4(x0, x1, x2, x3, t0, t1, t2)
567 #define write_blocks(x0, x1, x2, x3, t0, t1, t2) \
568 transpose_4x4(x0, x1, x2, x3, t0, t1, t2)
571 __serpent_enc_blk8_avx:
574 * RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: blocks
576 * RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: encrypted blocks
579 vpcmpeqd RNOT, RNOT, RNOT;
581 read_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
582 read_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
584 K2(RA, RB, RC, RD, RE, 0);
585 S(S0, RA, RB, RC, RD, RE); LK2(RC, RB, RD, RA, RE, 1);
586 S(S1, RC, RB, RD, RA, RE); LK2(RE, RD, RA, RC, RB, 2);
587 S(S2, RE, RD, RA, RC, RB); LK2(RB, RD, RE, RC, RA, 3);
588 S(S3, RB, RD, RE, RC, RA); LK2(RC, RA, RD, RB, RE, 4);
589 S(S4, RC, RA, RD, RB, RE); LK2(RA, RD, RB, RE, RC, 5);
590 S(S5, RA, RD, RB, RE, RC); LK2(RC, RA, RD, RE, RB, 6);
591 S(S6, RC, RA, RD, RE, RB); LK2(RD, RB, RA, RE, RC, 7);
592 S(S7, RD, RB, RA, RE, RC); LK2(RC, RA, RE, RD, RB, 8);
593 S(S0, RC, RA, RE, RD, RB); LK2(RE, RA, RD, RC, RB, 9);
594 S(S1, RE, RA, RD, RC, RB); LK2(RB, RD, RC, RE, RA, 10);
595 S(S2, RB, RD, RC, RE, RA); LK2(RA, RD, RB, RE, RC, 11);
596 S(S3, RA, RD, RB, RE, RC); LK2(RE, RC, RD, RA, RB, 12);
597 S(S4, RE, RC, RD, RA, RB); LK2(RC, RD, RA, RB, RE, 13);
598 S(S5, RC, RD, RA, RB, RE); LK2(RE, RC, RD, RB, RA, 14);
599 S(S6, RE, RC, RD, RB, RA); LK2(RD, RA, RC, RB, RE, 15);
600 S(S7, RD, RA, RC, RB, RE); LK2(RE, RC, RB, RD, RA, 16);
601 S(S0, RE, RC, RB, RD, RA); LK2(RB, RC, RD, RE, RA, 17);
602 S(S1, RB, RC, RD, RE, RA); LK2(RA, RD, RE, RB, RC, 18);
603 S(S2, RA, RD, RE, RB, RC); LK2(RC, RD, RA, RB, RE, 19);
604 S(S3, RC, RD, RA, RB, RE); LK2(RB, RE, RD, RC, RA, 20);
605 S(S4, RB, RE, RD, RC, RA); LK2(RE, RD, RC, RA, RB, 21);
606 S(S5, RE, RD, RC, RA, RB); LK2(RB, RE, RD, RA, RC, 22);
607 S(S6, RB, RE, RD, RA, RC); LK2(RD, RC, RE, RA, RB, 23);
608 S(S7, RD, RC, RE, RA, RB); LK2(RB, RE, RA, RD, RC, 24);
609 S(S0, RB, RE, RA, RD, RC); LK2(RA, RE, RD, RB, RC, 25);
610 S(S1, RA, RE, RD, RB, RC); LK2(RC, RD, RB, RA, RE, 26);
611 S(S2, RC, RD, RB, RA, RE); LK2(RE, RD, RC, RA, RB, 27);
612 S(S3, RE, RD, RC, RA, RB); LK2(RA, RB, RD, RE, RC, 28);
613 S(S4, RA, RB, RD, RE, RC); LK2(RB, RD, RE, RC, RA, 29);
614 S(S5, RB, RD, RE, RC, RA); LK2(RA, RB, RD, RC, RE, 30);
615 S(S6, RA, RB, RD, RC, RE); LK2(RD, RE, RB, RC, RA, 31);
616 S(S7, RD, RE, RB, RC, RA); K2(RA, RB, RC, RD, RE, 32);
618 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
619 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
622 ENDPROC(__serpent_enc_blk8_avx)
625 __serpent_dec_blk8_avx:
628 * RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: encrypted blocks
630 * RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2: decrypted blocks
633 vpcmpeqd RNOT, RNOT, RNOT;
635 read_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
636 read_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
638 K2(RA, RB, RC, RD, RE, 32);
639 SP(SI7, RA, RB, RC, RD, RE, 31); KL2(RB, RD, RA, RE, RC, 31);
640 SP(SI6, RB, RD, RA, RE, RC, 30); KL2(RA, RC, RE, RB, RD, 30);
641 SP(SI5, RA, RC, RE, RB, RD, 29); KL2(RC, RD, RA, RE, RB, 29);
642 SP(SI4, RC, RD, RA, RE, RB, 28); KL2(RC, RA, RB, RE, RD, 28);
643 SP(SI3, RC, RA, RB, RE, RD, 27); KL2(RB, RC, RD, RE, RA, 27);
644 SP(SI2, RB, RC, RD, RE, RA, 26); KL2(RC, RA, RE, RD, RB, 26);
645 SP(SI1, RC, RA, RE, RD, RB, 25); KL2(RB, RA, RE, RD, RC, 25);
646 SP(SI0, RB, RA, RE, RD, RC, 24); KL2(RE, RC, RA, RB, RD, 24);
647 SP(SI7, RE, RC, RA, RB, RD, 23); KL2(RC, RB, RE, RD, RA, 23);
648 SP(SI6, RC, RB, RE, RD, RA, 22); KL2(RE, RA, RD, RC, RB, 22);
649 SP(SI5, RE, RA, RD, RC, RB, 21); KL2(RA, RB, RE, RD, RC, 21);
650 SP(SI4, RA, RB, RE, RD, RC, 20); KL2(RA, RE, RC, RD, RB, 20);
651 SP(SI3, RA, RE, RC, RD, RB, 19); KL2(RC, RA, RB, RD, RE, 19);
652 SP(SI2, RC, RA, RB, RD, RE, 18); KL2(RA, RE, RD, RB, RC, 18);
653 SP(SI1, RA, RE, RD, RB, RC, 17); KL2(RC, RE, RD, RB, RA, 17);
654 SP(SI0, RC, RE, RD, RB, RA, 16); KL2(RD, RA, RE, RC, RB, 16);
655 SP(SI7, RD, RA, RE, RC, RB, 15); KL2(RA, RC, RD, RB, RE, 15);
656 SP(SI6, RA, RC, RD, RB, RE, 14); KL2(RD, RE, RB, RA, RC, 14);
657 SP(SI5, RD, RE, RB, RA, RC, 13); KL2(RE, RC, RD, RB, RA, 13);
658 SP(SI4, RE, RC, RD, RB, RA, 12); KL2(RE, RD, RA, RB, RC, 12);
659 SP(SI3, RE, RD, RA, RB, RC, 11); KL2(RA, RE, RC, RB, RD, 11);
660 SP(SI2, RA, RE, RC, RB, RD, 10); KL2(RE, RD, RB, RC, RA, 10);
661 SP(SI1, RE, RD, RB, RC, RA, 9); KL2(RA, RD, RB, RC, RE, 9);
662 SP(SI0, RA, RD, RB, RC, RE, 8); KL2(RB, RE, RD, RA, RC, 8);
663 SP(SI7, RB, RE, RD, RA, RC, 7); KL2(RE, RA, RB, RC, RD, 7);
664 SP(SI6, RE, RA, RB, RC, RD, 6); KL2(RB, RD, RC, RE, RA, 6);
665 SP(SI5, RB, RD, RC, RE, RA, 5); KL2(RD, RA, RB, RC, RE, 5);
666 SP(SI4, RD, RA, RB, RC, RE, 4); KL2(RD, RB, RE, RC, RA, 4);
667 SP(SI3, RD, RB, RE, RC, RA, 3); KL2(RE, RD, RA, RC, RB, 3);
668 SP(SI2, RE, RD, RA, RC, RB, 2); KL2(RD, RB, RC, RA, RE, 2);
669 SP(SI1, RD, RB, RC, RA, RE, 1); KL2(RE, RB, RC, RA, RD, 1);
670 S(SI0, RE, RB, RC, RA, RD); K2(RC, RD, RB, RE, RA, 0);
672 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
673 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
676 ENDPROC(__serpent_dec_blk8_avx)
678 ENTRY(serpent_ecb_enc_8way_avx)
685 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
687 call __serpent_enc_blk8_avx;
689 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
692 ENDPROC(serpent_ecb_enc_8way_avx)
694 ENTRY(serpent_ecb_dec_8way_avx)
701 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
703 call __serpent_dec_blk8_avx;
705 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
708 ENDPROC(serpent_ecb_dec_8way_avx)
710 ENTRY(serpent_cbc_dec_8way_avx)
717 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
719 call __serpent_dec_blk8_avx;
721 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
724 ENDPROC(serpent_cbc_dec_8way_avx)
726 ENTRY(serpent_ctr_8way_avx)
731 * %rcx: iv (little endian, 128bit)
734 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
737 call __serpent_enc_blk8_avx;
739 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
742 ENDPROC(serpent_ctr_8way_avx)
744 ENTRY(serpent_xts_enc_8way_avx)
749 * %rcx: iv (t ⊕ αⁿ ∈ GF(2¹²⁸))
752 /* regs <= src, dst <= IVs, regs <= regs xor IVs */
753 load_xts_8way(%rcx, %rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2,
754 RK0, RK1, RK2, .Lxts_gf128mul_and_shl1_mask);
756 call __serpent_enc_blk8_avx;
758 /* dst <= regs xor IVs(in dst) */
759 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
762 ENDPROC(serpent_xts_enc_8way_avx)
764 ENTRY(serpent_xts_dec_8way_avx)
769 * %rcx: iv (t ⊕ αⁿ ∈ GF(2¹²⁸))
772 /* regs <= src, dst <= IVs, regs <= regs xor IVs */
773 load_xts_8way(%rcx, %rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2,
774 RK0, RK1, RK2, .Lxts_gf128mul_and_shl1_mask);
776 call __serpent_dec_blk8_avx;
778 /* dst <= regs xor IVs(in dst) */
779 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
782 ENDPROC(serpent_xts_dec_8way_avx)