1b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#!/usr/bin/env perl 2b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 3b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ==================================================================== 4b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL 5b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# project. The module is, however, dual licensed under OpenSSL and 6b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# CRYPTOGAMS licenses depending on where you obtain it. For further 7b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# details see http://www.openssl.org/~appro/cryptogams/. 8b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ==================================================================== 9b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 10b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# SHA2 block procedures for MIPS. 11b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 12b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# October 2010. 13b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# 14b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# SHA256 performance improvement on MIPS R5000 CPU is ~27% over gcc- 15b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# generated code in o32 build and ~55% in n32/64 build. SHA512 [which 16b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# for now can only be compiled for MIPS64 ISA] improvement is modest 17b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ~17%, but it comes for free, because it's same instruction sequence. 18b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# Improvement coefficients are for aligned input. 19b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 20b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic###################################################################### 21b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# There is a number of MIPS ABI in use, O32 and N32/64 are most 22b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# widely used. Then there is a new contender: NUBI. It appears that if 23b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# one picks the latter, it's possible to arrange code in ABI neutral 24b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# manner. Therefore let's stick to NUBI register layout: 25b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# 26b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic($zero,$at,$t0,$t1,$t2)=map("\$$_",(0..2,24,25)); 27b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7)=map("\$$_",(4..11)); 28b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9,$s10,$s11)=map("\$$_",(12..23)); 29b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic($gp,$tp,$sp,$fp,$ra)=map("\$$_",(3,28..31)); 30b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# 31b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# The return value is placed in $a0. Following coding rules facilitate 32b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# interoperability: 33b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# 34b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# - never ever touch $tp, "thread pointer", former $gp [o32 can be 35b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# excluded from the rule, because it's specified volatile]; 36b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# - copy return value to $t0, former $v0 [or to $a0 if you're adapting 37b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# old code]; 38b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# - on O32 populate $a4-$a7 with 'lw $aN,4*N($sp)' if necessary; 39b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# 40b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# For reference here is register layout for N32/64 MIPS ABIs: 41b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# 42b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($zero,$at,$v0,$v1)=map("\$$_",(0..3)); 43b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7)=map("\$$_",(4..11)); 44b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($t0,$t1,$t2,$t3,$t8,$t9)=map("\$$_",(12..15,24,25)); 45b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7)=map("\$$_",(16..23)); 46b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($gp,$sp,$fp,$ra)=map("\$$_",(28..31)); 47b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# 48b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$flavour = shift; # supported flavours are o32,n32,64,nubi32,nubi64 49b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 50b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicif ($flavour =~ /64|n32/i) { 51b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_ADD="dadd"; # incidentally works even on n32 52b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_SUB="dsub"; # incidentally works even on n32 53b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S="sd"; 54b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L="ld"; 55b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_SLL="dsll"; # incidentally works even on n32 56b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SZREG=8; 57b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic} else { 58b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_ADD="add"; 59b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_SUB="sub"; 60b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S="sw"; 61b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L="lw"; 62b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_SLL="sll"; 63b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SZREG=4; 64b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic} 65b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$pf = ($flavour =~ /nubi/i) ? $t0 : $t2; 66b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# 67b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# <appro@openssl.org> 68b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# 69b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic###################################################################### 70b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 71b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$big_endian=(`echo MIPSEL | $ENV{CC} -E -P -`=~/MIPSEL/)?1:0; 72b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 73b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicfor (@ARGV) { $output=$_ if (/^\w[\w\-]*\.\w+$/); } 74b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicopen STDOUT,">$output"; 75b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 76b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicif (!defined($big_endian)) { $big_endian=(unpack('L',pack('N',1))==1); } 77b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 78b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicif ($output =~ /512/) { 79b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $label="512"; 80b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SZ=8; 81b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD="ld"; # load from memory 82b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST="sd"; # store to memory 83b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL="dsll"; # shift left logical 84b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL="dsrl"; # shift right logical 85b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU="daddu"; 86b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic @Sigma0=(28,34,39); 87b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic @Sigma1=(14,18,41); 88b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic @sigma0=( 7, 1, 8); # right shift first 89b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic @sigma1=( 6,19,61); # right shift first 90b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $lastK=0x817; 91b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $rounds=80; 92b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic} else { 93b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $label="256"; 94b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SZ=4; 95b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD="lw"; # load from memory 96b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST="sw"; # store to memory 97b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL="sll"; # shift left logical 98b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL="srl"; # shift right logical 99b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU="addu"; 100b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic @Sigma0=( 2,13,22); 101b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic @Sigma1=( 6,11,25); 102b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic @sigma0=( 3, 7,18); # right shift first 103b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic @sigma1=(10,17,19); # right shift first 104b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $lastK=0x8f2; 105b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $rounds=64; 106b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic} 107b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 108b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$MSB = $big_endian ? 0 : ($SZ-1); 109b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$LSB = ($SZ-1)&~$MSB; 110b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 111b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic@V=($A,$B,$C,$D,$E,$F,$G,$H)=map("\$$_",(1,2,3,7,24,25,30,31)); 112b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic@X=map("\$$_",(8..23)); 113b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 114b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$ctx=$a0; 115b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$inp=$a1; 116b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$len=$a2; $Ktbl=$len; 117b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 118b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicsub BODY_00_15 { 119b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($i,$a,$b,$c,$d,$e,$f,$g,$h)=@_; 120b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($T1,$tmp0,$tmp1,$tmp2)=(@X[4],@X[5],@X[6],@X[7]); 121b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 122b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($i<15); 123b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic ${LD}l @X[1],`($i+1)*$SZ+$MSB`($inp) 124b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic ${LD}r @X[1],`($i+1)*$SZ+$LSB`($inp) 125b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 126b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if (!$big_endian && $i<16 && $SZ==4); 127b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic srl $tmp0,@X[0],24 # byte swap($i) 128b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic srl $tmp1,@X[0],8 129b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic andi $tmp2,@X[0],0xFF00 130b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic sll @X[0],@X[0],24 131b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic andi $tmp1,0xFF00 132b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic sll $tmp2,$tmp2,8 133b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or @X[0],$tmp0 134b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or $tmp1,$tmp2 135b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or @X[0],$tmp1 136b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 137b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if (!$big_endian && $i<16 && $SZ==8); 138b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic ori $tmp0,$zero,0xFF 139b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic dsll $tmp2,$tmp0,32 140b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or $tmp0,$tmp2 # 0x000000FF000000FF 141b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic and $tmp1,@X[0],$tmp0 # byte swap($i) 142b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic dsrl $tmp2,@X[0],24 143b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic dsll $tmp1,24 144b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic and $tmp2,$tmp0 145b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic dsll $tmp0,8 # 0x0000FF000000FF00 146b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or $tmp1,$tmp2 147b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic and $tmp2,@X[0],$tmp0 148b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic dsrl @X[0],8 149b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic dsll $tmp2,8 150b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic and @X[0],$tmp0 151b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or $tmp1,$tmp2 152b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or @X[0],$tmp1 153b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic dsrl $tmp1,@X[0],32 154b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic dsll @X[0],32 155b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or @X[0],$tmp1 156b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 157b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 158b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $T1,$X[0],$h # $i 159b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $h,$e,@Sigma1[0] 160b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp2,$f,$g 161b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,$e,`$SZ*8-@Sigma1[2]` 162b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic and $tmp2,$e 163b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp0,$e,@Sigma1[1] 164b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $h,$tmp1 165b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,$e,`$SZ*8-@Sigma1[1]` 166b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $h,$tmp0 167b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp0,$e,@Sigma1[2] 168b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $h,$tmp1 169b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,$e,`$SZ*8-@Sigma1[0]` 170b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $h,$tmp0 171b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp2,$g # Ch(e,f,g) 172b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp0,$tmp1,$h # Sigma1(e) 173b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 174b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $h,$a,@Sigma0[0] 175b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $T1,$tmp2 176b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD $tmp2,`$i*$SZ`($Ktbl) # K[$i] 177b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,$a,`$SZ*8-@Sigma0[2]` 178b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $T1,$tmp0 179b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp0,$a,@Sigma0[1] 180b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $h,$tmp1 181b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,$a,`$SZ*8-@Sigma0[1]` 182b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $h,$tmp0 183b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp0,$a,@Sigma0[2] 184b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $h,$tmp1 185b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,$a,`$SZ*8-@Sigma0[0]` 186b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $h,$tmp0 187b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST @X[0],`($i%16)*$SZ`($sp) # offload to ring buffer 188b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $h,$tmp1 # Sigma0(a) 189b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 190b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or $tmp0,$a,$b 191b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic and $tmp1,$a,$b 192b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic and $tmp0,$c 193b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic or $tmp1,$tmp0 # Maj(a,b,c) 194b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $T1,$tmp2 # +=K[$i] 195b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $h,$tmp1 196b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 197b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $d,$T1 198b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $h,$T1 199b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 200b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($i>=13); 201b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD @X[3],`(($i+3)%16)*$SZ`($sp) # prefetch from ring buffer 202b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 203b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic} 204b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 205b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicsub BODY_16_XX { 206b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy $i=@_[0]; 207b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($tmp0,$tmp1,$tmp2,$tmp3)=(@X[4],@X[5],@X[6],@X[7]); 208b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 209b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 210b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp2,@X[1],@sigma0[0] # Xupdate($i) 211b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU @X[0],@X[9] # +=X[i+9] 212b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,@X[1],`$SZ*8-@sigma0[2]` 213b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp0,@X[1],@sigma0[1] 214b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp2,$tmp1 215b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,`@sigma0[2]-@sigma0[1]` 216b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp2,$tmp0 217b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp0,@X[1],@sigma0[2] 218b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp2,$tmp1 219b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 220b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp3,@X[14],@sigma1[0] 221b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp2,$tmp0 # sigma0(X[i+1]) 222b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,@X[14],`$SZ*8-@sigma1[2]` 223b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU @X[0],$tmp2 224b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp0,@X[14],@sigma1[1] 225b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp3,$tmp1 226b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SLL $tmp1,`@sigma1[2]-@sigma1[1]` 227b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp3,$tmp0 228b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $SRL $tmp0,@X[14],@sigma1[2] 229b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp3,$tmp1 230b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 231b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic xor $tmp3,$tmp0 # sigma1(X[i+14]) 232b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU @X[0],$tmp3 233b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 234b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic &BODY_00_15(@_); 235b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic} 236b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 237b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$FRAMESIZE=16*$SZ+16*$SZREG; 238b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$SAVED_REGS_MASK = ($flavour =~ /nubi/i) ? 0xc0fff008 : 0xc0ff0000; 239b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 240b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 241b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#ifdef OPENSSL_FIPSCANISTER 242b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# include <openssl/fipssyms.h> 243b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#endif 244b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 245b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.text 246b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.set noat 247b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#if !defined(__vxworks) || defined(__pic__) 248b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.option pic2 249b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#endif 250b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 251b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align 5 252b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.globl sha${label}_block_data_order 253b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.ent sha${label}_block_data_order 254b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicsha${label}_block_data_order: 255b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .frame $sp,$FRAMESIZE,$ra 256b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .mask $SAVED_REGS_MASK,-$SZREG 257b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .set noreorder 258b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 259b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /o32/i); # o32 PIC-ification 260b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .cpload $pf 261b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 262b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 263b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_SUB $sp,$FRAMESIZE 264b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $ra,$FRAMESIZE-1*$SZREG($sp) 265b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $fp,$FRAMESIZE-2*$SZREG($sp) 266b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s11,$FRAMESIZE-3*$SZREG($sp) 267b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s10,$FRAMESIZE-4*$SZREG($sp) 268b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s9,$FRAMESIZE-5*$SZREG($sp) 269b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s8,$FRAMESIZE-6*$SZREG($sp) 270b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s7,$FRAMESIZE-7*$SZREG($sp) 271b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s6,$FRAMESIZE-8*$SZREG($sp) 272b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s5,$FRAMESIZE-9*$SZREG($sp) 273b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s4,$FRAMESIZE-10*$SZREG($sp) 274b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 275b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i); # optimize non-nubi prologue 276b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s3,$FRAMESIZE-11*$SZREG($sp) 277b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s2,$FRAMESIZE-12*$SZREG($sp) 278b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s1,$FRAMESIZE-13*$SZREG($sp) 279b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $s0,$FRAMESIZE-14*$SZREG($sp) 280b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S $gp,$FRAMESIZE-15*$SZREG($sp) 281b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 282b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 283b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_SLL @X[15],$len,`log(16*$SZ)/log(2)` 284b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 285b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour !~ /o32/i); # non-o32 PIC-ification 286b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .cplocal $Ktbl 287b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .cpsetup $pf,$zero,sha${label}_block_data_order 288b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 289b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 290b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .set reorder 291b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic la $Ktbl,K${label} # PIC-ified 'load address' 292b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 293b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD $A,0*$SZ($ctx) # load context 294b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD $B,1*$SZ($ctx) 295b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD $C,2*$SZ($ctx) 296b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD $D,3*$SZ($ctx) 297b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD $E,4*$SZ($ctx) 298b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD $F,5*$SZ($ctx) 299b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD $G,6*$SZ($ctx) 300b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD $H,7*$SZ($ctx) 301b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 302b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_ADD @X[15],$inp # pointer to the end of input 303b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_S @X[15],16*$SZ($sp) 304b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic b .Loop 305b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 306b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align 5 307b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.Loop: 308b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic ${LD}l @X[0],$MSB($inp) 309b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic ${LD}r @X[0],$LSB($inp) 310b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 311b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicfor ($i=0;$i<16;$i++) 312b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic{ &BODY_00_15($i,@V); unshift(@V,pop(@V)); push(@X,shift(@X)); } 313b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 314b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic b .L16_xx 315b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align 4 316b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.L16_xx: 317b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 318b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicfor (;$i<32;$i++) 319b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic{ &BODY_16_XX($i,@V); unshift(@V,pop(@V)); push(@X,shift(@X)); } 320b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 321b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic and @X[6],0xfff 322b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic li @X[7],$lastK 323b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .set noreorder 324b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic bne @X[6],@X[7],.L16_xx 325b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_ADD $Ktbl,16*$SZ # Ktbl+=16 326b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 327b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L @X[15],16*$SZ($sp) # restore pointer to the end of input 328b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD @X[0],0*$SZ($ctx) 329b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD @X[1],1*$SZ($ctx) 330b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD @X[2],2*$SZ($ctx) 331b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_ADD $inp,16*$SZ 332b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD @X[3],3*$SZ($ctx) 333b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $A,@X[0] 334b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD @X[4],4*$SZ($ctx) 335b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $B,@X[1] 336b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD @X[5],5*$SZ($ctx) 337b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $C,@X[2] 338b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD @X[6],6*$SZ($ctx) 339b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $D,@X[3] 340b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $LD @X[7],7*$SZ($ctx) 341b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $E,@X[4] 342b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST $A,0*$SZ($ctx) 343b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $F,@X[5] 344b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST $B,1*$SZ($ctx) 345b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $G,@X[6] 346b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST $C,2*$SZ($ctx) 347b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ADDU $H,@X[7] 348b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST $D,3*$SZ($ctx) 349b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST $E,4*$SZ($ctx) 350b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST $F,5*$SZ($ctx) 351b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST $G,6*$SZ($ctx) 352b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $ST $H,7*$SZ($ctx) 353b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 354b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic bnel $inp,@X[15],.Loop 355b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_SUB $Ktbl,`($rounds-16)*$SZ` # rewind $Ktbl 356b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 357b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $ra,$FRAMESIZE-1*$SZREG($sp) 358b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $fp,$FRAMESIZE-2*$SZREG($sp) 359b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s11,$FRAMESIZE-3*$SZREG($sp) 360b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s10,$FRAMESIZE-4*$SZREG($sp) 361b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s9,$FRAMESIZE-5*$SZREG($sp) 362b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s8,$FRAMESIZE-6*$SZREG($sp) 363b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s7,$FRAMESIZE-7*$SZREG($sp) 364b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s6,$FRAMESIZE-8*$SZREG($sp) 365b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s5,$FRAMESIZE-9*$SZREG($sp) 366b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s4,$FRAMESIZE-10*$SZREG($sp) 367b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 368b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i); 369b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s3,$FRAMESIZE-11*$SZREG($sp) 370b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s2,$FRAMESIZE-12*$SZREG($sp) 371b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s1,$FRAMESIZE-13*$SZREG($sp) 372b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $s0,$FRAMESIZE-14*$SZREG($sp) 373b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $REG_L $gp,$FRAMESIZE-15*$SZREG($sp) 374b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 375b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 376b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic jr $ra 377b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic $PTR_ADD $sp,$FRAMESIZE 378b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.end sha${label}_block_data_order 379b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 380b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.rdata 381b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align 5 382b83a02d94f9ba66fc5da46c2e27572674ea17931Petar JovanovicK${label}: 383b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 384b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicif ($SZ==4) { 385b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 386b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5 387b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5 388b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3 389b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174 390b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc 391b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da 392b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7 393b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967 394b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13 395b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85 396b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3 397b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070 398b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5 399b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3 400b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208 401b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .word 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 402b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 403b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic} else { 404b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 405b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x428a2f98d728ae22, 0x7137449123ef65cd 406b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc 407b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x3956c25bf348b538, 0x59f111f1b605d019 408b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x923f82a4af194f9b, 0xab1c5ed5da6d8118 409b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xd807aa98a3030242, 0x12835b0145706fbe 410b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2 411b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x72be5d74f27b896f, 0x80deb1fe3b1696b1 412b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x9bdc06a725c71235, 0xc19bf174cf692694 413b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xe49b69c19ef14ad2, 0xefbe4786384f25e3 414b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65 415b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x2de92c6f592b0275, 0x4a7484aa6ea6e483 416b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5 417b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x983e5152ee66dfab, 0xa831c66d2db43210 418b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xb00327c898fb213f, 0xbf597fc7beef0ee4 419b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xc6e00bf33da88fc2, 0xd5a79147930aa725 420b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x06ca6351e003826f, 0x142929670a0e6e70 421b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x27b70a8546d22ffc, 0x2e1b21385c26c926 422b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df 423b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x650a73548baf63de, 0x766a0abb3c77b2a8 424b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x81c2c92e47edaee6, 0x92722c851482353b 425b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xa2bfe8a14cf10364, 0xa81a664bbc423001 426b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xc24b8b70d0f89791, 0xc76c51a30654be30 427b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xd192e819d6ef5218, 0xd69906245565a910 428b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xf40e35855771202a, 0x106aa07032bbd1b8 429b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x19a4c116b8d2d0c8, 0x1e376c085141ab53 430b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8 431b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb 432b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3 433b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x748f82ee5defb2fc, 0x78a5636f43172f60 434b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x84c87814a1f0ab72, 0x8cc702081a6439ec 435b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x90befffa23631e28, 0xa4506cebde82bde9 436b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xbef9a3f7b2c67915, 0xc67178f2e372532b 437b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xca273eceea26619c, 0xd186b8c721c0c207 438b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178 439b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x06f067aa72176fba, 0x0a637dc5a2c898a6 440b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x113f9804bef90dae, 0x1b710b35131c471b 441b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x28db77f523047d84, 0x32caab7b40c72493 442b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c 443b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a 444b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic .dword 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 445b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 446b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic} 447b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___; 448b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.asciiz "SHA${label} for MIPS, CRYPTOGAMS by <appro\@openssl.org>" 449b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align 5 450b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 451b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___ 452b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic 453b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code =~ s/\`([^\`]*)\`/eval $1/gem; 454b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicprint $code; 455b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicclose STDOUT; 456