+2020-11-07 Niels Möller <nisse@lysator.liu.se>
+
+ * configure.ac: New command line option --enable-power-altivec.
+ Update asm_path logic, and add altivec to FAT_TEST_LIST.
+ * fat-ppc.c (get_ppc_features): Add logic to check for altivec and
+ vsx support, and select aither C or altivec implementation of
+ chacha_core.
+ * powerpc64/fat/chacha-core-internal-2.asm: New file.
+
2020-09-25 Niels Möller <nisse@lysator.liu.se>
* powerpc64/p7/chacha-core-internal.asm: New file.
AC_HELP_STRING([--enable-power-crypto-ext], [Enable POWER crypto extensions. (default=no)]),,
[enable_power_crypto_ext=no])
+AC_ARG_ENABLE(power-altivec,
+ AC_HELP_STRING([--enable-power-altivec], [Enable POWER altivec and vsx extensions. (default=no)]),,
+ [enable_altivec=no])
+
AC_ARG_ENABLE(mini-gmp,
AC_HELP_STRING([--enable-mini-gmp], [Enable mini-gmp, used instead of libgmp.]),,
[enable_mini_gmp=no])
*powerpc64*)
if test "$ABI" = 64 ; then
GMP_ASM_POWERPC_R_REGISTERS
- asm_path="powerpc64/p7 powerpc64"
+ asm_path="powerpc64"
if test "x$enable_fat" = xyes ; then
asm_path="powerpc64/fat $asm_path"
OPT_NETTLE_SOURCES="fat-ppc.c $OPT_NETTLE_SOURCES"
- FAT_TEST_LIST="none crypto_ext"
- elif test "x$enable_power_crypto_ext" = xyes ; then
- asm_path="powerpc64/p8 $asm_path"
+ FAT_TEST_LIST="none crypto_ext altivec"
+ else
+ if test "$enable_power_crypto_ext" = yes ; then
+ asm_path="powerpc64/p8 $asm_path"
+ fi
+ if test "$enable_power_altivec" = yes ; then
+ asm_path="powerpc64/p7 $asm_path"
+ fi
fi
fi
;;
struct ppc_features
{
int have_crypto_ext;
+ int have_altivec;
};
#define MATCH(s, slen, literal, llen) \
{
const char *s;
features->have_crypto_ext = 0;
+ features->have_altivec = 0;
s = secure_getenv (ENV_OVERRIDE);
if (s)
if (MATCH (s, length, "crypto_ext", 10))
features->have_crypto_ext = 1;
+ else if (MATCH(s, length, "altivec", 7))
+ features->have_altivec = 1;
if (!sep)
break;
s = sep + 1;
#if defined(_AIX) && defined(__power_8_andup)
features->have_crypto_ext = __power_8_andup() != 0 ? 1 : 0;
#else
+ unsigned long hwcap = 0;
unsigned long hwcap2 = 0;
# if defined(__linux__)
+ hwcap = getauxval(AT_HWCAP);
hwcap2 = getauxval(AT_HWCAP2);
# elif defined(__FreeBSD__)
# if __FreeBSD__ >= 12
sysctlbyname("hw.cpu_features2", &hwcap2, &len, NULL, 0);
# endif
# endif
- features->have_crypto_ext =
- (hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO ? 1 : 0;
+ features->have_crypto_ext
+ = ((hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO);
+
+ /* We also need VSX instructions, mainly for load and store. */
+ features->have_altivec
+ = ((hwcap & (PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_VSX))
+ == (PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_VSX));
#endif
}
}
DECLARE_FAT_FUNC_VAR(aes_decrypt, aes_crypt_internal_func, c)
DECLARE_FAT_FUNC_VAR(aes_decrypt, aes_crypt_internal_func, ppc64)
+DECLARE_FAT_FUNC(_nettle_chacha_core, chacha_core_func)
+DECLARE_FAT_FUNC_VAR(chacha_core, chacha_core_func, c);
+DECLARE_FAT_FUNC_VAR(chacha_core, chacha_core_func, altivec);
+
static void CONSTRUCTOR
fat_init (void)
{
_nettle_aes_encrypt_vec = _nettle_aes_encrypt_c;
_nettle_aes_decrypt_vec = _nettle_aes_decrypt_c;
}
+ if (features.have_altivec)
+ {
+ if (verbose)
+ fprintf (stderr, "libnettle: enabling altivec code.\n");
+ _nettle_chacha_core_vec = _nettle_chacha_core_altivec;
+ }
+ else
+ {
+ _nettle_chacha_core_vec = _nettle_chacha_core_c;
+ }
}
DEFINE_FAT_FUNC(_nettle_aes_encrypt, void,
size_t length, uint8_t *dst,
const uint8_t *src),
(rounds, keys, T, length, dst, src))
+
+DEFINE_FAT_FUNC(_nettle_chacha_core, void,
+ (uint32_t *dst, const uint32_t *src, unsigned rounds),
+ (dst, src, rounds))
--- /dev/null
+C powerpc64/fat/chacha-core-internal-2.asm
+
+
+ifelse(`
+ Copyright (C) 2020 Niels Möller
+
+ This file is part of GNU Nettle.
+
+ GNU Nettle is free software: you can redistribute it and/or
+ modify it under the terms of either:
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ or both in parallel, as here.
+
+ GNU Nettle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see http://www.gnu.org/licenses/.
+')
+
+dnl PROLOGUE(_nettle_chacha_core) picked up by configure
+
+define(`fat_transform', `$1_altivec')
+include_src(`powerpc64/p7/chacha-core-internal.asm')