2 # Copyright 2009-2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
10 # ====================================================================
11 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
12 # project. The module is, however, dual licensed under OpenSSL and
13 # CRYPTOGAMS licenses depending on where you obtain it. For further
14 # details see http://www.openssl.org/~appro/cryptogams/.
15 # ====================================================================
17 # SHA1 block procedure for PA-RISC.
21 # On PA-7100LC performance is >30% better than gcc 3.2 generated code
22 # for aligned input and >50% better for unaligned. Compared to vendor
23 # compiler on PA-8600 it's almost 60% faster in 64-bit build and just
24 # few percent faster in 32-bit one (this for aligned input, data for
25 # unaligned input is not available).
27 # Special thanks to polarhome.com for providing HP-UX account.
29 # $output is the last argument if it looks like a file (it has an extension)
30 # $flavour is the first argument if it doesn't look like a file
31 $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
32 $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
34 $output and open STDOUT,">$output";
36 if ($flavour =~ /64/) {
56 $FRAME=14*$SIZE_T+$FRAME_MARKER;# 14 saved regs + frame marker
57 # [+ argument transfer]
66 @X=("%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", "%r8",
67 "%r9", "%r10","%r11","%r12","%r13","%r14","%r15","%r16",$t0);
69 @V=($A,$B,$C,$D,$E)=("%r19","%r20","%r21","%r22","%r23");
72 my ($i,$a,$b,$c,$d,$e)=@_;
74 $code.=<<___ if ($i<15);
85 $code.=<<___ if ($i>=15); # with forward Xupdate
88 xor @X[($j+2)%16],@X[$j%16],@X[$j%16]
91 xor @X[($j+8)%16],@X[$j%16],@X[$j%16]
96 xor @X[($j+13)%16],@X[$j%16],@X[$j%16]
98 shd @X[$j%16],@X[$j%16],31,@X[$j%16]
103 my ($i,$a,$b,$c,$d,$e)=@_;
105 $code.=<<___ if ($i<79);
106 xor @X[($j+2)%16],@X[$j%16],@X[$j%16] ; $i
109 xor @X[($j+8)%16],@X[$j%16],@X[$j%16]
112 xor @X[($j+13)%16],@X[$j%16],@X[$j%16]
116 shd @X[$j%16],@X[$j%16],31,@X[$j%16]
119 $code.=<<___ if ($i==79); # with context load
120 ldw 0($ctx),@X[0] ; $i
137 my ($i,$a,$b,$c,$d,$e)=@_;
140 shd $a,$a,27,$t1 ; $i
142 xor @X[($j+2)%16],@X[$j%16],@X[$j%16]
145 xor @X[($j+8)%16],@X[$j%16],@X[$j%16]
149 xor @X[($j+13)%16],@X[$j%16],@X[$j%16]
152 shd @X[$j%16],@X[$j%16],31,@X[$j%16]
160 .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY
162 .EXPORT sha1_block_data_order,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR
163 sha1_block_data_order
165 .CALLINFO FRAME=`$FRAME-14*$SIZE_T`,NO_CALLS,SAVE_RP,ENTRY_GR=16
167 $PUSH %r2,-$SAVED_RP(%sp) ; standard prologue
168 $PUSHMA %r3,$FRAME(%sp)
169 $PUSH %r4,`-$FRAME+1*$SIZE_T`(%sp)
170 $PUSH %r5,`-$FRAME+2*$SIZE_T`(%sp)
171 $PUSH %r6,`-$FRAME+3*$SIZE_T`(%sp)
172 $PUSH %r7,`-$FRAME+4*$SIZE_T`(%sp)
173 $PUSH %r8,`-$FRAME+5*$SIZE_T`(%sp)
174 $PUSH %r9,`-$FRAME+6*$SIZE_T`(%sp)
175 $PUSH %r10,`-$FRAME+7*$SIZE_T`(%sp)
176 $PUSH %r11,`-$FRAME+8*$SIZE_T`(%sp)
177 $PUSH %r12,`-$FRAME+9*$SIZE_T`(%sp)
178 $PUSH %r13,`-$FRAME+10*$SIZE_T`(%sp)
179 $PUSH %r14,`-$FRAME+11*$SIZE_T`(%sp)
180 $PUSH %r15,`-$FRAME+12*$SIZE_T`(%sp)
181 $PUSH %r16,`-$FRAME+13*$SIZE_T`(%sp)
189 extru $inp,31,2,$t0 ; t0=inp&3;
190 sh3addl $t0,%r0,$t0 ; t0*=8;
191 subi 32,$t0,$t0 ; t0=32-t0;
192 mtctl $t0,%cr11 ; %sar=t0;
196 andcm $inp,$t0,$t0 ; 64-bit neutral
198 for ($i=0;$i<15;$i++) { # load input block
199 $code.="\tldw `4*$i`($t0),@X[$i]\n"; }
201 cmpb,*= $inp,$t0,L\$aligned
205 for ($i=0;$i<16;$i++) { # align input
206 $code.="\tvshd @X[$i],@X[$i+1],@X[$i]\n"; }
209 ldil L'0x5a827000,$K ; K_00_19
212 for ($i=0;$i<20;$i++) { &BODY_00_19($i,@V); unshift(@V,pop(@V)); }
214 ldil L'0x6ed9e000,$K ; K_20_39
218 for (;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
220 ldil L'0x8f1bb000,$K ; K_40_59
224 for (;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
226 ldil L'0xca62c000,$K ; K_60_79
229 for (;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
242 addib,*<> -1,$num,L\$oop
245 $POP `-$FRAME-$SAVED_RP`(%sp),%r2 ; standard epilogue
246 $POP `-$FRAME+1*$SIZE_T`(%sp),%r4
247 $POP `-$FRAME+2*$SIZE_T`(%sp),%r5
248 $POP `-$FRAME+3*$SIZE_T`(%sp),%r6
249 $POP `-$FRAME+4*$SIZE_T`(%sp),%r7
250 $POP `-$FRAME+5*$SIZE_T`(%sp),%r8
251 $POP `-$FRAME+6*$SIZE_T`(%sp),%r9
252 $POP `-$FRAME+7*$SIZE_T`(%sp),%r10
253 $POP `-$FRAME+8*$SIZE_T`(%sp),%r11
254 $POP `-$FRAME+9*$SIZE_T`(%sp),%r12
255 $POP `-$FRAME+10*$SIZE_T`(%sp),%r13
256 $POP `-$FRAME+11*$SIZE_T`(%sp),%r14
257 $POP `-$FRAME+12*$SIZE_T`(%sp),%r15
258 $POP `-$FRAME+13*$SIZE_T`(%sp),%r16
261 $POPMB -$FRAME(%sp),%r3
263 .STRINGZ "SHA1 block transform for PA-RISC, CRYPTOGAMS by <appro\@openssl.org>"
266 if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
267 =~ /GNU assembler/) {
271 foreach(split("\n",$code)) {
272 s/\`([^\`]*)\`/eval $1/ge;
274 s/(\.LEVEL\s+2\.0)W/$1w/ if ($gnuas && $SIZE_T==8);
275 s/\.SPACE\s+\$TEXT\$/.text/ if ($gnuas && $SIZE_T==8);
276 s/\.SUBSPA.*// if ($gnuas && $SIZE_T==8);
277 s/,\*/,/ if ($SIZE_T==4);
278 s/\bbv\b/bve/ if ($SIZE_T==8);
282 close STDOUT or die "error closing STDOUT";