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

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