Add PowerPC chacha20 implementation from openssl/cryptograms
PATCH 1/1 Add PowerPC chacha20 implementation from openssl/cryptograms
There is a bug where may_use_simd()
returns false in kworker, and prevents most of this code from running.
Otherwise this is tested (with the VSX code enabled) on Power 9 (ppc64le). It is quite a bit faster (look at the benchmarks in the assembly file) but it is difficult to give numbers because the interface line speed is the limiting factor.
Signed-off-by Shawn Landden <[email protected]>
--- src/compat/simd/include/linux/simd.h | 18 +- src/crypto/Kbuild.include | 26 +- src/crypto/zinc/chacha20/chacha20-ppc-glue.c | 67 + src/crypto/zinc/chacha20/chacha20-ppc.pl | 1355 ++++++++++++++++++ src/crypto/zinc/chacha20/chacha20.c | 2 + src/crypto/zinc/chacha20/ppc-xlate.pl | 353 +++++ 6 files changed, 1818 insertions(+), 3 deletions(-) create mode 100644 src/crypto/zinc/chacha20/chacha20-ppc-glue.c create mode 100644 src/crypto/zinc/chacha20/chacha20-ppc.pl create mode 100644 src/crypto/zinc/chacha20/ppc-xlate.pl
src/compat/simd/include/linux/simd.h +16 -2
@@ -11,10 +11,12 @@#if defined(CONFIG_X86_64 )#include <linux/version.h> #include <asm/fpu/api.h> #elif defined(CONFIG_KERNEL_MODE_NEON )#include <asm/neon.h> +#elif defined(CONFIG_ALTIVEC ) || defined(CONFIG_VSX ) +#include <asm/switch_to.h> #endif typedef enum { HAVE_NO_SIMD = 1 << 0, HAVE_FULL_SIMD = 1 << 1,
@@ -28,17 +30,23 @@ static inline void simd_get(simd_context_t *ctx) *ctx = !IS_ENABLED (CONFIG_PREEMPT_RT_BASE ) &&may_use_simd () ?HAVE_FULL_SIMD :HAVE_NO_SIMD ; }static inline void simd_put (simd_context_t *ctx) { +if (*ctx &HAVE_SIMD_IN_USE ) {#if defined(CONFIG_X86_64 ) -if (*ctx &HAVE_SIMD_IN_USE )kernel_fpu_end ();#elif defined(CONFIG_KERNEL_MODE_NEON ) -if (*ctx &HAVE_SIMD_IN_USE )kernel_neon_end (); +#elif defined(CONFIG_VSX ) +disable_kernel_vsx (); +preempt_enable (); +#elif defined(CONFIG_ALTIVEC ) +disable_kernel_altivec (); +preempt_enable ();#endif + } *ctx =HAVE_NO_SIMD ; }static inline bool simd_relax (simd_context_t *ctx) {
@@ -60,10 +68,16 @@ static __must_check inline bool simd_use(simd_context_t *ctx)return true;#if defined(CONFIG_X86_64 )kernel_fpu_begin ();#elif defined(CONFIG_KERNEL_MODE_NEON )kernel_neon_begin (); +#elif defined(CONFIG_VSX ) +preempt_disable (); +enable_kernel_vsx (); +#elif defined(CONFIG_ALTIVEC ) +preempt_disable (); +enable_kernel_altivec ();#endif *ctx |=HAVE_SIMD_IN_USE ;return true; }
src/crypto/Kbuild.include +25 -1
@@ -11,17 +11,25 @@ ifeq ($(CONFIG_MIPS)$(CONFIG_CPU_MIPS32_R2),yy) CONFIG_ZINC_ARCH_MIPS := y endif ifeq ($(CONFIG_MIPS)$(CONFIG_64BIT),yy) CONFIG_ZINC_ARCH_MIPS64 := y endif +ifeq ($(CONFIG_PPC32),y) +CONFIG_ZINC_ARCH_PPC32 := y +endif +ifeq ($(CONFIG_PPC64),y) +CONFIG_ZINC_ARCH_PPC64 := y +endif zinc-y += chacha20/chacha20.o zinc-$(CONFIG_ZINC_ARCH_X86_64) += chacha20/chacha20-x86_64.o zinc-$(CONFIG_ZINC_ARCH_ARM) += chacha20/chacha20-arm.o chacha20/chacha20-unrolled-arm.o zinc-$(CONFIG_ZINC_ARCH_ARM64) += chacha20/chacha20-arm64.o zinc-$(CONFIG_ZINC_ARCH_MIPS) += chacha20/chacha20-mips.o AFLAGS_chacha20-mips.o += -O2 # This is required to fill the branch delay slots +zinc-$(CONFIG_ZINC_ARCH_PPC32) += chacha20/chacha20-ppc.o +zinc-$(CONFIG_ZINC_ARCH_PPC64) += chacha20/chacha20-ppc.o zinc-y += poly1305/poly1305.o zinc-$(CONFIG_ZINC_ARCH_X86_64) += poly1305/poly1305-x86_64.o zinc-$(CONFIG_ZINC_ARCH_ARM) += poly1305/poly1305-arm.o zinc-$(CONFIG_ZINC_ARCH_ARM64) += poly1305/poly1305-arm64.o
@@ -36,22 +44,38 @@ zinc-$(CONFIG_ZINC_ARCH_X86_64) += blake2s/blake2s-x86_64.o zinc-y += curve25519/curve25519.o zinc-$(CONFIG_ZINC_ARCH_ARM) += curve25519/curve25519-arm.o quiet_cmd_perlasm = PERLASM $@ - cmd_perlasm = $(PERL) $< > $@ + cmd_perlasm = $(PERL) $< $(perlflags-y) > $@ $(obj)/%.S: $(src)/%.pl FORCE $(call if_changed,perlasm) kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) targets := $(patsubst $(kbuild-dir)/%.pl,%.S,$(wildcard $(patsubst %.o,$(kbuild-dir)/crypto/zinc/%.pl,$(zinc-y) $(zinc-m) $(zinc-)))) +perlflags-$(CONFIG_ZINC_ARCH_PPC32) += linux32 +ifeq ($(CONFIG_ZINC_ARCH_PPC64),y) +perlflags-$(CONFIG_CPU_BIG_ENDIAN) += linux64 +perlflags-$(CONFIG_CPU_LITTLE_ENDIAN) += linux64le +endif + # Old kernels don't set this, which causes trouble. .SECONDARY: wireguard-y += $(addprefix crypto/zinc/,$(zinc-y)) ccflags-y += -I$(src)/crypto/include ccflags-$(CONFIG_ZINC_ARCH_X86_64) += -DCONFIG_ZINC_ARCH_X86_64 ccflags-$(CONFIG_ZINC_ARCH_ARM) += -DCONFIG_ZINC_ARCH_ARM ccflags-$(CONFIG_ZINC_ARCH_ARM64) += -DCONFIG_ZINC_ARCH_ARM64 ccflags-$(CONFIG_ZINC_ARCH_MIPS) += -DCONFIG_ZINC_ARCH_MIPS ccflags-$(CONFIG_ZINC_ARCH_MIPS64) += -DCONFIG_ZINC_ARCH_MIPS64 +ccflags-$(CONFIG_ZINC_ARCH_PPC32) += -DCONFIG_ZINC_ARCH_PPC32 +ccflags-$(CONFIG_ZINC_ARCH_PPC64) += -DCONFIG_ZINC_ARCH_PPC64 +ifdef ($(CONFIG_VSX),y) +ccflags-$(CONFIG_ZINC_ARCH_PPC32) += -DCONFIG_VSX +ccflags-$(CONFIG_ZINC_ARCH_PPC64) += -DCONFIG_VSX +endif +ifdef ($(CONFIG_ALTIVEC),y) +ccflags-$(CONFIG_ZINC_ARCH_PPC32) += -DCONFIG_ALTIVEC +ccflags-$(CONFIG_ZINC_ARCH_PPC64) += -DCONFIG_ALTIVEC +endif ccflags-$(CONFIG_WIREGUARD_DEBUG) += -DCONFIG_ZINC_SELFTEST
src/crypto/zinc/chacha20/chacha20-ppc-glue.c new file +67 -0
67 lines not on this page · raw message
src/crypto/zinc/chacha20/chacha20-ppc.pl new file +1355 -0
1,355 lines not on this page · raw message
src/crypto/zinc/chacha20/chacha20.c +2 -0
@@ -20,10 +20,12 @@#include "chacha20-x86_64-glue.c" #elif defined(CONFIG_ZINC_ARCH_ARM ) || defined(CONFIG_ZINC_ARCH_ARM64 )#include "chacha20-arm-glue.c" #elif defined(CONFIG_ZINC_ARCH_MIPS )#include "chacha20-mips-glue.c" +#elif defined(CONFIG_ZINC_ARCH_PPC32 ) || defined(CONFIG_ZINC_ARCH_PPC64 ) +#include "chacha20-ppc-glue.c" #else static bool *const chacha20_nobs[]__initconst = { };static void __init chacha20_fpu_init (void ) { }
src/crypto/zinc/chacha20/ppc-xlate.pl new file +353 -0
353 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ WireGuard mailing list [email protected] https://lists.zx2c4.com/mailman/listinfo/wireguard