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 # ====================================================================
10 # GHASH for for PowerISA v2.07.
14 # Accurate performance measurements are problematic, because it's
15 # always virtualized setup with possibly throttled processor.
16 # Relative comparison is therefore more informative. This initial
17 # version is ~2.1x slower than hardware-assisted AES-128-CTR, ~12x
18 # faster than "4-bit" integer-only compiler-generated 64-bit code.
19 # "Initial version" means that there is room for futher improvement.
24 if ($flavour =~ /64/) {
30 } elsif ($flavour =~ /32/) {
36 } else { die "nonsense $flavour"; }
38 $0 =~ m/(.*[\/\\])[^\
/\\]+$/; $dir=$1;
39 ( $xlate="${dir}ppc-xlate.pl" and -f
$xlate ) or
40 ( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f
$xlate) or
41 die "can't locate ppc-xlate.pl";
43 open STDOUT
,"| $^X $xlate $flavour $output" || die "can't call $xlate: $!";
45 my ($Xip,$Htbl,$inp,$len)=map("r$_",(3..6)); # argument block
47 my ($Xl,$Xm,$Xh,$IN)=map("v$_",(0..3));
48 my ($zero,$t0,$t1,$t2,$xC2,$H,$Hh,$Hl,$lemask)=map("v$_",(4..12));
63 lvx_u
$H,0,r4
# load H
65 le?addi r7
,r7
,0x8 # need a vperm start with 08
68 le?vxor
5,5,6 # set a b-endian mask
71 vspltisb
$xC2,-16 # 0xf0
73 vaddubm
$xC2,$xC2,$xC2 # 0xe0
74 vxor
$zero,$zero,$zero
75 vor
$xC2,$xC2,$t0 # 0xe1
76 vsldoi
$xC2,$xC2,$zero,15 # 0xe1...
77 vsldoi
$t1,$zero,$t0,1 # ...1
78 vaddubm
$xC2,$xC2,$xC2 # 0xc2...
80 vor
$xC2,$xC2,$t1 # 0xc2....01
81 vspltb
$t1,$H,0 # most significant byte
83 vsrab
$t1,$t1,$t2 # broadcast carry bit
85 vxor
$H,$H,$t1 # twisted H
87 vsldoi
$H,$H,$H,8 # twist even more ...
88 vsldoi
$xC2,$zero,$xC2,8 # 0xc2.0
89 vsldoi
$Hl,$zero,$H,8 # ... and split
92 stvx_u
$xC2,0,r3
# save pre-computed table
100 .byte
0,12,0x14,0,0,0,2,0
102 .size
.gcm_init_p8
,.-.gcm_init_p8
111 lvx_u
$IN,0,$Xip # load Xi
113 lvx_u
$Hl,r8
,$Htbl # load pre-computed table
114 le?lvsl
$lemask,r0
,r0
118 le?vxor
$lemask,$lemask,$t0
120 le?vperm
$IN,$IN,$IN,$lemask
121 vxor
$zero,$zero,$zero
123 vpmsumd
$Xl,$IN,$Hl # H.lo·Xi.lo
124 vpmsumd
$Xm,$IN,$H # H.hi·Xi.lo+H.lo·Xi.hi
125 vpmsumd
$Xh,$IN,$Hh # H.hi·Xi.hi
127 vpmsumd
$t2,$Xl,$xC2 # 1st phase
129 vsldoi
$t0,$Xm,$zero,8
130 vsldoi
$t1,$zero,$Xm,8
137 vsldoi
$t1,$Xl,$Xl,8 # 2nd phase
142 le?vperm
$Xl,$Xl,$Xl,$lemask
143 stvx_u
$Xl,0,$Xip # write out Xi
148 .byte
0,12,0x14,0,0,0,2,0
150 .size
.gcm_gmult_p8
,.-.gcm_gmult_p8
159 lvx_u
$Xl,0,$Xip # load Xi
161 lvx_u
$Hl,r8
,$Htbl # load pre-computed table
162 le?lvsl
$lemask,r0
,r0
166 le?vxor
$lemask,$lemask,$t0
168 le?vperm
$Xl,$Xl,$Xl,$lemask
169 vxor
$zero,$zero,$zero
174 le?vperm
$IN,$IN,$IN,$lemask
181 vpmsumd
$Xl,$IN,$Hl # H.lo·Xi.lo
182 subfe
. r0
,r0
,r0
# borrow?-1:0
183 vpmsumd
$Xm,$IN,$H # H.hi·Xi.lo+H.lo·Xi.hi
185 vpmsumd
$Xh,$IN,$Hh # H.hi·Xi.hi
188 vpmsumd
$t2,$Xl,$xC2 # 1st phase
190 vsldoi
$t0,$Xm,$zero,8
191 vsldoi
$t1,$zero,$Xm,8
200 vsldoi
$t1,$Xl,$Xl,8 # 2nd phase
202 le?vperm
$IN,$IN,$IN,$lemask
206 beq Loop
# did $len-=16 borrow?
209 le?vperm
$Xl,$Xl,$Xl,$lemask
210 stvx_u
$Xl,0,$Xip # write out Xi
215 .byte
0,12,0x14,0,0,0,4,0
217 .size
.gcm_ghash_p8
,.-.gcm_ghash_p8
219 .asciz
"GHASH for PowerISA 2.07, CRYPTOGAMS by <appro\@openssl.org>"
223 foreach (split("\n",$code)) {
224 if ($flavour =~ /le$/o) { # little-endian
234 close STDOUT
; # enforce flush