SHA1 algorithm is defined using 32-bit variables in big-endian. This patch updates sha1-ppc.pl to generate code that byte swaps the input data when needed.
Signed-off-by: Marcelo Cerri <[email protected]> --- crypto/sha/asm/sha1-ppc.pl | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/crypto/sha/asm/sha1-ppc.pl b/crypto/sha/asm/sha1-ppc.pl index 8aa5a37..9cc0d22 100755 --- a/crypto/sha/asm/sha1-ppc.pl +++ b/crypto/sha/asm/sha1-ppc.pl @@ -38,6 +38,29 @@ if ($flavour =~ /64/) { $PUSH ="stw"; } else { die "nonsense $flavour"; } +# Define endianess based on flavour +# i.e.: linux-ppc64le +$LITTLE_ENDIAN=0; +if ($flavour =~ /le$/) { + if ($SIZE_T == 4) { + die "little-endian is 64-bit only: $flavour"; + } + $LITTLE_ENDIAN=1; +} + +sub load { +my ($dst, $src, $temp_reg) = @_; +$code.=<<___; +lwz $dst,$src +___ +$code.=<<___ if $LITTLE_ENDIAN; +rotlwi $temp_reg,$dst,8 +rlwimi $temp_reg,$dst,24,0,7 +rlwimi $temp_reg,$dst,24,16,23 +clrldi $dst,$temp_reg,32 +___ +} + $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or ( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or @@ -71,11 +94,12 @@ $T ="r12"; sub BODY_00_19 { my ($i,$a,$b,$c,$d,$e,$f)=@_; my $j=$i+1; -$code.=<<___ if ($i==0); - lwz @X[$i],`$i*4`($inp) -___ + +# Since the last value of $f is discarded, we can use +# it as a temp reg to swap byte-order when needed. +load("@X[$i]","`$i*4`($inp)",$f) if ($i==0); +load("@X[$j]","`$j*4`($inp)",$f) if ($i<15); $code.=<<___ if ($i<15); - lwz @X[$j],`$j*4`($inp) add $f,$K,$e rotlwi $e,$a,5 add $f,$f,@X[$i] -- 1.7.12 ______________________________________________________________________ OpenSSL Project http://www.openssl.org Development Mailing List [email protected] Automated List Manager [email protected]
