Blame SOURCES/nettle-3.4.1-powerpc64-aes-asm.patch

b507f4
diff --git a/Makefile.in b/Makefile.in
b507f4
index b43e494f..ec46a9df 100644
b507f4
--- a/Makefile.in
b507f4
+++ b/Makefile.in
b507f4
@@ -189,7 +189,7 @@ hogweed_SOURCES = sexp.c sexp-format.c \
b507f4
 		  ed25519-sha512-pubkey.c \
b507f4
 		  ed25519-sha512-sign.c ed25519-sha512-verify.c
b507f4
 
b507f4
-OPT_SOURCES = fat-x86_64.c fat-arm.c mini-gmp.c
b507f4
+OPT_SOURCES = fat-arm.c fat-ppc.c fat-x86_64.c mini-gmp.c
b507f4
 
b507f4
 HEADERS = aes.h arcfour.h arctwo.h asn1.h blowfish.h \
b507f4
 	  base16.h base64.h bignum.h buffer.h camellia.h cast128.h \
b507f4
@@ -573,7 +573,8 @@ distdir: $(DISTFILES)
b507f4
 	done
b507f4
 	set -e; for d in sparc32 sparc64 x86 \
b507f4
 		x86_64 x86_64/aesni x86_64/fat \
b507f4
-		arm arm/neon arm/v6 arm/fat ; do \
b507f4
+		arm arm/neon arm/v6 arm/fat \
b507f4
+		powerpc64 powerpc64/p8 powerpc64/fat ; do \
b507f4
 	  mkdir "$(distdir)/$$d" ; \
b507f4
 	  find "$(srcdir)/$$d" -maxdepth 1 '(' -name '*.asm' -o -name '*.m4' ')' \
b507f4
 	    -exec cp '{}' "$(distdir)/$$d" ';' ; \
b507f4
diff --git a/aes-decrypt-internal.c b/aes-decrypt-internal.c
b507f4
index 709c52f9..9e8cf34a 100644
b507f4
--- a/aes-decrypt-internal.c
b507f4
+++ b/aes-decrypt-internal.c
b507f4
@@ -40,6 +40,16 @@
b507f4
 #include "aes-internal.h"
b507f4
 #include "macros.h"
b507f4
 
b507f4
+/* For fat builds */
b507f4
+#if HAVE_NATIVE_aes_decrypt
b507f4
+void
b507f4
+_nettle_aes_decrypt_c(unsigned rounds, const uint32_t *keys,
b507f4
+    const struct aes_table *T,
b507f4
+    size_t length, uint8_t *dst,
b507f4
+    const uint8_t *src);
b507f4
+#define _nettle_aes_decrypt _nettle_aes_decrypt_c
b507f4
+#endif
b507f4
+
b507f4
 void
b507f4
 _nettle_aes_decrypt(unsigned rounds, const uint32_t *keys,
b507f4
 		    const struct aes_table *T,
b507f4
diff --git a/aes-encrypt-internal.c b/aes-encrypt-internal.c
b507f4
index 9f61386d..ad17e6c1 100644
b507f4
--- a/aes-encrypt-internal.c
b507f4
+++ b/aes-encrypt-internal.c
b507f4
@@ -40,6 +40,16 @@
b507f4
 #include "aes-internal.h"
b507f4
 #include "macros.h"
b507f4
 
b507f4
+/* For fat builds */
b507f4
+#if HAVE_NATIVE_aes_encrypt
b507f4
+void
b507f4
+_nettle_aes_encrypt_c(unsigned rounds, const uint32_t *keys,
b507f4
+    const struct aes_table *T,
b507f4
+    size_t length, uint8_t *dst,
b507f4
+    const uint8_t *src);
b507f4
+#define _nettle_aes_encrypt _nettle_aes_encrypt_c
b507f4
+#endif
b507f4
+
b507f4
 void
b507f4
 _nettle_aes_encrypt(unsigned rounds, const uint32_t *keys,
b507f4
 		    const struct aes_table *T,
b507f4
diff --git a/asm.m4 b/asm.m4
b507f4
index ee377a78..59d64098 100644
b507f4
--- a/asm.m4
b507f4
+++ b/asm.m4
b507f4
@@ -51,6 +51,14 @@ define(<ALIGN>,
b507f4
 <.align ifelse(ALIGN_LOG,yes,<m4_log2($1)>,$1)
b507f4
 >)
b507f4
 
b507f4
+define(<IF_BE>, 
b507f4
+WORDS_BIGENDIAN,yes,<$1>,
b507f4
+WORDS_BIGENDIAN,no,<$2>,
b507f4
+<errprint(<Unsupported endianness value>,WORDS_BIGENDIAN,<
b507f4
+>)
b507f4
+  m4exit(1)>)>)
b507f4
+define(<IF_LE>, <IF_BE(<$2>, <$1>)>)
b507f4
+
b507f4
 dnl Struct defining macros
b507f4
 
b507f4
 dnl STRUCTURE(prefix) 
b507f4
diff --git a/config.m4.in b/config.m4.in
b507f4
index 666e34b8..e480334d 100644
b507f4
--- a/config.m4.in
b507f4
+++ b/config.m4.in
b507f4
@@ -9,6 +9,7 @@ define(<W64_ABI>, <@W64_ABI@>)dnl
b507f4
 define(<RODATA>, <@ASM_RODATA@>)dnl
b507f4
 define(<ASM_X86_ENDBR>,<@ASM_X86_ENDBR@>)dnl
b507f4
 define(<ASM_X86_MARK_CET_ALIGN>,<@ASM_X86_MARK_CET_ALIGN@>)dnl
b507f4
+define(<WORDS_BIGENDIAN>, <@ASM_WORDS_BIGENDIAN@>)dnl
b507f4
 divert(1)
b507f4
 @ASM_X86_MARK_CET@
b507f4
 @ASM_MARK_NOEXEC_STACK@
b507f4
diff --git a/configure.ac b/configure.ac
b507f4
index 090e43a4..788e6842 100644
b507f4
--- a/configure.ac
b507f4
+++ b/configure.ac
b507f4
@@ -85,6 +85,10 @@ AC_ARG_ENABLE(x86-aesni,
b507f4
   AC_HELP_STRING([--enable-x86-aesni], [Enable x86_64 aes instructions. (default=no)]),,
b507f4
   [enable_x86_aesni=no])
b507f4
 
b507f4
+AC_ARG_ENABLE(power-crypto-ext,
b507f4
+  AC_HELP_STRING([--enable-power-crypto-ext], [Enable POWER crypto extensions. (default=no)]),,
b507f4
+  [enable_power_crypto_ext=no])
b507f4
+
b507f4
 AC_ARG_ENABLE(mini-gmp,
b507f4
   AC_HELP_STRING([--enable-mini-gmp], [Enable mini-gmp, used instead of libgmp.]),,
b507f4
   [enable_mini_gmp=no])
b507f4
@@ -201,7 +205,11 @@ LSH_FUNC_STRERROR
b507f4
 # getenv_secure is used for fat overrides,
b507f4
 # getline is used in the testsuite
b507f4
 AC_CHECK_FUNCS(secure_getenv getline)
b507f4
-AC_C_BIGENDIAN
b507f4
+
b507f4
+ASM_WORDS_BIGENDIAN=unknown
b507f4
+AC_C_BIGENDIAN([AC_DEFINE([WORDS_BIGENDIAN], 1)
b507f4
+		ASM_WORDS_BIGENDIAN=yes],
b507f4
+	[ASM_WORDS_BIGENDIAN=no])
b507f4
 
b507f4
 LSH_GCC_ATTRIBUTES
b507f4
 
b507f4
@@ -310,6 +318,17 @@ case "$host_cpu" in
b507f4
     AC_TRY_COMPILE([
b507f4
 #if defined(__sgi) && defined(__LP64__)
b507f4
 #error 64-bit mips
b507f4
+#endif
b507f4
+    ], [], [
b507f4
+      ABI=32
b507f4
+    ], [
b507f4
+      ABI=64
b507f4
+    ])
b507f4
+    ;;
b507f4
+  *powerpc64*)
b507f4
+    AC_TRY_COMPILE([
b507f4
+#if defined(__PPC64__)
b507f4
+#error 64-bit powerpc
b507f4
 #endif
b507f4
     ], [], [
b507f4
       ABI=32
b507f4
@@ -422,6 +441,18 @@ if test "x$enable_assembler" = xyes ; then
b507f4
 	esac
b507f4
       fi
b507f4
       ;;
b507f4
+    *powerpc64*)
b507f4
+      if test "$ABI" = 64 ; then
b507f4
+	asm_path="powerpc64"
b507f4
+	if test "x$enable_fat" = xyes ; then
b507f4
+	  asm_path="powerpc64/fat $asm_path"
b507f4
+	  OPT_NETTLE_SOURCES="fat-ppc.c $OPT_NETTLE_SOURCES"
b507f4
+	elif test "x$enable_power_crypto_ext" = xyes ; then
b507f4
+          asm_path="powerpc64/p8 $asm_path"
b507f4
+	fi
b507f4
+      fi
b507f4
+      ;;
b507f4
+
b507f4
     *)
