1221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#!/usr/bin/env perl 2221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 3221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# ==================================================================== 4221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL 5221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# project. The module is, however, dual licensed under OpenSSL and 6221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# CRYPTOGAMS licenses depending on where you obtain it. For further 7221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# details see http://www.openssl.org/~appro/cryptogams/. 8221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# ==================================================================== 9221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 10221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# I let hardware handle unaligned input(*), except on page boundaries 11221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# (see below for details). Otherwise straightforward implementation 12221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# with X vector in register bank. The module is big-endian [which is 13221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# not big deal as there're no little-endian targets left around]. 14221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# 15221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# (*) this means that this module is inappropriate for PPC403? Does 16221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# anybody know if pre-POWER3 can sustain unaligned load? 17221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 18221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# -m64 -m32 19221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# ---------------------------------- 20221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# PPC970,gcc-4.0.0 +76% +59% 21221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# Power6,xlc-7 +68% +33% 22221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 23221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$flavour = shift; 24221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 25221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromif ($flavour =~ /64/) { 26221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $SIZE_T =8; 27392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $LRSAVE =2*$SIZE_T; 28221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $UCMP ="cmpld"; 29221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $STU ="stdu"; 30221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $POP ="ld"; 31221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH ="std"; 32221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom} elsif ($flavour =~ /32/) { 33221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $SIZE_T =4; 34392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $LRSAVE =$SIZE_T; 35221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $UCMP ="cmplw"; 36221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $STU ="stwu"; 37221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $POP ="lwz"; 38221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH ="stw"; 39221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom} else { die "nonsense $flavour"; } 40221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 41221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; 42221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or 43221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or 44221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromdie "can't locate ppc-xlate.pl"; 45221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 46221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromopen STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!"; 47221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 48392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom$FRAME=24*$SIZE_T+64; 49392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom$LOCALS=6*$SIZE_T; 50221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 51221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$K ="r0"; 52221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$sp ="r1"; 53221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$toc="r2"; 54221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$ctx="r3"; 55221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$inp="r4"; 56221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$num="r5"; 57221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$t0 ="r15"; 58221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$t1 ="r6"; 59221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 60221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$A ="r7"; 61221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$B ="r8"; 62221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$C ="r9"; 63221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$D ="r10"; 64221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$E ="r11"; 65221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$T ="r12"; 66221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 67221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom@V=($A,$B,$C,$D,$E,$T); 68221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom@X=("r16","r17","r18","r19","r20","r21","r22","r23", 69221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom "r24","r25","r26","r27","r28","r29","r30","r31"); 70221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 71221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromsub BODY_00_19 { 72221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrommy ($i,$a,$b,$c,$d,$e,$f)=@_; 73221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrommy $j=$i+1; 74221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___ if ($i==0); 75221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz @X[$i],`$i*4`($inp) 76221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 77221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___ if ($i<15); 78221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz @X[$j],`$j*4`($inp) 79221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$K,$e 80221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $e,$a,5 81221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,@X[$i] 82221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom and $t0,$c,$b 83221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$e 84221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom andc $t1,$d,$b 85221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $b,$b,30 86221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom or $t0,$t0,$t1 87221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$t0 88221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 89221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___ if ($i>=15); 90221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$K,$e 91221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $e,$a,5 92221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor @X[$j%16],@X[$j%16],@X[($j+2)%16] 93221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,@X[$i%16] 94221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom and $t0,$c,$b 95221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor @X[$j%16],@X[$j%16],@X[($j+8)%16] 96221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$e 97221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom andc $t1,$d,$b 98221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $b,$b,30 99221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom or $t0,$t0,$t1 100221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor @X[$j%16],@X[$j%16],@X[($j+13)%16] 101221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$t0 102221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi @X[$j%16],@X[$j%16],1 103221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 104221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom} 105221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 106221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromsub BODY_20_39 { 107221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrommy ($i,$a,$b,$c,$d,$e,$f)=@_; 108221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrommy $j=$i+1; 109221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___ if ($i<79); 110221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$K,$e 111221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $e,$a,5 112221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor @X[$j%16],@X[$j%16],@X[($j+2)%16] 113221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,@X[$i%16] 114221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor $t0,$b,$c 115221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor @X[$j%16],@X[$j%16],@X[($j+8)%16] 116221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$e 117221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $b,$b,30 118221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor $t0,$t0,$d 119221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor @X[$j%16],@X[$j%16],@X[($j+13)%16] 120221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$t0 121221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi @X[$j%16],@X[$j%16],1 122221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 123221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___ if ($i==79); 124221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$K,$e 125221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $e,$a,5 126221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz r16,0($ctx) 127221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,@X[$i%16] 128221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor $t0,$b,$c 129221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz r17,4($ctx) 130221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$e 131221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $b,$b,30 132221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz r18,8($ctx) 133221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor $t0,$t0,$d 134221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz r19,12($ctx) 135221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$t0 136221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz r20,16($ctx) 137221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 138221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom} 139221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 140221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromsub BODY_40_59 { 141221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrommy ($i,$a,$b,$c,$d,$e,$f)=@_; 142221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrommy $j=$i+1; 143221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___; 144221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$K,$e 145221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $e,$a,5 146221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor @X[$j%16],@X[$j%16],@X[($j+2)%16] 147221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,@X[$i%16] 148221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom and $t0,$b,$c 149221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor @X[$j%16],@X[$j%16],@X[($j+8)%16] 150221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$e 151221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom or $t1,$b,$c 152221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi $b,$b,30 153221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom xor @X[$j%16],@X[$j%16],@X[($j+13)%16] 154221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom and $t1,$t1,$d 155221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom or $t0,$t0,$t1 156221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom rotlwi @X[$j%16],@X[$j%16],1 157221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add $f,$f,$t0 158221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 159221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom} 160221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 161221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code=<<___; 162221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom.machine "any" 163221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom.text 164221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 165221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom.globl .sha1_block_data_order 166221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom.align 4 167221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom.sha1_block_data_order: 168392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $STU $sp,-$FRAME($sp) 169221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mflr r0 170221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r15,`$FRAME-$SIZE_T*17`($sp) 171221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r16,`$FRAME-$SIZE_T*16`($sp) 172221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r17,`$FRAME-$SIZE_T*15`($sp) 173221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r18,`$FRAME-$SIZE_T*14`($sp) 174221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r19,`$FRAME-$SIZE_T*13`($sp) 175221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r20,`$FRAME-$SIZE_T*12`($sp) 176221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r21,`$FRAME-$SIZE_T*11`($sp) 177221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r22,`$FRAME-$SIZE_T*10`($sp) 178221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r23,`$FRAME-$SIZE_T*9`($sp) 179221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r24,`$FRAME-$SIZE_T*8`($sp) 180221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r25,`$FRAME-$SIZE_T*7`($sp) 181221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r26,`$FRAME-$SIZE_T*6`($sp) 182221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r27,`$FRAME-$SIZE_T*5`($sp) 183221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r28,`$FRAME-$SIZE_T*4`($sp) 184221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r29,`$FRAME-$SIZE_T*3`($sp) 185221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r30,`$FRAME-$SIZE_T*2`($sp) 186221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $PUSH r31,`$FRAME-$SIZE_T*1`($sp) 187392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $PUSH r0,`$FRAME+$LRSAVE`($sp) 188221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz $A,0($ctx) 189221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz $B,4($ctx) 190221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz $C,8($ctx) 191221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz $D,12($ctx) 192221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lwz $E,16($ctx) 193221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom andi. r0,$inp,3 194221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom bne Lunaligned 195221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromLaligned: 196221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mtctr $num 197221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom bl Lsha1_block_private 198392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom b Ldone 199221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 200392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom; PowerPC specification allows an implementation to be ill-behaved 201392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom; upon unaligned access which crosses page boundary. "Better safe 202392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom; than sorry" principle makes me treat it specially. But I don't 203392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom; look for particular offending word, but rather for 64-byte input 204392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom; block which crosses the boundary. Once found that block is aligned 205392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom; and hashed separately... 206221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom.align 4 207221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromLunaligned: 208221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom subfic $t1,$inp,4096 209221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom andi. $t1,$t1,4095 ; distance to closest page boundary 210221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom srwi. $t1,$t1,6 ; t1/=64 211221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom beq Lcross_page 212221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom $UCMP $num,$t1 213221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom ble- Laligned ; didn't cross the page boundary 214221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mtctr $t1 215221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom subfc $num,$t1,$num 216221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom bl Lsha1_block_private 217221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromLcross_page: 218221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom li $t1,16 219221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mtctr $t1 220392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom addi r20,$sp,$LOCALS ; spot within the frame 221221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromLmemcpy: 222221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lbz r16,0($inp) 223221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lbz r17,1($inp) 224221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lbz r18,2($inp) 225221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lbz r19,3($inp) 226221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom addi $inp,$inp,4 227221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom stb r16,0(r20) 228221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom stb r17,1(r20) 229221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom stb r18,2(r20) 230221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom stb r19,3(r20) 231221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom addi r20,r20,4 232221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom bdnz Lmemcpy 233221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 234392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $PUSH $inp,`$FRAME-$SIZE_T*18`($sp) 235221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom li $t1,1 236392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom addi $inp,$sp,$LOCALS 237221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mtctr $t1 238221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom bl Lsha1_block_private 239392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP $inp,`$FRAME-$SIZE_T*18`($sp) 240221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom addic. $num,$num,-1 241221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom bne- Lunaligned 242392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 243392aa7cc7d2b122614c5393c3e357da07fd07af3Brian CarlstromLdone: 244392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r0,`$FRAME+$LRSAVE`($sp) 245392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r15,`$FRAME-$SIZE_T*17`($sp) 246392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r16,`$FRAME-$SIZE_T*16`($sp) 247392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r17,`$FRAME-$SIZE_T*15`($sp) 248392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r18,`$FRAME-$SIZE_T*14`($sp) 249392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r19,`$FRAME-$SIZE_T*13`($sp) 250392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r20,`$FRAME-$SIZE_T*12`($sp) 251392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r21,`$FRAME-$SIZE_T*11`($sp) 252392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r22,`$FRAME-$SIZE_T*10`($sp) 253392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r23,`$FRAME-$SIZE_T*9`($sp) 254392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r24,`$FRAME-$SIZE_T*8`($sp) 255392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r25,`$FRAME-$SIZE_T*7`($sp) 256392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r26,`$FRAME-$SIZE_T*6`($sp) 257392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r27,`$FRAME-$SIZE_T*5`($sp) 258392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r28,`$FRAME-$SIZE_T*4`($sp) 259392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r29,`$FRAME-$SIZE_T*3`($sp) 260392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r30,`$FRAME-$SIZE_T*2`($sp) 261392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $POP r31,`$FRAME-$SIZE_T*1`($sp) 262392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom mtlr r0 263392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom addi $sp,$sp,$FRAME 264392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom blr 265392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom .long 0 266392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom .byte 0,12,4,1,0x80,18,3,0 267392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom .long 0 268221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 269221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 270221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# This is private block function, which uses tailored calling 271221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# interface, namely upon entry SHA_CTX is pre-loaded to given 272221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# registers and counter register contains amount of chunks to 273221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# digest... 274221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___; 275221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom.align 4 276221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromLsha1_block_private: 277221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 278221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___; # load K_00_19 279221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lis $K,0x5a82 280221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom ori $K,$K,0x7999 281221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 282221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromfor($i=0;$i<20;$i++) { &BODY_00_19($i,@V); unshift(@V,pop(@V)); } 283221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___; # load K_20_39 284221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lis $K,0x6ed9 285221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom ori $K,$K,0xeba1 286221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 287221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromfor(;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); } 288221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___; # load K_40_59 289221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lis $K,0x8f1b 290221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom ori $K,$K,0xbcdc 291221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 292221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromfor(;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); } 293221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___; # load K_60_79 294221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom lis $K,0xca62 295221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom ori $K,$K,0xc1d6 296221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 297221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromfor(;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); } 298221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___; 299221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add r16,r16,$E 300221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add r17,r17,$T 301221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add r18,r18,$A 302221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add r19,r19,$B 303221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom add r20,r20,$C 304221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom stw r16,0($ctx) 305221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mr $A,r16 306221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom stw r17,4($ctx) 307221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mr $B,r17 308221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom stw r18,8($ctx) 309221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mr $C,r18 310221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom stw r19,12($ctx) 311221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mr $D,r19 312221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom stw r20,16($ctx) 313221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mr $E,r20 314221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom addi $inp,$inp,`16*4` 315221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom bdnz- Lsha1_block_private 316221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom blr 317392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom .long 0 318392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom .byte 0,12,0x14,0,0,0,0,0 319221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 320221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code.=<<___; 321221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom.asciz "SHA1 block transform for PPC, CRYPTOGAMS by <appro\@fy.chalmers.se>" 322221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom___ 323221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 324221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$code =~ s/\`([^\`]*)\`/eval $1/gem; 325221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromprint $code; 326221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromclose STDOUT; 327