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

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