11f13597dSJung-uk Kim#! /usr/bin/env perl 2*17f01e99SJung-uk Kim# Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved. 3e71b7053SJung-uk Kim# 4e71b7053SJung-uk Kim# Licensed under the OpenSSL license (the "License"). You may not use 5e71b7053SJung-uk Kim# this file except in compliance with the License. You can obtain a copy 6e71b7053SJung-uk Kim# in the file LICENSE in the source distribution or at 7e71b7053SJung-uk Kim# https://www.openssl.org/source/license.html 8e71b7053SJung-uk Kim 91f13597dSJung-uk Kim 101f13597dSJung-uk Kim# ==================================================================== 11e71b7053SJung-uk Kim# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL 121f13597dSJung-uk Kim# project. The module is, however, dual licensed under OpenSSL and 131f13597dSJung-uk Kim# CRYPTOGAMS licenses depending on where you obtain it. For further 141f13597dSJung-uk Kim# details see http://www.openssl.org/~appro/cryptogams/. 151f13597dSJung-uk Kim# ==================================================================== 161f13597dSJung-uk Kim 171f13597dSJung-uk Kim# SHA1 block procedure for PA-RISC. 181f13597dSJung-uk Kim 191f13597dSJung-uk Kim# June 2009. 201f13597dSJung-uk Kim# 211f13597dSJung-uk Kim# On PA-7100LC performance is >30% better than gcc 3.2 generated code 221f13597dSJung-uk Kim# for aligned input and >50% better for unaligned. Compared to vendor 231f13597dSJung-uk Kim# compiler on PA-8600 it's almost 60% faster in 64-bit build and just 241f13597dSJung-uk Kim# few percent faster in 32-bit one (this for aligned input, data for 251f13597dSJung-uk Kim# unaligned input is not available). 261f13597dSJung-uk Kim# 271f13597dSJung-uk Kim# Special thanks to polarhome.com for providing HP-UX account. 281f13597dSJung-uk Kim 291f13597dSJung-uk Kim$flavour = shift; 301f13597dSJung-uk Kim$output = shift; 311f13597dSJung-uk Kimopen STDOUT,">$output"; 321f13597dSJung-uk Kim 331f13597dSJung-uk Kimif ($flavour =~ /64/) { 341f13597dSJung-uk Kim $LEVEL ="2.0W"; 351f13597dSJung-uk Kim $SIZE_T =8; 361f13597dSJung-uk Kim $FRAME_MARKER =80; 371f13597dSJung-uk Kim $SAVED_RP =16; 381f13597dSJung-uk Kim $PUSH ="std"; 391f13597dSJung-uk Kim $PUSHMA ="std,ma"; 401f13597dSJung-uk Kim $POP ="ldd"; 411f13597dSJung-uk Kim $POPMB ="ldd,mb"; 421f13597dSJung-uk Kim} else { 431f13597dSJung-uk Kim $LEVEL ="1.0"; 441f13597dSJung-uk Kim $SIZE_T =4; 451f13597dSJung-uk Kim $FRAME_MARKER =48; 461f13597dSJung-uk Kim $SAVED_RP =20; 471f13597dSJung-uk Kim $PUSH ="stw"; 481f13597dSJung-uk Kim $PUSHMA ="stwm"; 491f13597dSJung-uk Kim $POP ="ldw"; 501f13597dSJung-uk Kim $POPMB ="ldwm"; 511f13597dSJung-uk Kim} 521f13597dSJung-uk Kim 531f13597dSJung-uk Kim$FRAME=14*$SIZE_T+$FRAME_MARKER;# 14 saved regs + frame marker 541f13597dSJung-uk Kim # [+ argument transfer] 551f13597dSJung-uk Kim$ctx="%r26"; # arg0 561f13597dSJung-uk Kim$inp="%r25"; # arg1 571f13597dSJung-uk Kim$num="%r24"; # arg2 581f13597dSJung-uk Kim 591f13597dSJung-uk Kim$t0="%r28"; 601f13597dSJung-uk Kim$t1="%r29"; 611f13597dSJung-uk Kim$K="%r31"; 621f13597dSJung-uk Kim 631f13597dSJung-uk Kim@X=("%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", "%r8", 641f13597dSJung-uk Kim "%r9", "%r10","%r11","%r12","%r13","%r14","%r15","%r16",$t0); 651f13597dSJung-uk Kim 661f13597dSJung-uk Kim@V=($A,$B,$C,$D,$E)=("%r19","%r20","%r21","%r22","%r23"); 671f13597dSJung-uk Kim 681f13597dSJung-uk Kimsub BODY_00_19 { 691f13597dSJung-uk Kimmy ($i,$a,$b,$c,$d,$e)=@_; 701f13597dSJung-uk Kimmy $j=$i+1; 711f13597dSJung-uk Kim$code.=<<___ if ($i<15); 721f13597dSJung-uk Kim addl $K,$e,$e ; $i 731f13597dSJung-uk Kim shd $a,$a,27,$t1 741f13597dSJung-uk Kim addl @X[$i],$e,$e 751f13597dSJung-uk Kim and $c,$b,$t0 761f13597dSJung-uk Kim addl $t1,$e,$e 771f13597dSJung-uk Kim andcm $d,$b,$t1 781f13597dSJung-uk Kim shd $b,$b,2,$b 791f13597dSJung-uk Kim or $t1,$t0,$t0 801f13597dSJung-uk Kim addl $t0,$e,$e 811f13597dSJung-uk Kim___ 821f13597dSJung-uk Kim$code.=<<___ if ($i>=15); # with forward Xupdate 831f13597dSJung-uk Kim addl $K,$e,$e ; $i 841f13597dSJung-uk Kim shd $a,$a,27,$t1 851f13597dSJung-uk Kim xor @X[($j+2)%16],@X[$j%16],@X[$j%16] 861f13597dSJung-uk Kim addl @X[$i%16],$e,$e 871f13597dSJung-uk Kim and $c,$b,$t0 881f13597dSJung-uk Kim xor @X[($j+8)%16],@X[$j%16],@X[$j%16] 891f13597dSJung-uk Kim addl $t1,$e,$e 901f13597dSJung-uk Kim andcm $d,$b,$t1 911f13597dSJung-uk Kim shd $b,$b,2,$b 921f13597dSJung-uk Kim or $t1,$t0,$t0 931f13597dSJung-uk Kim xor @X[($j+13)%16],@X[$j%16],@X[$j%16] 941f13597dSJung-uk Kim add $t0,$e,$e 951f13597dSJung-uk Kim shd @X[$j%16],@X[$j%16],31,@X[$j%16] 961f13597dSJung-uk Kim___ 971f13597dSJung-uk Kim} 981f13597dSJung-uk Kim 991f13597dSJung-uk Kimsub BODY_20_39 { 1001f13597dSJung-uk Kimmy ($i,$a,$b,$c,$d,$e)=@_; 1011f13597dSJung-uk Kimmy $j=$i+1; 1021f13597dSJung-uk Kim$code.=<<___ if ($i<79); 1031f13597dSJung-uk Kim xor @X[($j+2)%16],@X[$j%16],@X[$j%16] ; $i 1041f13597dSJung-uk Kim addl $K,$e,$e 1051f13597dSJung-uk Kim shd $a,$a,27,$t1 1061f13597dSJung-uk Kim xor @X[($j+8)%16],@X[$j%16],@X[$j%16] 1071f13597dSJung-uk Kim addl @X[$i%16],$e,$e 1081f13597dSJung-uk Kim xor $b,$c,$t0 1091f13597dSJung-uk Kim xor @X[($j+13)%16],@X[$j%16],@X[$j%16] 1101f13597dSJung-uk Kim addl $t1,$e,$e 1111f13597dSJung-uk Kim shd $b,$b,2,$b 1121f13597dSJung-uk Kim xor $d,$t0,$t0 1131f13597dSJung-uk Kim shd @X[$j%16],@X[$j%16],31,@X[$j%16] 1141f13597dSJung-uk Kim addl $t0,$e,$e 1151f13597dSJung-uk Kim___ 1161f13597dSJung-uk Kim$code.=<<___ if ($i==79); # with context load 1171f13597dSJung-uk Kim ldw 0($ctx),@X[0] ; $i 1181f13597dSJung-uk Kim addl $K,$e,$e 1191f13597dSJung-uk Kim shd $a,$a,27,$t1 1201f13597dSJung-uk Kim ldw 4($ctx),@X[1] 1211f13597dSJung-uk Kim addl @X[$i%16],$e,$e 1221f13597dSJung-uk Kim xor $b,$c,$t0 1231f13597dSJung-uk Kim ldw 8($ctx),@X[2] 1241f13597dSJung-uk Kim addl $t1,$e,$e 1251f13597dSJung-uk Kim shd $b,$b,2,$b 1261f13597dSJung-uk Kim xor $d,$t0,$t0 1271f13597dSJung-uk Kim ldw 12($ctx),@X[3] 1281f13597dSJung-uk Kim addl $t0,$e,$e 1291f13597dSJung-uk Kim ldw 16($ctx),@X[4] 1301f13597dSJung-uk Kim___ 1311f13597dSJung-uk Kim} 1321f13597dSJung-uk Kim 1331f13597dSJung-uk Kimsub BODY_40_59 { 1341f13597dSJung-uk Kimmy ($i,$a,$b,$c,$d,$e)=@_; 1351f13597dSJung-uk Kimmy $j=$i+1; 1361f13597dSJung-uk Kim$code.=<<___; 1371f13597dSJung-uk Kim shd $a,$a,27,$t1 ; $i 1381f13597dSJung-uk Kim addl $K,$e,$e 1391f13597dSJung-uk Kim xor @X[($j+2)%16],@X[$j%16],@X[$j%16] 1401f13597dSJung-uk Kim xor $d,$c,$t0 1411f13597dSJung-uk Kim addl @X[$i%16],$e,$e 1421f13597dSJung-uk Kim xor @X[($j+8)%16],@X[$j%16],@X[$j%16] 1431f13597dSJung-uk Kim and $b,$t0,$t0 1441f13597dSJung-uk Kim addl $t1,$e,$e 1451f13597dSJung-uk Kim shd $b,$b,2,$b 1461f13597dSJung-uk Kim xor @X[($j+13)%16],@X[$j%16],@X[$j%16] 1471f13597dSJung-uk Kim addl $t0,$e,$e 1481f13597dSJung-uk Kim and $d,$c,$t1 1491f13597dSJung-uk Kim shd @X[$j%16],@X[$j%16],31,@X[$j%16] 1501f13597dSJung-uk Kim addl $t1,$e,$e 1511f13597dSJung-uk Kim___ 1521f13597dSJung-uk Kim} 1531f13597dSJung-uk Kim 1541f13597dSJung-uk Kim$code=<<___; 1551f13597dSJung-uk Kim .LEVEL $LEVEL 1561f13597dSJung-uk Kim .SPACE \$TEXT\$ 1571f13597dSJung-uk Kim .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY 1581f13597dSJung-uk Kim 1591f13597dSJung-uk Kim .EXPORT sha1_block_data_order,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR 1601f13597dSJung-uk Kimsha1_block_data_order 1611f13597dSJung-uk Kim .PROC 1621f13597dSJung-uk Kim .CALLINFO FRAME=`$FRAME-14*$SIZE_T`,NO_CALLS,SAVE_RP,ENTRY_GR=16 1631f13597dSJung-uk Kim .ENTRY 1641f13597dSJung-uk Kim $PUSH %r2,-$SAVED_RP(%sp) ; standard prologue 1651f13597dSJung-uk Kim $PUSHMA %r3,$FRAME(%sp) 1661f13597dSJung-uk Kim $PUSH %r4,`-$FRAME+1*$SIZE_T`(%sp) 1671f13597dSJung-uk Kim $PUSH %r5,`-$FRAME+2*$SIZE_T`(%sp) 1681f13597dSJung-uk Kim $PUSH %r6,`-$FRAME+3*$SIZE_T`(%sp) 1691f13597dSJung-uk Kim $PUSH %r7,`-$FRAME+4*$SIZE_T`(%sp) 1701f13597dSJung-uk Kim $PUSH %r8,`-$FRAME+5*$SIZE_T`(%sp) 1711f13597dSJung-uk Kim $PUSH %r9,`-$FRAME+6*$SIZE_T`(%sp) 1721f13597dSJung-uk Kim $PUSH %r10,`-$FRAME+7*$SIZE_T`(%sp) 1731f13597dSJung-uk Kim $PUSH %r11,`-$FRAME+8*$SIZE_T`(%sp) 1741f13597dSJung-uk Kim $PUSH %r12,`-$FRAME+9*$SIZE_T`(%sp) 1751f13597dSJung-uk Kim $PUSH %r13,`-$FRAME+10*$SIZE_T`(%sp) 1761f13597dSJung-uk Kim $PUSH %r14,`-$FRAME+11*$SIZE_T`(%sp) 1771f13597dSJung-uk Kim $PUSH %r15,`-$FRAME+12*$SIZE_T`(%sp) 1781f13597dSJung-uk Kim $PUSH %r16,`-$FRAME+13*$SIZE_T`(%sp) 1791f13597dSJung-uk Kim 1801f13597dSJung-uk Kim ldw 0($ctx),$A 1811f13597dSJung-uk Kim ldw 4($ctx),$B 1821f13597dSJung-uk Kim ldw 8($ctx),$C 1831f13597dSJung-uk Kim ldw 12($ctx),$D 1841f13597dSJung-uk Kim ldw 16($ctx),$E 1851f13597dSJung-uk Kim 1861f13597dSJung-uk Kim extru $inp,31,2,$t0 ; t0=inp&3; 1871f13597dSJung-uk Kim sh3addl $t0,%r0,$t0 ; t0*=8; 1881f13597dSJung-uk Kim subi 32,$t0,$t0 ; t0=32-t0; 1891f13597dSJung-uk Kim mtctl $t0,%cr11 ; %sar=t0; 1901f13597dSJung-uk Kim 1911f13597dSJung-uk KimL\$oop 1921f13597dSJung-uk Kim ldi 3,$t0 1931f13597dSJung-uk Kim andcm $inp,$t0,$t0 ; 64-bit neutral 1941f13597dSJung-uk Kim___ 1951f13597dSJung-uk Kim for ($i=0;$i<15;$i++) { # load input block 1961f13597dSJung-uk Kim $code.="\tldw `4*$i`($t0),@X[$i]\n"; } 1971f13597dSJung-uk Kim$code.=<<___; 1981f13597dSJung-uk Kim cmpb,*= $inp,$t0,L\$aligned 1991f13597dSJung-uk Kim ldw 60($t0),@X[15] 2001f13597dSJung-uk Kim ldw 64($t0),@X[16] 2011f13597dSJung-uk Kim___ 2021f13597dSJung-uk Kim for ($i=0;$i<16;$i++) { # align input 2031f13597dSJung-uk Kim $code.="\tvshd @X[$i],@X[$i+1],@X[$i]\n"; } 2041f13597dSJung-uk Kim$code.=<<___; 2051f13597dSJung-uk KimL\$aligned 2061f13597dSJung-uk Kim ldil L'0x5a827000,$K ; K_00_19 2071f13597dSJung-uk Kim ldo 0x999($K),$K 2081f13597dSJung-uk Kim___ 2091f13597dSJung-uk Kimfor ($i=0;$i<20;$i++) { &BODY_00_19($i,@V); unshift(@V,pop(@V)); } 2101f13597dSJung-uk Kim$code.=<<___; 2111f13597dSJung-uk Kim ldil L'0x6ed9e000,$K ; K_20_39 2121f13597dSJung-uk Kim ldo 0xba1($K),$K 2131f13597dSJung-uk Kim___ 2141f13597dSJung-uk Kim 2151f13597dSJung-uk Kimfor (;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); } 2161f13597dSJung-uk Kim$code.=<<___; 2171f13597dSJung-uk Kim ldil L'0x8f1bb000,$K ; K_40_59 2181f13597dSJung-uk Kim ldo 0xcdc($K),$K 2191f13597dSJung-uk Kim___ 2201f13597dSJung-uk Kim 2211f13597dSJung-uk Kimfor (;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); } 2221f13597dSJung-uk Kim$code.=<<___; 2231f13597dSJung-uk Kim ldil L'0xca62c000,$K ; K_60_79 2241f13597dSJung-uk Kim ldo 0x1d6($K),$K 2251f13597dSJung-uk Kim___ 2261f13597dSJung-uk Kimfor (;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); } 2271f13597dSJung-uk Kim 2281f13597dSJung-uk Kim$code.=<<___; 2291f13597dSJung-uk Kim addl @X[0],$A,$A 2301f13597dSJung-uk Kim addl @X[1],$B,$B 2311f13597dSJung-uk Kim addl @X[2],$C,$C 2321f13597dSJung-uk Kim addl @X[3],$D,$D 2331f13597dSJung-uk Kim addl @X[4],$E,$E 2341f13597dSJung-uk Kim stw $A,0($ctx) 2351f13597dSJung-uk Kim stw $B,4($ctx) 2361f13597dSJung-uk Kim stw $C,8($ctx) 2371f13597dSJung-uk Kim stw $D,12($ctx) 2381f13597dSJung-uk Kim stw $E,16($ctx) 2391f13597dSJung-uk Kim addib,*<> -1,$num,L\$oop 2401f13597dSJung-uk Kim ldo 64($inp),$inp 2411f13597dSJung-uk Kim 2421f13597dSJung-uk Kim $POP `-$FRAME-$SAVED_RP`(%sp),%r2 ; standard epilogue 2431f13597dSJung-uk Kim $POP `-$FRAME+1*$SIZE_T`(%sp),%r4 2441f13597dSJung-uk Kim $POP `-$FRAME+2*$SIZE_T`(%sp),%r5 2451f13597dSJung-uk Kim $POP `-$FRAME+3*$SIZE_T`(%sp),%r6 2461f13597dSJung-uk Kim $POP `-$FRAME+4*$SIZE_T`(%sp),%r7 2471f13597dSJung-uk Kim $POP `-$FRAME+5*$SIZE_T`(%sp),%r8 2481f13597dSJung-uk Kim $POP `-$FRAME+6*$SIZE_T`(%sp),%r9 2491f13597dSJung-uk Kim $POP `-$FRAME+7*$SIZE_T`(%sp),%r10 2501f13597dSJung-uk Kim $POP `-$FRAME+8*$SIZE_T`(%sp),%r11 2511f13597dSJung-uk Kim $POP `-$FRAME+9*$SIZE_T`(%sp),%r12 2521f13597dSJung-uk Kim $POP `-$FRAME+10*$SIZE_T`(%sp),%r13 2531f13597dSJung-uk Kim $POP `-$FRAME+11*$SIZE_T`(%sp),%r14 2541f13597dSJung-uk Kim $POP `-$FRAME+12*$SIZE_T`(%sp),%r15 2551f13597dSJung-uk Kim $POP `-$FRAME+13*$SIZE_T`(%sp),%r16 2561f13597dSJung-uk Kim bv (%r2) 2571f13597dSJung-uk Kim .EXIT 2581f13597dSJung-uk Kim $POPMB -$FRAME(%sp),%r3 2591f13597dSJung-uk Kim .PROCEND 2601f13597dSJung-uk Kim .STRINGZ "SHA1 block transform for PA-RISC, CRYPTOGAMS by <appro\@openssl.org>" 2611f13597dSJung-uk Kim___ 2621f13597dSJung-uk Kim 263e71b7053SJung-uk Kimif (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1` 264e71b7053SJung-uk Kim =~ /GNU assembler/) { 265e71b7053SJung-uk Kim $gnuas = 1; 266e71b7053SJung-uk Kim} 267e71b7053SJung-uk Kim 268e71b7053SJung-uk Kimforeach(split("\n",$code)) { 269e71b7053SJung-uk Kim s/\`([^\`]*)\`/eval $1/ge; 270e71b7053SJung-uk Kim 271e71b7053SJung-uk Kim s/(\.LEVEL\s+2\.0)W/$1w/ if ($gnuas && $SIZE_T==8); 272e71b7053SJung-uk Kim s/\.SPACE\s+\$TEXT\$/.text/ if ($gnuas && $SIZE_T==8); 273e71b7053SJung-uk Kim s/\.SUBSPA.*// if ($gnuas && $SIZE_T==8); 274e71b7053SJung-uk Kim s/,\*/,/ if ($SIZE_T==4); 275e71b7053SJung-uk Kim s/\bbv\b/bve/ if ($SIZE_T==8); 276e71b7053SJung-uk Kim 277e71b7053SJung-uk Kim print $_,"\n"; 278e71b7053SJung-uk Kim} 279*17f01e99SJung-uk Kimclose STDOUT or die "error closing STDOUT: $!"; 280