This patch updates aes-ppc.pl to generate code that byte swaps the input
data when needed,

Signed-off-by: Marcelo Cerri <[email protected]>
---
 crypto/aes/asm/aes-ppc.pl | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/crypto/aes/asm/aes-ppc.pl b/crypto/aes/asm/aes-ppc.pl
index 18138c2..e9d70e8 100644
--- a/crypto/aes/asm/aes-ppc.pl
+++ b/crypto/aes/asm/aes-ppc.pl
@@ -45,6 +45,14 @@ if ($flavour =~ /64/) {
        $PUSH   ="stw";
 } else { die "nonsense $flavour"; }
 
+$LITTLE_ENDIAN=0;
+if ($flavour =~ /le$/) {
+       if ($SIZE_T == 4) {
+               die "little-endian is 64-bit only: $flavour";
+       }
+       $LITTLE_ENDIAN=1;
+}
+
 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
 ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
 ( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
@@ -59,6 +67,17 @@ sub _data_word()
     while(defined($i=shift)) { $code.=sprintf"\t.long\t0x%08x,0x%08x\n",$i,$i; 
}
 }
 
+sub fix_byte_order
+{
+       my ($reg, $tmp) = @_;
+$code.=<<___ if ($LITTLE_ENDIAN);
+       rotlwi  $tmp,$reg,8
+       rlwimi  $tmp,$reg,24,0,7
+       rlwimi  $tmp,$reg,24,16,23
+       clrldi  $reg,$tmp,32
+___
+}
+
 $sp="r1";
 $toc="r2";
 $inp="r3";
@@ -618,6 +637,12 @@ Lenc_loop:
 
 .align 4
 Lppc_AES_encrypt_compact:
+___
+       fix_byte_order($s0,$acc00);
+       fix_byte_order($s1,$acc00);
+       fix_byte_order($s2,$acc00);
+       fix_byte_order($s3,$acc00);
+$code.=<<___;
        lwz     $acc00,240($key)
        addi    $Tbl1,$Tbl0,2048
        lwz     $t0,0($key)
@@ -757,6 +782,12 @@ Lenc_compact_done:
        xor     $s1,$s1,$t1
        xor     $s2,$s2,$t2
        xor     $s3,$s3,$t3
+___
+       fix_byte_order($s0,$acc00);
+       fix_byte_order($s1,$acc00);
+       fix_byte_order($s2,$acc00);
+       fix_byte_order($s3,$acc00);
+$code.=<<___;
        blr
        .long   0
        .byte   0,12,0x14,0,0,0,0,0
@@ -1052,6 +1083,12 @@ Ldec_loop:
 
 .align 4
 Lppc_AES_decrypt_compact:
+___
+       fix_byte_order($s0,$acc00);
+       fix_byte_order($s1,$acc00);
+       fix_byte_order($s2,$acc00);
+       fix_byte_order($s3,$acc00);
+$code.=<<___;
        lwz     $acc00,240($key)
        addi    $Tbl1,$Tbl0,2048
        lwz     $t0,0($key)
@@ -1348,6 +1385,12 @@ Ldec_compact_done:
        xor     $s1,$s1,$t1
        xor     $s2,$s2,$t2
        xor     $s3,$s3,$t3
+___
+       fix_byte_order($s0,$acc00);
+       fix_byte_order($s1,$acc00);
+       fix_byte_order($s2,$acc00);
+       fix_byte_order($s3,$acc00);
+$code.=<<___;
        blr
        .long   0
        .byte   0,12,0x14,0,0,0,0,0
-- 
1.7.12

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [email protected]
Automated List Manager                           [email protected]

Reply via email to