2 # Copyright 2009-2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (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.
31 open STDOUT,">$output";
33 if ($flavour =~ /64/) {
53 $FRAME=14*$SIZE_T+$FRAME_MARKER;# 14 saved regs + frame marker
54 # [+ argument transfer]
63 @X=("%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", "%r8",
64 "%r9", "%r10","%r11","%r12","%r13","%r14","%r15","%r16",$t0);
66 @V=($A,$B,$C,$D,$E)=("%r19","%r20","%r21","%r22","%r23");
69 my ($i,$a,$b,$c,$d,$e)=@_;
71 $code.=<<___ if ($i<15);
82 $code.=<<___ if ($i>=15); # with forward Xupdate
85 xor @X[($j+2)%16],@X[$j%16],@X[$j%16]
88 xor @X[($j+8)%16],@X[$j%16],@X[$j%16]
93 xor @X[($j+13)%16],@X[$j%16],@X[$j%16]
95 shd @X[$j%16],@X[$j%16],31,@X[$j%16]
100 my ($i,$a,$b,$c,$d,$e)=@_;
102 $code.=<<___ if ($i<79);
103 xor @X[($j+2)%16],@X[$j%16],@X[$j%16] ; $i
106 xor @X[($j+8)%16],@X[$j%16],@X[$j%16]
109 xor @X[($j+13)%16],@X[$j%16],@X[$j%16]
113 shd @X[$j%16],@X[$j%16],31,@X[$j%16]
116 $code.=<<___ if ($i==79); # with context load
117 ldw 0($ctx),@X[0] ; $i
134 my ($i,$a,$b,$c,$d,$e)=@_;
137 shd $a,$a,27,$t1 ; $i
139 xor @X[($j+2)%16],@X[$j%16],@X[$j%16]
142 xor @X[($j+8)%16],@X[$j%16],@X[$j%16]
146 xor @X[($j+13)%16],@X[$j%16],@X[$j%16]
149 shd @X[$j%16],@X[$j%16],31,@X[$j%16]
157 .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY
159 .EXPORT sha1_block_data_order,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR
160 sha1_block_data_order
162 .CALLINFO FRAME=`$FRAME-14*$SIZE_T`,NO_CALLS,SAVE_RP,ENTRY_GR=16
164 $PUSH %r2,-$SAVED_RP(%sp) ; standard prologue
165 $PUSHMA %r3,$FRAME(%sp)
166 $PUSH %r4,`-$FRAME+1*$SIZE_T`(%sp)
167 $PUSH %r5,`-$FRAME+2*$SIZE_T`(%sp)
168 $PUSH %r6,`-$FRAME+3*$SIZE_T`(%sp)
169 $PUSH %r7,`-$FRAME+4*$SIZE_T`(%sp)
170 $PUSH %r8,`-$FRAME+5*$SIZE_T`(%sp)
171 $PUSH %r9,`-$FRAME+6*$SIZE_T`(%sp)
172 $PUSH %r10,`-$FRAME+7*$SIZE_T`(%sp)
173 $PUSH %r11,`-$FRAME+8*$SIZE_T`(%sp)
174 $PUSH %r12,`-$FRAME+9*$SIZE_T`(%sp)
175 $PUSH %r13,`-$FRAME+10*$SIZE_T`(%sp)
176 $PUSH %r14,`-$FRAME+11*$SIZE_T`(%sp)
177 $PUSH %r15,`-$FRAME+12*$SIZE_T`(%sp)
178 $PUSH %r16,`-$FRAME+13*$SIZE_T`(%sp)
186 extru $inp,31,2,$t0 ; t0=inp&3;
187 sh3addl $t0,%r0,$t0 ; t0*=8;
188 subi 32,$t0,$t0 ; t0=32-t0;
189 mtctl $t0,%cr11 ; %sar=t0;
193 andcm $inp,$t0,$t0 ; 64-bit neutral
195 for ($i=0;$i<15;$i++) { # load input block
196 $code.="\tldw `4*$i`($t0),@X[$i]\n"; }
198 cmpb,*= $inp,$t0,L\$aligned
202 for ($i=0;$i<16;$i++) { # align input
203 $code.="\tvshd @X[$i],@X[$i+1],@X[$i]\n"; }
206 ldil L'0x5a827000,$K ; K_00_19
209 for ($i=0;$i<20;$i++) { &BODY_00_19($i,@V); unshift(@V,pop(@V)); }
211 ldil L'0x6ed9e000,$K ; K_20_39
215 for (;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
217 ldil L'0x8f1bb000,$K ; K_40_59
221 for (;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
223 ldil L'0xca62c000,$K ; K_60_79
226 for (;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
239 addib,*<> -1,$num,L\$oop
242 $POP `-$FRAME-$SAVED_RP`(%sp),%r2 ; standard epilogue
243 $POP `-$FRAME+1*$SIZE_T`(%sp),%r4
244 $POP `-$FRAME+2*$SIZE_T`(%sp),%r5
245 $POP `-$FRAME+3*$SIZE_T`(%sp),%r6
246 $POP `-$FRAME+4*$SIZE_T`(%sp),%r7
247 $POP `-$FRAME+5*$SIZE_T`(%sp),%r8
248 $POP `-$FRAME+6*$SIZE_T`(%sp),%r9
249 $POP `-$FRAME+7*$SIZE_T`(%sp),%r10
250 $POP `-$FRAME+8*$SIZE_T`(%sp),%r11
251 $POP `-$FRAME+9*$SIZE_T`(%sp),%r12
252 $POP `-$FRAME+10*$SIZE_T`(%sp),%r13
253 $POP `-$FRAME+11*$SIZE_T`(%sp),%r14
254 $POP `-$FRAME+12*$SIZE_T`(%sp),%r15
255 $POP `-$FRAME+13*$SIZE_T`(%sp),%r16
258 $POPMB -$FRAME(%sp),%r3
260 .STRINGZ "SHA1 block transform for PA-RISC, CRYPTOGAMS by <appro\@openssl.org>"
263 if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
264 =~ /GNU assembler/) {
268 foreach(split("\n",$code)) {
269 s/\`([^\`]*)\`/eval $1/ge;
271 s/(\.LEVEL\s+2\.0)W/$1w/ if ($gnuas && $SIZE_T==8);
272 s/\.SPACE\s+\$TEXT\$/.text/ if ($gnuas && $SIZE_T==8);
273 s/\.SUBSPA.*// if ($gnuas && $SIZE_T==8);
274 s/,\*/,/ if ($SIZE_T==4);
275 s/\bbv\b/bve/ if ($SIZE_T==8);