3 # ====================================================================
4 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
5 # project. The module is, however, dual licensed under OpenSSL and
6 # CRYPTOGAMS licenses depending on where you obtain it. For further
7 # details see http://www.openssl.org/~appro/cryptogams/.
8 # ====================================================================
12 # The module implements "4-bit" GCM GHASH function and underlying
13 # single multiplication operation in GF(2^128). "4-bit" means that
14 # it uses 256 bytes per-key table [+128 bytes shared table]. GHASH
15 # function features so called "528B" variant utilizing additional
16 # 256+16 bytes of per-key storage [+512 bytes shared table].
17 # Performance results are for this streamed GHASH subroutine and are
18 # expressed in cycles per processed byte, less is better:
20 # gcc 3.4.x(*) assembler
23 # Opteron 19.3 7.7 +150%
24 # Core2 17.8 8.1(**) +120%
26 # VIA Nano 21.8 10.1 +115%
28 # (*) comparison is not completely fair, because C results are
29 # for vanilla "256B" implementation, while assembler results
31 # (**) it's mystery [to me] why Core2 result is not same as for
36 # Add PCLMULQDQ version performing at 2.02 cycles per processed byte.
37 # See ghash-x86.pl for background information and details about coding
40 # Special thanks to David Woodhouse <dwmw2@infradead.org> for
41 # providing access to a Westmere-based system on behalf of Intel
42 # Open Source Technology Centre.
46 # Overhaul: aggregate Karatsuba post-processing, improve ILP in
47 # reduction_alg9, increase reduction aggregate factor to 4x. As for
48 # the latter. ghash-x86.pl discusses that it makes lesser sense to
49 # increase aggregate factor. Then why increase here? Critical path
50 # consists of 3 independent pclmulqdq instructions, Karatsuba post-
51 # processing and reduction. "On top" of this we lay down aggregated
52 # multiplication operations, triplets of independent pclmulqdq's. As
53 # issue rate for pclmulqdq is limited, it makes lesser sense to
54 # aggregate more multiplications than it takes to perform remaining
55 # non-multiplication operations. 2x is near-optimal coefficient for
56 # contemporary Intel CPUs (therefore modest improvement coefficient),
57 # but not for Bulldozer. Latter is because logical SIMD operations
58 # are twice as slow in comparison to Intel, so that critical path is
59 # longer. A CPU with higher pclmulqdq issue rate would also benefit
60 # from higher aggregate factor...
63 # Sandy Bridge 1.79(+9%)
64 # Ivy Bridge 1.79(+8%)
65 # Bulldozer 1.52(+25%)
69 if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
71 $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
73 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
74 ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
75 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
76 die "can't locate x86_64-xlate.pl";
78 open OUT,"| \"$^X\" $xlate $flavour $output";
83 # common register layout
94 # per-function register layout
98 sub LB() { my $r=shift; $r =~ s/%[er]([a-d])x/%\1l/ or
99 $r =~ s/%[er]([sd]i)/%\1l/ or
100 $r =~ s/%[er](bp)/%\1l/ or
101 $r =~ s/%(r[0-9]+)[d]?/%\1b/; $r; }
103 sub AUTOLOAD() # thunk [simplified] 32-bit style perlasm
104 { my $opcode = $AUTOLOAD; $opcode =~ s/.*:://;
106 $arg = "\$$arg" if ($arg*1 eq $arg);
107 $code .= "\t$opcode\t".join(',',$arg,reverse @_)."\n";
118 mov `&LB("$Zlo")`,`&LB("$nlo")`
119 mov `&LB("$Zlo")`,`&LB("$nhi")`
120 shl \$4,`&LB("$nlo")`
122 mov 8($Htbl,$nlo),$Zlo
123 mov ($Htbl,$nlo),$Zhi
124 and \$0xf0,`&LB("$nhi")`
133 mov ($inp,$cnt),`&LB("$nlo")`
135 xor 8($Htbl,$nhi),$Zlo
137 xor ($Htbl,$nhi),$Zhi
138 mov `&LB("$nlo")`,`&LB("$nhi")`
139 xor ($rem_4bit,$rem,8),$Zhi
141 shl \$4,`&LB("$nlo")`
150 xor 8($Htbl,$nlo),$Zlo
152 xor ($Htbl,$nlo),$Zhi
153 and \$0xf0,`&LB("$nhi")`
154 xor ($rem_4bit,$rem,8),$Zhi
165 xor 8($Htbl,$nlo),$Zlo
167 xor ($Htbl,$nlo),$Zhi
168 and \$0xf0,`&LB("$nhi")`
169 xor ($rem_4bit,$rem,8),$Zhi
177 xor 8($Htbl,$nhi),$Zlo
179 xor ($Htbl,$nhi),$Zhi
181 xor ($rem_4bit,$rem,8),$Zhi
191 .globl gcm_gmult_4bit
192 .type gcm_gmult_4bit,\@function,2
196 push %rbp # %rbp and %r12 are pushed exclusively in
197 push %r12 # order to reuse Win64 exception handler...
201 lea .Lrem_4bit(%rip),$rem_4bit
212 .size gcm_gmult_4bit,.-gcm_gmult_4bit
215 # per-function register layout
221 .globl gcm_ghash_4bit
222 .type gcm_ghash_4bit,\@function,4
233 mov $inp,%r14 # reassign couple of args
239 my @nhi=("%ebx","%ecx");
240 my @rem=("%r12","%r13");
243 &sub ($Htbl,-128); # size optimization
244 &lea ($Hshr4,"16+128(%rsp)");
245 { my @lo =($nlo,$nhi);
249 for ($i=0,$j=-2;$i<18;$i++,$j++) {
250 &mov ("$j(%rsp)",&LB($dat)) if ($i>1);
251 &or ($lo[0],$tmp) if ($i>1);
252 &mov (&LB($dat),&LB($lo[1])) if ($i>0 && $i<17);
253 &shr ($lo[1],4) if ($i>0 && $i<17);
254 &mov ($tmp,$hi[1]) if ($i>0 && $i<17);
255 &shr ($hi[1],4) if ($i>0 && $i<17);
256 &mov ("8*$j($Hshr4)",$hi[0]) if ($i>1);
257 &mov ($hi[0],"16*$i+0-128($Htbl)") if ($i<16);
258 &shl (&LB($dat),4) if ($i>0 && $i<17);
259 &mov ("8*$j-128($Hshr4)",$lo[0]) if ($i>1);
260 &mov ($lo[0],"16*$i+8-128($Htbl)") if ($i<16);
261 &shl ($tmp,60) if ($i>0 && $i<17);
263 push (@lo,shift(@lo));
264 push (@hi,shift(@hi));
268 &mov ($Zlo,"8($Xi)");
269 &mov ($Zhi,"0($Xi)");
270 &add ($len,$inp); # pointer to the end of data
271 &lea ($rem_8bit,".Lrem_8bit(%rip)");
272 &jmp (".Louter_loop");
274 $code.=".align 16\n.Louter_loop:\n";
275 &xor ($Zhi,"($inp)");
276 &mov ("%rdx","8($inp)");
277 &lea ($inp,"16($inp)");
280 &mov ("8($Xi)","%rdx");
285 &mov (&LB($nlo),&LB($dat));
286 &movz ($nhi[0],&LB($dat));
290 for ($j=11,$i=0;$i<15;$i++) {
292 &xor ($Zlo,"8($Htbl,$nlo)") if ($i>0);
293 &xor ($Zhi,"($Htbl,$nlo)") if ($i>0);
294 &mov ($Zlo,"8($Htbl,$nlo)") if ($i==0);
295 &mov ($Zhi,"($Htbl,$nlo)") if ($i==0);
297 &mov (&LB($nlo),&LB($dat));
298 &xor ($Zlo,$tmp) if ($i>0);
299 &movzw ($rem[1],"($rem_8bit,$rem[1],2)") if ($i>0);
301 &movz ($nhi[1],&LB($dat));
303 &movzb ($rem[0],"(%rsp,$nhi[0])");
305 &shr ($nhi[1],4) if ($i<14);
306 &and ($nhi[1],0xf0) if ($i==14);
307 &shl ($rem[1],48) if ($i>0);
311 &xor ($Zhi,$rem[1]) if ($i>0);
314 &movz ($rem[0],&LB($rem[0]));
315 &mov ($dat,"$j($Xi)") if (--$j%4==0);
318 &xor ($Zlo,"-128($Hshr4,$nhi[0],8)");
320 &xor ($Zhi,"($Hshr4,$nhi[0],8)");
322 unshift (@nhi,pop(@nhi)); # "rotate" registers
323 unshift (@rem,pop(@rem));
325 &movzw ($rem[1],"($rem_8bit,$rem[1],2)");
326 &xor ($Zlo,"8($Htbl,$nlo)");
327 &xor ($Zhi,"($Htbl,$nlo)");
333 &movz ($rem[0],&LB($Zlo));
337 &shl (&LB($rem[0]),4);
340 &xor ($Zlo,"8($Htbl,$nhi[0])");
341 &movzw ($rem[0],"($rem_8bit,$rem[0],2)");
344 &xor ($Zhi,"($Htbl,$nhi[0])");
353 &jb (".Louter_loop");
369 .size gcm_ghash_4bit,.-gcm_ghash_4bit
372 ######################################################################
375 @_4args=$win64? ("%rcx","%rdx","%r8", "%r9") : # Win64 order
376 ("%rdi","%rsi","%rdx","%rcx"); # Unix order
378 ($Xi,$Xhi)=("%xmm0","%xmm1"); $Hkey="%xmm2";
379 ($T1,$T2,$T3)=("%xmm3","%xmm4","%xmm5");
381 sub clmul64x64_T2 { # minimal register pressure
382 my ($Xhi,$Xi,$Hkey,$HK)=@_;
384 if (!defined($HK)) { $HK = $T2;
387 pshufd \$0b01001110,$Xi,$T1
388 pshufd \$0b01001110,$Hkey,$T2
395 pshufd \$0b01001110,$Xi,$T1
400 pclmulqdq \$0x00,$Hkey,$Xi #######
401 pclmulqdq \$0x11,$Hkey,$Xhi #######
402 pclmulqdq \$0x00,$HK,$T1 #######
414 sub reduction_alg9 { # 17/11 times faster than Intel version
444 { my ($Htbl,$Xip)=@_4args;
447 .globl gcm_init_clmul
448 .type gcm_init_clmul,\@abi-omnipotent
452 pshufd \$0b01001110,$Hkey,$Hkey # dword swap
455 pshufd \$0b11111111,$Hkey,$T2 # broadcast uppermost dword
460 pcmpgtd $T2,$T3 # broadcast carry bit
462 por $T1,$Hkey # H<<=1
465 pand .L0x1c2_polynomial(%rip),$T3
466 pxor $T3,$Hkey # if(carry) H^=0x1c2_polynomial
471 &clmul64x64_T2 ($Xhi,$Xi,$Hkey);
472 &reduction_alg9 ($Xhi,$Xi);
474 pshufd \$0b01001110,$Hkey,$T1
475 pshufd \$0b01001110,$Xi,$T2
476 pxor $Hkey,$T1 # Karatsuba pre-processing
477 movdqu $Hkey,0x00($Htbl) # save H
478 pxor $Xi,$T2 # Karatsuba pre-processing
479 movdqu $Xi,0x10($Htbl) # save H^2
480 palignr \$8,$T1,$T2 # low part is H.lo^H.hi...
481 movdqu $T2,0x20($Htbl) # save Karatsuba "salt"
484 &clmul64x64_T2 ($Xhi,$Xi,$Hkey); # H^3
485 &reduction_alg9 ($Xhi,$Xi);
489 &clmul64x64_T2 ($Xhi,$Xi,$Hkey); # H^4
490 &reduction_alg9 ($Xhi,$Xi);
492 pshufd \$0b01001110,$T3,$T1
493 pshufd \$0b01001110,$Xi,$T2
494 pxor $T3,$T1 # Karatsuba pre-processing
495 movdqu $T3,0x30($Htbl) # save H^3
496 pxor $Xi,$T2 # Karatsuba pre-processing
497 movdqu $Xi,0x40($Htbl) # save H^4
498 palignr \$8,$T1,$T2 # low part is H.lo^H.hi...
499 movdqu $T2,0x50($Htbl) # save Karatsuba "salt"
504 .size gcm_init_clmul,.-gcm_init_clmul
508 { my ($Xip,$Htbl)=@_4args;
511 .globl gcm_gmult_clmul
512 .type gcm_gmult_clmul,\@abi-omnipotent
516 movdqa .Lbswap_mask(%rip),$T3
518 movdqu 0x20($Htbl),$T2
521 &clmul64x64_T2 ($Xhi,$Xi,$Hkey,$T2);
522 $code.=<<___ if (0 || (&reduction_alg9($Xhi,$Xi)&&0));
523 # experimental alternative. special thing about is that there
524 # no dependency between the two multiplications...
526 mov \$0xA040608020C0E000,%r10 # ((7..0)·0xE0)&0xff
530 movq %r11,$T3 # borrow $T3
532 pshufb $T3,$T2 # ($Xi&7)·0xE0
534 pclmulqdq \$0x00,$Xi,$T1 # ·(0xE1<<1)
537 paddd $T2,$T2 # <<(64+56+1)
539 pclmulqdq \$0x01,$T3,$Xi
540 movdqa .Lbswap_mask(%rip),$T3 # reload $T3
550 .size gcm_gmult_clmul,.-gcm_gmult_clmul
554 { my ($Xip,$Htbl,$inp,$len)=@_4args;
555 my ($Xln,$Xmn,$Xhn,$Hkey2,$HK) = map("%xmm$_",(6..10));
558 .globl gcm_ghash_clmul
559 .type gcm_ghash_clmul,\@abi-omnipotent
563 $code.=<<___ if ($win64);
565 .LSEH_begin_gcm_ghash_clmul:
566 # I can't trust assembler to use specific encoding:-(
567 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax),%rsp
568 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6,-0x20(%rax)
569 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7,-0x10(%rax)
570 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8,0(%rax)
571 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9,0x10(%rax)
572 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10,0x20(%rax)
573 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11,0x30(%rax)
574 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12,0x40(%rax)
575 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13,0x50(%rax)
576 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14,0x60(%rax)
577 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15,0x70(%rax)
580 movdqa .Lbswap_mask(%rip),$T3
581 mov \$0xA040608020C0E000,%rax # ((7..0)·0xE0)&0xff
585 movdqu 0x20($Htbl),$HK
591 movdqu 0x10($Htbl),$Hkey2
594 my ($Xl,$Xm,$Xh,$Hkey3,$Hkey4)=map("%xmm$_",(11..15));
601 movdqu 0x30($Htbl),$Hkey3
602 movdqu 0x40($Htbl),$Hkey4
605 # Xi+4 =[(H*Ii+3) + (H^2*Ii+2) + (H^3*Ii+1) + H^4*(Ii+Xi)] mod P
607 movdqu 0x30($inp),$Xln
608 movdqu 0x20($inp),$Xl
612 pshufd \$0b01001110,$Xln,$Xmn
614 pclmulqdq \$0x00,$Hkey,$Xln
615 pclmulqdq \$0x11,$Hkey,$Xhn
616 pclmulqdq \$0x00,$HK,$Xmn
619 pshufd \$0b01001110,$Xl,$Xm
621 pclmulqdq \$0x00,$Hkey2,$Xl
622 pclmulqdq \$0x11,$Hkey2,$Xh
624 pclmulqdq \$0x10,$HK,$Xm
626 movups 0x50($Htbl),$HK
629 movdqu 0x10($inp),$Xl
634 pshufd \$0b01001110,$Xl,$Xm
637 pclmulqdq \$0x00,$Hkey3,$Xl
639 pshufd \$0b01001110,$Xi,$T1
641 pclmulqdq \$0x11,$Hkey3,$Xh
643 pclmulqdq \$0x00,$HK,$Xm
653 pclmulqdq \$0x00,$Hkey4,$Xi
655 movdqu 0x30($inp),$Xl
657 pclmulqdq \$0x11,$Hkey4,$Xhi
659 movdqu 0x20($inp),$Xln
661 pshufd \$0b01001110,$Xl,$Xm
662 pclmulqdq \$0x10,$HK,$T1
666 movups 0x20($Htbl),$HK
667 pclmulqdq \$0x00,$Hkey,$Xl
670 pshufd \$0b01001110,$Xln,$Xmn
672 pxor $Xi,$T1 # aggregated Karatsuba post-processing
677 pclmulqdq \$0x11,$Hkey,$Xh
680 movdqa .L7_mask(%rip),$T1
684 pand $Xi,$T1 # 1st phase
686 pclmulqdq \$0x00,$HK,$Xm
691 pclmulqdq \$0x00,$Hkey2,$Xln
697 movdqa $Xi,$T2 # 2nd phase
699 pclmulqdq \$0x11,$Hkey2,$Xhn
701 movdqu 0x10($inp),$Xl
703 pclmulqdq \$0x10,$HK,$Xmn
705 movups 0x50($Htbl),$HK
713 pshufd \$0b01001110,$Xl,$Xm
715 pclmulqdq \$0x00,$Hkey3,$Xl
719 pclmulqdq \$0x11,$Hkey3,$Xh
723 pclmulqdq \$0x00,$HK,$Xm
727 pshufd \$0b01001110,$Xi,$T1
735 pclmulqdq \$0x00,$Hkey4,$Xi
737 pclmulqdq \$0x11,$Hkey4,$Xhi
739 pclmulqdq \$0x10,$HK,$T1
741 pxor $Xi,$Xhi # aggregated Karatsuba post-processing
753 &reduction_alg9($Xhi,$Xi);
757 movdqu 0x20($Htbl),$HK
765 # Xi+2 =[H*(Ii+1 + Xi+1)] mod P =
766 # [(H*Ii+1) + (H*Xi+1)] mod P =
767 # [(H*Ii+1) + H^2*(Ii+Xi)] mod P
769 movdqu ($inp),$T1 # Ii
770 movdqu 16($inp),$Xln # Ii+1
776 pshufd \$0b01001110,$Xln,$T1
778 pclmulqdq \$0x00,$Hkey,$Xln
779 pclmulqdq \$0x11,$Hkey,$Xhn
780 pclmulqdq \$0x00,$HK,$T1
782 lea 32($inp),$inp # i+=2
790 pshufd \$0b01001110,$Xi,$T2 #
793 pclmulqdq \$0x00,$Hkey2,$Xi
794 pclmulqdq \$0x11,$Hkey2,$Xhi
795 pclmulqdq \$0x10,$HK,$T2
797 pxor $Xln,$Xi # (H*Ii+1) + H^2*(Ii+Xi)
799 movdqu ($inp),$Xhn # Ii
801 movdqu 16($inp),$Xln # Ii+1
803 pxor $Xi,$T1 # aggregated Karatsuba post-processing
805 pxor $Xhn,$Xhi # "Ii+Xi", consume early
816 movdqa $Xi,$T2 # 1st phase
819 pclmulqdq \$0x00,$Hkey,$Xln #######
829 pshufd \$0b01001110,$Xhn,$T1
832 pclmulqdq \$0x11,$Hkey,$Xhn #######
833 movdqa $Xi,$T2 # 2nd phase
840 pclmulqdq \$0x00,$HK,$T1 #######
849 pshufd \$0b01001110,$Xi,$T2 #
852 pclmulqdq \$0x00,$Hkey2,$Xi
853 pclmulqdq \$0x11,$Hkey2,$Xhi
854 pclmulqdq \$0x10,$HK,$T2
856 pxor $Xln,$Xi # (H*Ii+1) + H^2*(Ii+Xi)
867 &reduction_alg9 ($Xhi,$Xi);
873 movdqu ($inp),$T1 # Ii
877 &clmul64x64_T2 ($Xhi,$Xi,$Hkey,$HK); # H*(Ii+Xi)
878 &reduction_alg9 ($Xhi,$Xi);
884 $code.=<<___ if ($win64);
886 movaps 0x10(%rsp),%xmm7
887 movaps 0x20(%rsp),%xmm8
888 movaps 0x30(%rsp),%xmm9
889 movaps 0x40(%rsp),%xmm10
890 movaps 0x50(%rsp),%xmm11
891 movaps 0x60(%rsp),%xmm12
892 movaps 0x70(%rsp),%xmm13
893 movaps 0x80(%rsp),%xmm14
894 movaps 0x90(%rsp),%xmm15
899 .LSEH_end_gcm_ghash_clmul:
900 .size gcm_ghash_clmul,.-gcm_ghash_clmul
907 .byte 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
909 .byte 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xc2
913 .long 7,0,`0xE1<<1`,0
915 .type .Lrem_4bit,\@object
917 .long 0,`0x0000<<16`,0,`0x1C20<<16`,0,`0x3840<<16`,0,`0x2460<<16`
918 .long 0,`0x7080<<16`,0,`0x6CA0<<16`,0,`0x48C0<<16`,0,`0x54E0<<16`
919 .long 0,`0xE100<<16`,0,`0xFD20<<16`,0,`0xD940<<16`,0,`0xC560<<16`
920 .long 0,`0x9180<<16`,0,`0x8DA0<<16`,0,`0xA9C0<<16`,0,`0xB5E0<<16`
921 .type .Lrem_8bit,\@object
923 .value 0x0000,0x01C2,0x0384,0x0246,0x0708,0x06CA,0x048C,0x054E
924 .value 0x0E10,0x0FD2,0x0D94,0x0C56,0x0918,0x08DA,0x0A9C,0x0B5E
925 .value 0x1C20,0x1DE2,0x1FA4,0x1E66,0x1B28,0x1AEA,0x18AC,0x196E
926 .value 0x1230,0x13F2,0x11B4,0x1076,0x1538,0x14FA,0x16BC,0x177E
927 .value 0x3840,0x3982,0x3BC4,0x3A06,0x3F48,0x3E8A,0x3CCC,0x3D0E
928 .value 0x3650,0x3792,0x35D4,0x3416,0x3158,0x309A,0x32DC,0x331E
929 .value 0x2460,0x25A2,0x27E4,0x2626,0x2368,0x22AA,0x20EC,0x212E
930 .value 0x2A70,0x2BB2,0x29F4,0x2836,0x2D78,0x2CBA,0x2EFC,0x2F3E
931 .value 0x7080,0x7142,0x7304,0x72C6,0x7788,0x764A,0x740C,0x75CE
932 .value 0x7E90,0x7F52,0x7D14,0x7CD6,0x7998,0x785A,0x7A1C,0x7BDE
933 .value 0x6CA0,0x6D62,0x6F24,0x6EE6,0x6BA8,0x6A6A,0x682C,0x69EE
934 .value 0x62B0,0x6372,0x6134,0x60F6,0x65B8,0x647A,0x663C,0x67FE
935 .value 0x48C0,0x4902,0x4B44,0x4A86,0x4FC8,0x4E0A,0x4C4C,0x4D8E
936 .value 0x46D0,0x4712,0x4554,0x4496,0x41D8,0x401A,0x425C,0x439E
937 .value 0x54E0,0x5522,0x5764,0x56A6,0x53E8,0x522A,0x506C,0x51AE
938 .value 0x5AF0,0x5B32,0x5974,0x58B6,0x5DF8,0x5C3A,0x5E7C,0x5FBE
939 .value 0xE100,0xE0C2,0xE284,0xE346,0xE608,0xE7CA,0xE58C,0xE44E
940 .value 0xEF10,0xEED2,0xEC94,0xED56,0xE818,0xE9DA,0xEB9C,0xEA5E
941 .value 0xFD20,0xFCE2,0xFEA4,0xFF66,0xFA28,0xFBEA,0xF9AC,0xF86E
942 .value 0xF330,0xF2F2,0xF0B4,0xF176,0xF438,0xF5FA,0xF7BC,0xF67E
943 .value 0xD940,0xD882,0xDAC4,0xDB06,0xDE48,0xDF8A,0xDDCC,0xDC0E
944 .value 0xD750,0xD692,0xD4D4,0xD516,0xD058,0xD19A,0xD3DC,0xD21E
945 .value 0xC560,0xC4A2,0xC6E4,0xC726,0xC268,0xC3AA,0xC1EC,0xC02E
946 .value 0xCB70,0xCAB2,0xC8F4,0xC936,0xCC78,0xCDBA,0xCFFC,0xCE3E
947 .value 0x9180,0x9042,0x9204,0x93C6,0x9688,0x974A,0x950C,0x94CE
948 .value 0x9F90,0x9E52,0x9C14,0x9DD6,0x9898,0x995A,0x9B1C,0x9ADE
949 .value 0x8DA0,0x8C62,0x8E24,0x8FE6,0x8AA8,0x8B6A,0x892C,0x88EE
950 .value 0x83B0,0x8272,0x8034,0x81F6,0x84B8,0x857A,0x873C,0x86FE
951 .value 0xA9C0,0xA802,0xAA44,0xAB86,0xAEC8,0xAF0A,0xAD4C,0xAC8E
952 .value 0xA7D0,0xA612,0xA454,0xA596,0xA0D8,0xA11A,0xA35C,0xA29E
953 .value 0xB5E0,0xB422,0xB664,0xB7A6,0xB2E8,0xB32A,0xB16C,0xB0AE
954 .value 0xBBF0,0xBA32,0xB874,0xB9B6,0xBCF8,0xBD3A,0xBF7C,0xBEBE
956 .asciz "GHASH for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
960 # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
961 # CONTEXT *context,DISPATCHER_CONTEXT *disp)
969 .extern __imp_RtlVirtualUnwind
970 .type se_handler,\@abi-omnipotent
984 mov 120($context),%rax # pull context->Rax
985 mov 248($context),%rbx # pull context->Rip
987 mov 8($disp),%rsi # disp->ImageBase
988 mov 56($disp),%r11 # disp->HandlerData
990 mov 0(%r11),%r10d # HandlerData[0]
991 lea (%rsi,%r10),%r10 # prologue label
992 cmp %r10,%rbx # context->Rip<prologue label
995 mov 152($context),%rax # pull context->Rsp
997 mov 4(%r11),%r10d # HandlerData[1]
998 lea (%rsi,%r10),%r10 # epilogue label
999 cmp %r10,%rbx # context->Rip>=epilogue label
1002 lea 24(%rax),%rax # adjust "rsp"
1007 mov %rbx,144($context) # restore context->Rbx
1008 mov %rbp,160($context) # restore context->Rbp
1009 mov %r12,216($context) # restore context->R12
1014 mov %rax,152($context) # restore context->Rsp
1015 mov %rsi,168($context) # restore context->Rsi
1016 mov %rdi,176($context) # restore context->Rdi
1018 mov 40($disp),%rdi # disp->ContextRecord
1019 mov $context,%rsi # context
1020 mov \$`1232/8`,%ecx # sizeof(CONTEXT)
1021 .long 0xa548f3fc # cld; rep movsq
1024 xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
1025 mov 8(%rsi),%rdx # arg2, disp->ImageBase
1026 mov 0(%rsi),%r8 # arg3, disp->ControlPc
1027 mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
1028 mov 40(%rsi),%r10 # disp->ContextRecord
1029 lea 56(%rsi),%r11 # &disp->HandlerData
1030 lea 24(%rsi),%r12 # &disp->EstablisherFrame
1031 mov %r10,32(%rsp) # arg5
1032 mov %r11,40(%rsp) # arg6
1033 mov %r12,48(%rsp) # arg7
1034 mov %rcx,56(%rsp) # arg8, (NULL)
1035 call *__imp_RtlVirtualUnwind(%rip)
1037 mov \$1,%eax # ExceptionContinueSearch
1049 .size se_handler,.-se_handler
1053 .rva .LSEH_begin_gcm_gmult_4bit
1054 .rva .LSEH_end_gcm_gmult_4bit
1055 .rva .LSEH_info_gcm_gmult_4bit
1057 .rva .LSEH_begin_gcm_ghash_4bit
1058 .rva .LSEH_end_gcm_ghash_4bit
1059 .rva .LSEH_info_gcm_ghash_4bit
1061 .rva .LSEH_begin_gcm_ghash_clmul
1062 .rva .LSEH_end_gcm_ghash_clmul
1063 .rva .LSEH_info_gcm_ghash_clmul
1067 .LSEH_info_gcm_gmult_4bit:
1070 .rva .Lgmult_prologue,.Lgmult_epilogue # HandlerData
1071 .LSEH_info_gcm_ghash_4bit:
1074 .rva .Lghash_prologue,.Lghash_epilogue # HandlerData
1075 .LSEH_info_gcm_ghash_clmul:
1076 .byte 0x01,0x33,0x16,0x00
1077 .byte 0x33,0xf8,0x09,0x00 #movaps 0x90(rsp),xmm15
1078 .byte 0x2e,0xe8,0x08,0x00 #movaps 0x80(rsp),xmm14
1079 .byte 0x29,0xd8,0x07,0x00 #movaps 0x70(rsp),xmm13
1080 .byte 0x24,0xc8,0x06,0x00 #movaps 0x60(rsp),xmm12
1081 .byte 0x1f,0xb8,0x05,0x00 #movaps 0x50(rsp),xmm11
1082 .byte 0x1a,0xa8,0x04,0x00 #movaps 0x40(rsp),xmm10
1083 .byte 0x15,0x98,0x03,0x00 #movaps 0x30(rsp),xmm9
1084 .byte 0x10,0x88,0x02,0x00 #movaps 0x20(rsp),xmm8
1085 .byte 0x0c,0x78,0x01,0x00 #movaps 0x10(rsp),xmm7
1086 .byte 0x08,0x68,0x00,0x00 #movaps 0x00(rsp),xmm6
1087 .byte 0x04,0x01,0x15,0x00 #sub 0xa8,rsp
1091 $code =~ s/\`([^\`]*)\`/eval($1)/gem;