Padlock: fix byte swapping assembly for AES-192 and 256
[openssl.git] / engines / asm / e_padlock-x86.pl
index 4148468c41de695751e8731369a948dff171c1ca..bb2b14468982cbb989326458231c8b6703a8b349 100644 (file)
@@ -1,4 +1,11 @@
-#!/usr/bin/env perl
+#! /usr/bin/env perl
+# Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (the "License").  You may not use
+# this file except in compliance with the License.  You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
 
 # ====================================================================
 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
@@ -35,7 +42,9 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
 push(@INC,"${dir}","${dir}../../crypto/perlasm");
 require "x86asm.pl";
 
-&asm_init($ARGV[0],$0);
+$output=pop and open STDOUT,">$output";
+
+&asm_init($ARGV[0]);
 
 %PADLOCK_PREFETCH=(ecb=>128, cbc=>64); # prefetch errata
 $PADLOCK_CHUNK=512;    # Must be a power of 2 larger than 16
@@ -63,11 +72,20 @@ $chunk="ebx";
        &cpuid  ();
        &xor    ("eax","eax");
        &cmp    ("ebx","0x".unpack("H*",'tneC'));
-       &jne    (&label("noluck"));
+       &jne    (&label("zhaoxin"));
        &cmp    ("edx","0x".unpack("H*",'Hrua'));
        &jne    (&label("noluck"));
        &cmp    ("ecx","0x".unpack("H*",'slua'));
        &jne    (&label("noluck"));
+       &jmp    (&label("zhaoxinEnd"));
+&set_label("zhaoxin");
+       &cmp    ("ebx","0x".unpack("H*",'hS  '));
+       &jne    (&label("noluck"));
+       &cmp    ("edx","0x".unpack("H*",'hgna'));
+       &jne    (&label("noluck"));
+       &cmp    ("ecx","0x".unpack("H*",'  ia'));
+       &jne    (&label("noluck"));
+&set_label("zhaoxinEnd");
        &mov    ("eax",0xC0000000);
        &cpuid  ();
        &mov    ("edx","eax");
@@ -97,6 +115,8 @@ $chunk="ebx";
 &function_begin_B("padlock_key_bswap");
        &mov    ("edx",&wparam(0));
        &mov    ("ecx",&DWP(240,"edx"));
+       &inc    ("ecx");
+       &shl    ("ecx",2);
 &set_label("bswap_loop");
        &mov    ("eax",&DWP(0,"edx"));
        &bswap  ("eax");
@@ -604,3 +624,5 @@ my ($mode,$opcode) = @_;
 &data_word(0);
 
 &asm_finish();
+
+close STDOUT;