b507f4
       enable_assembler=no
b507f4
       ;;
b507f4
@@ -544,6 +575,8 @@ AC_SUBST([IF_ASM])
b507f4
 AH_VERBATIM([HAVE_NATIVE],
b507f4
 [/* Define to 1 each of the following for which a native (ie. CPU specific)
b507f4
     implementation of the corresponding routine exists.  */
b507f4
+#undef HAVE_NATIVE_aes_decrypt
b507f4
+#undef HAVE_NATIVE_aes_encrypt
b507f4
 #undef HAVE_NATIVE_ecc_192_modp
b507f4
 #undef HAVE_NATIVE_ecc_192_redc
b507f4
 #undef HAVE_NATIVE_ecc_224_modp
b507f4
@@ -857,6 +890,7 @@ AC_SUBST(ASM_TYPE_PROGBITS)
b507f4
 AC_SUBST(ASM_MARK_NOEXEC_STACK)
b507f4
 AC_SUBST(ASM_ALIGN_LOG)
b507f4
 AC_SUBST(W64_ABI)
b507f4
+AC_SUBST(ASM_WORDS_BIGENDIAN)
b507f4
 AC_SUBST(EMULATOR)
b507f4
 AC_SUBST(ASM_X86_ENDBR)
b507f4
 AC_SUBST(ASM_X86_MARK_CET)
b507f4
diff --git a/fat-ppc.c b/fat-ppc.c
b507f4
new file mode 100644
b507f4
index 00000000..7198e2dd
b507f4
--- /dev/null
b507f4
+++ b/fat-ppc.c
b507f4
@@ -0,0 +1,129 @@
b507f4
+/* fat-ppc.c
b507f4
+
b507f4
+   Copyright (C) 2020 Mamone Tarsha
b507f4
+
b507f4
+   This file is part of GNU Nettle.
b507f4
+
b507f4
+   GNU Nettle is free software: you can redistribute it and/or
b507f4
+   modify it under the terms of either:
b507f4
+
b507f4
+     * the GNU Lesser General Public License as published by the Free
b507f4
+       Software Foundation; either version 3 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or
b507f4
+
b507f4
+     * the GNU General Public License as published by the Free
b507f4
+       Software Foundation; either version 2 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or both in parallel, as here.
b507f4
+
b507f4
+   GNU Nettle is distributed in the hope that it will be useful,
b507f4
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b507f4
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b507f4
+   General Public License for more details.
b507f4
+
b507f4
+   You should have received copies of the GNU General Public License and
b507f4
+   the GNU Lesser General Public License along with this program.  If
b507f4
+   not, see http://www.gnu.org/licenses/.
b507f4
+*/
b507f4
+
b507f4
+#define _GNU_SOURCE
b507f4
+
b507f4
+#if HAVE_CONFIG_H
b507f4
+# include "config.h"
b507f4
+#endif
b507f4
+
b507f4
+#include <assert.h>
b507f4
+#include <stdio.h>
b507f4
+#include <stdlib.h>
b507f4
+#include <string.h>
b507f4
+#if defined(__FreeBSD__) && __FreeBSD__ < 12
b507f4
+#include <sys/sysctl.h>
b507f4
+#else
b507f4
+#include <sys/auxv.h>
b507f4
+#endif
b507f4
+
b507f4
+#include "nettle-types.h"
b507f4
+
b507f4
+#include "aes-internal.h"
b507f4
+#include "gcm.h"
b507f4
+#include "fat-setup.h"
b507f4
+
b507f4
+/* Define from arch/powerpc/include/uapi/asm/cputable.h in Linux kernel */
b507f4
+#ifndef PPC_FEATURE2_VEC_CRYPTO
b507f4
+#define PPC_FEATURE2_VEC_CRYPTO 0x02000000
b507f4
+#endif
b507f4
+
b507f4
+struct ppc_features
b507f4
+{
b507f4
+  int have_crypto_ext;
b507f4
+};
b507f4
+
b507f4
+static void
b507f4
+get_ppc_features (struct ppc_features *features)
b507f4
+{
b507f4
+  unsigned long hwcap2 = 0;
b507f4
+#if defined(__FreeBSD__)
b507f4
+#if __FreeBSD__ < 12
b507f4
+  size_t len = sizeof(hwcap2);
b507f4
+  sysctlbyname("hw.cpu_features2", &hwcap2, &len, NULL, 0);
b507f4
+#else
b507f4
+  elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2));
b507f4
+#endif
b507f4
+#else
b507f4
+  hwcap2 = getauxval(AT_HWCAP2);
b507f4
+#endif
b507f4
+  features->have_crypto_ext =
b507f4
+   (hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO ? 1 : 0;
b507f4
+}
b507f4
+
b507f4
+DECLARE_FAT_FUNC(_nettle_aes_encrypt, aes_crypt_internal_func)
b507f4
+DECLARE_FAT_FUNC_VAR(aes_encrypt, aes_crypt_internal_func, c)
b507f4
+DECLARE_FAT_FUNC_VAR(aes_encrypt, aes_crypt_internal_func, ppc64)
b507f4
+
b507f4
+DECLARE_FAT_FUNC(_nettle_aes_decrypt, aes_crypt_internal_func)
b507f4
+DECLARE_FAT_FUNC_VAR(aes_decrypt, aes_crypt_internal_func, c)
b507f4
+DECLARE_FAT_FUNC_VAR(aes_decrypt, aes_crypt_internal_func, ppc64)
b507f4
+
b507f4
+static void CONSTRUCTOR
b507f4
+fat_init (void)
b507f4
+{
b507f4
+  struct ppc_features features;
b507f4
+  int verbose;
b507f4
+
b507f4
+  get_ppc_features (&features);
b507f4
+
b507f4
+  verbose = getenv (ENV_VERBOSE) != NULL;
b507f4
+  if (verbose)
b507f4
+    fprintf (stderr, "libnettle: cpu features: %s\n",
b507f4
+     features.have_crypto_ext ? "crypto extensions" : "");
b507f4
+
b507f4
+  if (features.have_crypto_ext)
b507f4
+  {
b507f4
+     if (verbose)
b507f4
+        fprintf (stderr, "libnettle: enabling arch 2.07 code.\n");
b507f4
+     _nettle_aes_encrypt_vec = _nettle_aes_encrypt_ppc64;
b507f4
+     _nettle_aes_decrypt_vec = _nettle_aes_decrypt_ppc64;
b507f4
+  }
b507f4
+  else
b507f4
+  {
b507f4
+     _nettle_aes_encrypt_vec = _nettle_aes_encrypt_c;
b507f4
+     _nettle_aes_decrypt_vec = _nettle_aes_decrypt_c;
b507f4
+  }
b507f4
+}
b507f4
+
b507f4
+DEFINE_FAT_FUNC(_nettle_aes_encrypt, void,
b507f4
+ (unsigned rounds, const uint32_t *keys,
b507f4
+ const struct aes_table *T,
b507f4
+ size_t length, uint8_t *dst,
b507f4
+ const uint8_t *src),
b507f4
+ (rounds, keys, T, length, dst, src))
b507f4
+
b507f4
+DEFINE_FAT_FUNC(_nettle_aes_decrypt, void,
b507f4
+ (unsigned rounds, const uint32_t *keys,
b507f4
+ const struct aes_table *T,
b507f4
+ size_t length, uint8_t *dst,
b507f4
+ const uint8_t *src),
b507f4
+ (rounds, keys, T, length, dst, src))
b507f4
diff --git a/powerpc64/fat/aes-decrypt-internal-2.asm b/powerpc64/fat/aes-decrypt-internal-2.asm
b507f4
new file mode 100644
b507f4
index 00000000..3a4e08c2
b507f4
--- /dev/null
b507f4
+++ b/powerpc64/fat/aes-decrypt-internal-2.asm
b507f4
@@ -0,0 +1,37 @@
b507f4
+C powerpc64/fat/aes-decrypt-internal-2.asm
b507f4
+
b507f4
+
b507f4
+ifelse(<
b507f4
+   Copyright (C) 2020 Mamone Tarsha
b507f4
+
b507f4
+   This file is part of GNU Nettle.
b507f4
+
b507f4
+   GNU Nettle is free software: you can redistribute it and/or
b507f4
+   modify it under the terms of either:
b507f4
+
b507f4
+     * the GNU Lesser General Public License as published by the Free
b507f4
+       Software Foundation; either version 3 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or
b507f4
+
b507f4
+     * the GNU General Public License as published by the Free
b507f4
+       Software Foundation; either version 2 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or both in parallel, as here.
b507f4
+
b507f4
+   GNU Nettle is distributed in the hope that it will be useful,
b507f4
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b507f4
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b507f4
+   General Public License for more details.
b507f4
+
b507f4
+   You should have received copies of the GNU General Public License and
b507f4
+   the GNU Lesser General Public License along with this program.  If
b507f4
+   not, see http://www.gnu.org/licenses/.
b507f4
+>)
b507f4
+
b507f4
+dnl PROLOGUE(_nettle_aes_decrypt) picked up by configure
b507f4
+
b507f4
+define(<fat_transform>, <$1_ppc64>)
b507f4
+include_src(<powerpc64/p8/aes-decrypt-internal.asm>)
b507f4
diff --git a/powerpc64/fat/aes-encrypt-internal-2.asm b/powerpc64/fat/aes-encrypt-internal-2.asm
b507f4
new file mode 100644
b507f4
index 00000000..42126e4f
b507f4
--- /dev/null
b507f4
+++ b/powerpc64/fat/aes-encrypt-internal-2.asm
b507f4
@@ -0,0 +1,37 @@
b507f4
+C powerpc64/fat/aes-encrypt-internal-2.asm
b507f4
+
b507f4
+
b507f4
+ifelse(<
b507f4
+   Copyright (C) 2020 Mamone Tarsha
b507f4
+
b507f4
+   This file is part of GNU Nettle.
b507f4
+
b507f4
+   GNU Nettle is free software: you can redistribute it and/or
b507f4
+   modify it under the terms of either:
b507f4
+
b507f4
+     * the GNU Lesser General Public License as published by the Free
b507f4
+       Software Foundation; either version 3 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or
b507f4
+
b507f4
+     * the GNU General Public License as published by the Free
b507f4
+       Software Foundation; either version 2 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or both in parallel, as here.
b507f4
+
b507f4
+   GNU Nettle is distributed in the hope that it will be useful,
b507f4
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b507f4
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b507f4
+   General Public License for more details.
b507f4
+
b507f4
+   You should have received copies of the GNU General Public License and
b507f4
+   the GNU Lesser General Public License along with this program.  If
b507f4
+   not, see http://www.gnu.org/licenses/.
b507f4
+>)
b507f4
+
b507f4
+dnl PROLOGUE(_nettle_aes_encrypt) picked up by configure
b507f4
+
b507f4
+define(<fat_transform>, <$1_ppc64>)
b507f4
+include_src(<powerpc64/p8/aes-encrypt-internal.asm>)
b507f4
diff --git a/powerpc64/machine.m4 b/powerpc64/machine.m4
b507f4
new file mode 100644
b507f4
index 00000000..b76bb8b1
b507f4
--- /dev/null
b507f4
+++ b/powerpc64/machine.m4
b507f4
@@ -0,0 +1,36 @@
b507f4
+define(<PROLOGUE>,
b507f4
+<.globl C_NAME($1)
b507f4
+DECLARE_FUNC(C_NAME($1))
b507f4
+ifelse(WORDS_BIGENDIAN,no,
b507f4
+<ifdef(<FUNC_ALIGN>,<.align FUNC_ALIGN>)
b507f4
+C_NAME($1):
b507f4
+addis 2,12,(.TOC.-C_NAME($1))@ha
b507f4
+addi 2,2,(.TOC.-C_NAME($1))@l
b507f4
+.localentry C_NAME($1), .-C_NAME($1)>,
b507f4
+<.section ".opd","aw"
b507f4
+.align 3
b507f4
+C_NAME($1):
b507f4
+.quad .C_NAME($1),.TOC.@tocbase,0
b507f4
+.previous
b507f4
+ifdef(<FUNC_ALIGN>,<.align FUNC_ALIGN>)
b507f4
+.C_NAME($1):>)
b507f4
+undefine(<FUNC_ALIGN>)>)
b507f4
+
b507f4
+define(<EPILOGUE>,
b507f4
+
b507f4
+<.size C_NAME($1), . - C_NAME($1)>,
b507f4
+<.size .C_NAME($1), . - .C_NAME($1)
b507f4
+.size C_NAME($1), . - .C_NAME($1)>)>)
b507f4
+
b507f4
+C Get vector-scalar register from vector register
b507f4
+C VSR(VR)
b507f4
+define(<VSR>,<32+$1>)
b507f4
+
b507f4
+C Load the quadword in DATA_SRC storage into
b507f4
+C VEC_DST. GPR is general-purpose register
b507f4
+C used to obtain the effective address of
b507f4
+C DATA_SRC storage.
b507f4
+C DATA_LOAD_VEC(VEC_DST, DATA_SRC, GPR)
b507f4
+define(<DATA_LOAD_VEC>,
b507f4
+
b507f4
+lvx $1,0,$3>)
b507f4
diff --git a/powerpc64/p8/aes-decrypt-internal.asm b/powerpc64/p8/aes-decrypt-internal.asm
b507f4
new file mode 100644
b507f4
index 00000000..bfedb32b
b507f4
--- /dev/null
b507f4
+++ b/powerpc64/p8/aes-decrypt-internal.asm
b507f4
@@ -0,0 +1,356 @@
b507f4
+C powerpc64/p8/aes-decrypt-internal.asm
b507f4
+
b507f4
+ifelse(<
b507f4
+   Copyright (C) 2020 Mamone Tarsha
b507f4
+   This file is part of GNU Nettle.
b507f4
+
b507f4
+   GNU Nettle is free software: you can redistribute it and/or
b507f4
+   modify it under the terms of either:
b507f4
+
b507f4
+     * the GNU Lesser General Public License as published by the Free
b507f4
+       Software Foundation; either version 3 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or
b507f4
+
b507f4
+     * the GNU General Public License as published by the Free
b507f4
+       Software Foundation; either version 2 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or both in parallel, as here.
b507f4
+
b507f4
+   GNU Nettle is distributed in the hope that it will be useful,
b507f4
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b507f4
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b507f4
+   General Public License for more details.
b507f4
+
b507f4
+   You should have received copies of the GNU General Public License and
b507f4
+   the GNU Lesser General Public License along with this program.  If
b507f4
+   not, see http://www.gnu.org/licenses/.
b507f4
+>)
b507f4
+
b507f4
+C Register usage:
b507f4
+
b507f4
+define(<SP>, <1>)
b507f4
+define(<TOCP>, <2>)
b507f4
+
b507f4
+define(<ROUNDS>, <3>)
b507f4
+define(<KEYS>, <4>)
b507f4
+define(<LENGTH>, <6>)
b507f4
+define(<DST>, <7>)
b507f4
+define(<SRC>, <8>)
b507f4
+
b507f4
+define(<swap_mask>, <0>)
b507f4
+
b507f4
+define(<K>, <1>)
b507f4
+define(<S0>, <2>)
b507f4
+define(<S1>, <3>)
b507f4
+define(<S2>, <4>)
b507f4
+define(<S3>, <5>)
b507f4
+define(<S4>, <6>)
b507f4
+define(<S5>, <7>)
b507f4
+define(<S6>, <8>)
b507f4
+define(<S7>, <9>)
b507f4
+
b507f4
+C ZERO vector register is used in place of RoundKey
b507f4
+C for vncipher instruction because the order of InvMixColumns
b507f4
+C and Xor processes are flipped in that instruction.
b507f4
+C The Xor process with RoundKey is executed afterward.
b507f4
+define(<ZERO>, <10>)
b507f4
+
b507f4
+.file "aes-decrypt-internal.asm"
b507f4
+
b507f4
+.text
b507f4
+
b507f4
+ C _aes_decrypt(unsigned rounds, const uint32_t *keys,
b507f4
+ C       const struct aes_table *T,
b507f4
+ C       size_t length, uint8_t *dst,
b507f4
+ C       uint8_t *src)
b507f4
+
b507f4
+define(<FUNC_ALIGN>, <5>)
b507f4
+PROLOGUE(_nettle_aes_decrypt)
b507f4
+ vxor ZERO,ZERO,ZERO
b507f4
+
b507f4
+ DATA_LOAD_VEC(swap_mask,.swap_mask,5)
b507f4
+
b507f4
+ subi ROUNDS,ROUNDS,1
b507f4
+ srdi LENGTH,LENGTH,4
b507f4
+
b507f4
+ srdi 5,LENGTH,3 #8x loop count
b507f4
+ cmpldi 5,0
b507f4
+ beq L4x
b507f4
+
b507f4
+ std 25,-56(SP);
b507f4
+ std 26,-48(SP);
b507f4
+ std 27,-40(SP);
b507f4
+ std 28,-32(SP);
b507f4
+ std 29,-24(SP);
b507f4
+ std 30,-16(SP);
b507f4
+ std 31,-8(SP);
b507f4
+
b507f4
+ li 25,0x10
b507f4
+ li 26,0x20
b507f4
+ li 27,0x30
b507f4
+ li 28,0x40
b507f4
+ li 29,0x50
b507f4
+ li 30,0x60
b507f4
+ li 31,0x70
b507f4
+
b507f4
+.align 5
b507f4
+Lx8_loop:
b507f4
+ lxvd2x VSR(K),0,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+
b507f4
+ lxvd2x VSR(S0),0,SRC
b507f4
+ lxvd2x VSR(S1),25,SRC
b507f4
+ lxvd2x VSR(S2),26,SRC
b507f4
+ lxvd2x VSR(S3),27,SRC
b507f4
+ lxvd2x VSR(S4),28,SRC
b507f4
+ lxvd2x VSR(S5),29,SRC
b507f4
+ lxvd2x VSR(S6),30,SRC
b507f4
+ lxvd2x VSR(S7),31,SRC
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask
b507f4
+ vperm S2,S2,S2,swap_mask
b507f4
+ vperm S3,S3,S3,swap_mask
b507f4
+ vperm S4,S4,S4,swap_mask
b507f4
+ vperm S5,S5,S5,swap_mask
b507f4
+ vperm S6,S6,S6,swap_mask
b507f4
+ vperm S7,S7,S7,swap_mask>)
b507f4
+
b507f4
+ vxor S0,S0,K
b507f4
+ vxor S1,S1,K
b507f4
+ vxor S2,S2,K
b507f4
+ vxor S3,S3,K
b507f4
+ vxor S4,S4,K
b507f4
+ vxor S5,S5,K
b507f4
+ vxor S6,S6,K
b507f4
+ vxor S7,S7,K
b507f4
+
b507f4
+ mtctr ROUNDS
b507f4
+ li 10,0x10
b507f4
+.align 5
b507f4
+L8x_round_loop:
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+ vncipher S0,S0,ZERO
b507f4
+ vncipher S1,S1,ZERO
b507f4
+ vncipher S2,S2,ZERO
b507f4
+ vncipher S3,S3,ZERO
b507f4
+ vncipher S4,S4,ZERO
b507f4
+ vncipher S5,S5,ZERO
b507f4
+ vncipher S6,S6,ZERO
b507f4
+ vncipher S7,S7,ZERO
b507f4
+ vxor S0,S0,K
b507f4
+ vxor S1,S1,K
b507f4
+ vxor S2,S2,K
b507f4
+ vxor S3,S3,K
b507f4
+ vxor S4,S4,K
b507f4
+ vxor S5,S5,K
b507f4
+ vxor S6,S6,K
b507f4
+ vxor S7,S7,K
b507f4
+ addi 10,10,0x10
b507f4
+ bdnz L8x_round_loop
b507f4
+
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+ vncipherlast S0,S0,K
b507f4
+ vncipherlast S1,S1,K
b507f4
+ vncipherlast S2,S2,K
b507f4
+ vncipherlast S3,S3,K
b507f4
+ vncipherlast S4,S4,K
b507f4
+ vncipherlast S5,S5,K
b507f4
+ vncipherlast S6,S6,K
b507f4
+ vncipherlast S7,S7,K
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask
b507f4
+ vperm S2,S2,S2,swap_mask
b507f4
+ vperm S3,S3,S3,swap_mask
b507f4
+ vperm S4,S4,S4,swap_mask
b507f4
+ vperm S5,S5,S5,swap_mask
b507f4
+ vperm S6,S6,S6,swap_mask
b507f4
+ vperm S7,S7,S7,swap_mask>)
b507f4
+
b507f4
+ stxvd2x VSR(S0),0,DST
b507f4
+ stxvd2x VSR(S1),25,DST
b507f4
+ stxvd2x VSR(S2),26,DST
b507f4
+ stxvd2x VSR(S3),27,DST
b507f4
+ stxvd2x VSR(S4),28,DST
b507f4
+ stxvd2x VSR(S5),29,DST
b507f4
+ stxvd2x VSR(S6),30,DST
b507f4
+ stxvd2x VSR(S7),31,DST
b507f4
+
b507f4
+ addi SRC,SRC,0x80
b507f4
+ addi DST,DST,0x80
b507f4
+ subic. 5,5,1
b507f4
+ bne Lx8_loop
b507f4
+
b507f4
+ ld 25,-56(SP);
b507f4
+ ld 26,-48(SP);
b507f4
+ ld 27,-40(SP);
b507f4
+ ld 28,-32(SP);
b507f4
+ ld 29,-24(SP);
b507f4
+ ld 30,-16(SP);
b507f4
+ ld 31,-8(SP);
b507f4
+
b507f4
+ clrldi LENGTH,LENGTH,61
b507f4
+
b507f4
+L4x:
b507f4
+ srdi   5,LENGTH,2
b507f4
+ cmpldi   5,0
b507f4
+ beq   L2x
b507f4
+
b507f4
+ lxvd2x   VSR(K),0,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+
b507f4
+ lxvd2x VSR(S0),0,SRC
b507f4
+ li  9,0x10
b507f4
+ lxvd2x VSR(S1),9,SRC
b507f4
+ addi   9,9,0x10
b507f4
+ lxvd2x VSR(S2),9,SRC
b507f4
+ addi   9,9,0x10
b507f4
+ lxvd2x VSR(S3),9,SRC
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask
b507f4
+ vperm S2,S2,S2,swap_mask
b507f4
+ vperm S3,S3,S3,swap_mask>)
b507f4
+
b507f4
+ vxor S0,S0,K
b507f4
+ vxor S1,S1,K
b507f4
+ vxor S2,S2,K
b507f4
+ vxor S3,S3,K
b507f4
+
b507f4
+ mtctr ROUNDS
b507f4
+ li 10,0x10
b507f4
+.align 5
b507f4
+L4x_round_loop:
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vncipher S0,S0,ZERO
b507f4
+ vncipher S1,S1,ZERO
b507f4
+ vncipher S2,S2,ZERO
b507f4
+ vncipher S3,S3,ZERO
b507f4
+ vxor   S0,S0,K
b507f4
+ vxor  S1,S1,K
b507f4
+ vxor   S2,S2,K
b507f4
+ vxor   S3,S3,K
b507f4
+ addi   10,10,0x10
b507f4
+ bdnz  L4x_round_loop
b507f4
+
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+ vncipherlast S0,S0,K
b507f4
+ vncipherlast S1,S1,K
b507f4
+ vncipherlast S2,S2,K
b507f4
+ vncipherlast S3,S3,K
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask
b507f4
+ vperm S2,S2,S2,swap_mask
b507f4
+ vperm S3,S3,S3,swap_mask>)
b507f4
+
b507f4
+ stxvd2x VSR(S0),0,DST
b507f4
+ li  9,0x10
b507f4
+ stxvd2x VSR(S1),9,DST
b507f4
+ addi   9,9,0x10
b507f4
+ stxvd2x VSR(S2),9,DST
b507f4
+ addi  9,9,0x10
b507f4
+ stxvd2x VSR(S3),9,DST
b507f4
+
b507f4
+ addi   SRC,SRC,0x40
b507f4
+ addi   DST,DST,0x40
b507f4
+
b507f4
+ clrldi LENGTH,LENGTH,62
b507f4
+
b507f4
+L2x:
b507f4
+ srdi  5,LENGTH,1
b507f4
+ cmpldi  5,0
b507f4
+ beq   L1x
b507f4
+
b507f4
+ lxvd2x VSR(K),0,KEYS
b507f4
+ vperm K,K,K,swap_mask
b507f4
+
b507f4
+ lxvd2x VSR(S0),0,SRC
b507f4
+ li   9,0x10
b507f4
+ lxvd2x VSR(S1),9,SRC
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask>)
b507f4
+
b507f4
+ vxor  S0,S0,K
b507f4
+ vxor   S1,S1,K
b507f4
+
b507f4
+ mtctr   ROUNDS
b507f4
+ li  10,0x10
b507f4
+.align 5
b507f4
+L2x_round_loop:
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vncipher S0,S0,ZERO
b507f4
+ vncipher S1,S1,ZERO
b507f4
+ vxor  S0,S0,K
b507f4
+ vxor  S1,S1,K
b507f4
+ addi   10,10,0x10
b507f4
+ bdnz   L2x_round_loop
b507f4
+
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vncipherlast S0,S0,K
b507f4
+ vncipherlast S1,S1,K
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask>)
b507f4
+
b507f4
+ stxvd2x VSR(S0),0,DST
b507f4
+ li  9,0x10
b507f4
+ stxvd2x VSR(S1),9,DST
b507f4
+
b507f4
+ addi   SRC,SRC,0x20
b507f4
+ addi   DST,DST,0x20
b507f4
+
b507f4
+ clrldi LENGTH,LENGTH,63
b507f4
+
b507f4
+L1x:
b507f4
+ cmpldi LENGTH,0
b507f4
+ beq   Ldone
b507f4
+
b507f4
+ lxvd2x VSR(K),0,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+
b507f4
+ lxvd2x VSR(S0),0,SRC
b507f4
+
b507f4
+IF_LE(<vperm S0,S0,S0,swap_mask>)
b507f4
+
b507f4
+ vxor   S0,S0,K
b507f4
+
b507f4
+ mtctr   ROUNDS
b507f4
+ li   10,0x10
b507f4
+.align 5
b507f4
+L1x_round_loop:
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vncipher S0,S0,ZERO
b507f4
+ vxor   S0,S0,K
b507f4
+ addi   10,10,0x10
b507f4
+ bdnz   L1x_round_loop
b507f4
+
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vncipherlast S0,S0,K
b507f4
+
b507f4
+IF_LE(<vperm S0,S0,S0,swap_mask>)
b507f4
+
b507f4
+ stxvd2x VSR(S0),0,DST
b507f4
+
b507f4
+Ldone:
b507f4
+ blr
b507f4
+EPILOGUE(_nettle_aes_decrypt)
b507f4
+
b507f4
+ .data
b507f4
+ .align 4
b507f4
+.swap_mask:
b507f4
+IF_LE(<.byte 8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7>)
b507f4
+IF_BE(<.byte 3,2,1,0,7,6,5,4,11,10,9,8,15,14,13,12>)
b507f4
diff --git a/powerpc64/p8/aes-encrypt-internal.asm b/powerpc64/p8/aes-encrypt-internal.asm
b507f4
new file mode 100644
b507f4
index 00000000..67c7e597
b507f4
--- /dev/null
b507f4
+++ b/powerpc64/p8/aes-encrypt-internal.asm
b507f4
@@ -0,0 +1,333 @@
b507f4
+C powerpc64/p8/aes-encrypt-internal.asm
b507f4
+
b507f4
+ifelse(<
b507f4
+   Copyright (C) 2020 Mamone Tarsha
b507f4
+   This file is part of GNU Nettle.
b507f4
+
b507f4
+   GNU Nettle is free software: you can redistribute it and/or
b507f4
+   modify it under the terms of either:
b507f4
+
b507f4
+     * the GNU Lesser General Public License as published by the Free
b507f4
+       Software Foundation; either version 3 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or
b507f4
+
b507f4
+     * the GNU General Public License as published by the Free
b507f4
+       Software Foundation; either version 2 of the License, or (at your
b507f4
+       option) any later version.
b507f4
+
b507f4
+   or both in parallel, as here.
b507f4
+
b507f4
+   GNU Nettle is distributed in the hope that it will be useful,
b507f4
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b507f4
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b507f4
+   General Public License for more details.
b507f4
+
b507f4
+   You should have received copies of the GNU General Public License and
b507f4
+   the GNU Lesser General Public License along with this program.  If
b507f4
+   not, see http://www.gnu.org/licenses/.
b507f4
+>)
b507f4
+
b507f4
+C Register usage:
b507f4
+
b507f4
+define(<SP>, <1>)
b507f4
+define(<TOCP>, <2>)
b507f4
+
b507f4
+define(<ROUNDS>, <3>)
b507f4
+define(<KEYS>, <4>)
b507f4
+define(<LENGTH>, <6>)
b507f4
+define(<DST>, <7>)
b507f4
+define(<SRC>, <8>)
b507f4
+
b507f4
+define(<swap_mask>, <0>)
b507f4
+
b507f4
+define(<K>, <1>)
b507f4
+define(<S0>, <2>)
b507f4
+define(<S1>, <3>)
b507f4
+define(<S2>, <4>)
b507f4
+define(<S3>, <5>)
b507f4
+define(<S4>, <6>)
b507f4
+define(<S5>, <7>)
b507f4
+define(<S6>, <8>)
b507f4
+define(<S7>, <9>)
b507f4
+
b507f4
+.file "aes-encrypt-internal.asm"
b507f4
+
b507f4
+.text
b507f4
+
b507f4
+ C _aes_encrypt(unsigned rounds, const uint32_t *keys,
b507f4
+ C       const struct aes_table *T,
b507f4
+ C       size_t length, uint8_t *dst,
b507f4
+ C       uint8_t *src)
b507f4
+
b507f4
+define(<FUNC_ALIGN>, <5>)
b507f4
+PROLOGUE(_nettle_aes_encrypt)
b507f4
+ DATA_LOAD_VEC(swap_mask,.swap_mask,5)
b507f4
+
b507f4
+ subi ROUNDS,ROUNDS,1
b507f4
+ srdi LENGTH,LENGTH,4
b507f4
+
b507f4
+ srdi 5,LENGTH,3 #8x loop count
b507f4
+ cmpldi 5,0
b507f4
+ beq L4x
b507f4
+
b507f4
+ std 25,-56(SP);
b507f4
+ std 26,-48(SP);
b507f4
+ std 27,-40(SP);
b507f4
+ std 28,-32(SP);
b507f4
+ std 29,-24(SP);
b507f4
+ std 30,-16(SP);
b507f4
+ std 31,-8(SP);
b507f4
+
b507f4
+ li 25,0x10
b507f4
+ li 26,0x20
b507f4
+ li 27,0x30
b507f4
+ li 28,0x40
b507f4
+ li 29,0x50
b507f4
+ li 30,0x60
b507f4
+ li 31,0x70
b507f4
+
b507f4
+.align 5
b507f4
+Lx8_loop:
b507f4
+ lxvd2x VSR(K),0,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+
b507f4
+ lxvd2x VSR(S0),0,SRC
b507f4
+ lxvd2x VSR(S1),25,SRC
b507f4
+ lxvd2x VSR(S2),26,SRC
b507f4
+ lxvd2x VSR(S3),27,SRC
b507f4
+ lxvd2x VSR(S4),28,SRC
b507f4
+ lxvd2x VSR(S5),29,SRC
b507f4
+ lxvd2x VSR(S6),30,SRC
b507f4
+ lxvd2x VSR(S7),31,SRC
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask
b507f4
+ vperm S2,S2,S2,swap_mask
b507f4
+ vperm S3,S3,S3,swap_mask
b507f4
+ vperm S4,S4,S4,swap_mask
b507f4
+ vperm S5,S5,S5,swap_mask
b507f4
+ vperm S6,S6,S6,swap_mask
b507f4
+ vperm S7,S7,S7,swap_mask>)
b507f4
+
b507f4
+ vxor S0,S0,K
b507f4
+ vxor S1,S1,K
b507f4
+ vxor S2,S2,K
b507f4
+ vxor S3,S3,K
b507f4
+ vxor S4,S4,K
b507f4
+ vxor S5,S5,K
b507f4
+ vxor S6,S6,K
b507f4
+ vxor S7,S7,K
b507f4
+
b507f4
+ mtctr ROUNDS
b507f4
+ li 10,0x10
b507f4
+.align 5
b507f4
+L8x_round_loop:
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+ vcipher S0,S0,K
b507f4
+ vcipher S1,S1,K
b507f4
+ vcipher S2,S2,K
b507f4
+ vcipher S3,S3,K
b507f4
+ vcipher S4,S4,K
b507f4
+ vcipher S5,S5,K
b507f4
+ vcipher S6,S6,K
b507f4
+ vcipher S7,S7,K
b507f4
+ addi 10,10,0x10
b507f4
+ bdnz L8x_round_loop
b507f4
+
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+ vcipherlast S0,S0,K
b507f4
+ vcipherlast S1,S1,K
b507f4
+ vcipherlast S2,S2,K
b507f4
+ vcipherlast S3,S3,K
b507f4
+ vcipherlast S4,S4,K
b507f4
+ vcipherlast S5,S5,K
b507f4
+ vcipherlast S6,S6,K
b507f4
+ vcipherlast S7,S7,K
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask
b507f4
+ vperm S2,S2,S2,swap_mask
b507f4
+ vperm S3,S3,S3,swap_mask
b507f4
+ vperm S4,S4,S4,swap_mask
b507f4
+ vperm S5,S5,S5,swap_mask
b507f4
+ vperm S6,S6,S6,swap_mask
b507f4
+ vperm S7,S7,S7,swap_mask>)
b507f4
+
b507f4
+ stxvd2x VSR(S0),0,DST
b507f4
+ stxvd2x VSR(S1),25,DST
b507f4
+ stxvd2x VSR(S2),26,DST
b507f4
+ stxvd2x VSR(S3),27,DST
b507f4
+ stxvd2x VSR(S4),28,DST
b507f4
+ stxvd2x VSR(S5),29,DST
b507f4
+ stxvd2x VSR(S6),30,DST
b507f4
+ stxvd2x VSR(S7),31,DST
b507f4
+
b507f4
+ addi SRC,SRC,0x80
b507f4
+ addi DST,DST,0x80
b507f4
+ subic. 5,5,1
b507f4
+ bne Lx8_loop
b507f4
+
b507f4
+ ld 25,-56(SP);
b507f4
+ ld 26,-48(SP);
b507f4
+ ld 27,-40(SP);
b507f4
+ ld 28,-32(SP);
b507f4
+ ld 29,-24(SP);
b507f4
+ ld 30,-16(SP);
b507f4
+ ld 31,-8(SP);
b507f4
+
b507f4
+ clrldi LENGTH,LENGTH,61
b507f4
+
b507f4
+L4x:
b507f4
+ srdi   5,LENGTH,2
b507f4
+ cmpldi   5,0
b507f4
+ beq   L2x
b507f4
+
b507f4
+ lxvd2x   VSR(K),0,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+
b507f4
+ lxvd2x VSR(S0),0,SRC
b507f4
+ li  9,0x10
b507f4
+ lxvd2x VSR(S1),9,SRC
b507f4
+ addi   9,9,0x10
b507f4
+ lxvd2x VSR(S2),9,SRC
b507f4
+ addi   9,9,0x10
b507f4
+ lxvd2x VSR(S3),9,SRC
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask
b507f4
+ vperm S2,S2,S2,swap_mask
b507f4
+ vperm S3,S3,S3,swap_mask>)
b507f4
+
b507f4
+ vxor S0,S0,K
b507f4
+ vxor S1,S1,K
b507f4
+ vxor S2,S2,K
b507f4
+ vxor S3,S3,K
b507f4
+
b507f4
+ mtctr ROUNDS
b507f4
+ li 10,0x10
b507f4
+.align 5
b507f4
+L4x_round_loop:
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vcipher S0,S0,K
b507f4
+ vcipher S1,S1,K
b507f4
+ vcipher S2,S2,K
b507f4
+ vcipher S3,S3,K
b507f4
+ addi   10,10,0x10
b507f4
+ bdnz  L4x_round_loop
b507f4
+
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+ vcipherlast S0,S0,K
b507f4
+ vcipherlast S1,S1,K
b507f4
+ vcipherlast S2,S2,K
b507f4
+ vcipherlast S3,S3,K
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask
b507f4
+ vperm S2,S2,S2,swap_mask
b507f4
+ vperm S3,S3,S3,swap_mask>)
b507f4
+
b507f4
+ stxvd2x VSR(S0),0,DST
b507f4
+ li  9,0x10
b507f4
+ stxvd2x VSR(S1),9,DST
b507f4
+ addi   9,9,0x10
b507f4
+ stxvd2x VSR(S2),9,DST
b507f4
+ addi  9,9,0x10
b507f4
+ stxvd2x VSR(S3),9,DST
b507f4
+
b507f4
+ addi   SRC,SRC,0x40
b507f4
+ addi   DST,DST,0x40
b507f4
+
b507f4
+ clrldi LENGTH,LENGTH,62
b507f4
+
b507f4
+L2x:
b507f4
+ srdi  5,LENGTH,1
b507f4
+ cmpldi  5,0
b507f4
+ beq   L1x
b507f4
+
b507f4
+ lxvd2x VSR(K),0,KEYS
b507f4
+ vperm K,K,K,swap_mask
b507f4
+
b507f4
+ lxvd2x VSR(S0),0,SRC
b507f4
+ li   9,0x10
b507f4
+ lxvd2x VSR(S1),9,SRC
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask>)
b507f4
+
b507f4
+ vxor  S0,S0,K
b507f4
+ vxor   S1,S1,K
b507f4
+
b507f4
+ mtctr   ROUNDS
b507f4
+ li  10,0x10
b507f4
+.align 5
b507f4
+L2x_round_loop:
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vcipher S0,S0,K
b507f4
+ vcipher S1,S1,K
b507f4
+ addi   10,10,0x10
b507f4
+ bdnz   L2x_round_loop
b507f4
+
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vcipherlast S0,S0,K
b507f4
+ vcipherlast S1,S1,K
b507f4
+
b507f4
+IF_LE(
b507f4
+ vperm S1,S1,S1,swap_mask>)
b507f4
+
b507f4
+ stxvd2x VSR(S0),0,DST
b507f4
+ li  9,0x10
b507f4
+ stxvd2x VSR(S1),9,DST
b507f4
+
b507f4
+ addi   SRC,SRC,0x20
b507f4
+ addi   DST,DST,0x20
b507f4
+
b507f4
+ clrldi LENGTH,LENGTH,63
b507f4
+
b507f4
+L1x:
b507f4
+ cmpldi LENGTH,0
b507f4
+ beq   Ldone
b507f4
+
b507f4
+ lxvd2x VSR(K),0,KEYS
b507f4
+ vperm   K,K,K,swap_mask
b507f4
+
b507f4
+ lxvd2x VSR(S0),0,SRC
b507f4
+
b507f4
+IF_LE(<vperm S0,S0,S0,swap_mask>)
b507f4
+
b507f4
+ vxor   S0,S0,K
b507f4
+
b507f4
+ mtctr   ROUNDS
b507f4
+ li   10,0x10
b507f4
+.align 5
b507f4
+L1x_round_loop:
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vcipher S0,S0,K
b507f4
+ addi   10,10,0x10
b507f4
+ bdnz   L1x_round_loop
b507f4
+
b507f4
+ lxvd2x VSR(K),10,KEYS
b507f4
+ vperm  K,K,K,swap_mask
b507f4
+ vcipherlast S0,S0,K
b507f4
+
b507f4
+IF_LE(<vperm S0,S0,S0,swap_mask>)
b507f4
+
b507f4
+ stxvd2x VSR(S0),0,DST
b507f4
+
b507f4
+Ldone:
b507f4
+ blr
b507f4
+EPILOGUE(_nettle_aes_encrypt)
b507f4
+
b507f4
+ .data
b507f4
+ .align 4
b507f4
+.swap_mask:
b507f4
+IF_LE(<.byte 8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7>)
b507f4
+IF_BE(<.byte 3,2,1,0,7,6,5,4,11,10,9,8,15,14,13,12>)