Implement GCM ghash using Zbc and Zbkb extensions
Subsystems (2)
v6 cover Implement GCM ghash using Zbc and Zbkb extensions
From: Heiko Stuebner <[email protected]>
This was originally part of my vector crypto series, but was part of a separate openssl merge request implementing GCM ghash as using non-vector extensions.
As that pull-request
https://github.com/openssl/openssl/pull/20078
got merged recently into openssl, we could also check if this could go into the kernel as well and provide a base for further accelerated cryptographic support.
changes in v6:
- rebase on top of riscv/for-next
- rebase on top of Samuel Ortiz Arch-random series
https://lore.kernel.org/r/[email protected]
as it has the nicer Zbc + Zbkb integration for extensions and hwprobe
- update perl code with better licensing text (Eric)
This was also merged into the original openSSL sources
- add SPDX license identifier (Eric)
- drop unneeded fallback element in the private struct (Herbert)
Changes in v5:
- rebased on top of 6.4-based riscv/next
- code from openssl is now dual-licensed under Apache + BSD see https://github.com/openssl/openssl/pull/20649
- separate init functions instead of creating them with macros (Nathan)
Changes in v4:
- rebase on top of riscv/for-next
- split out the scalar crypto implementation from the vector series
- refresh code from openSSL to match exactly
- Remove RFC label, as Zbc and Zbkb are ratified and
the cryptographic code was merged into openSSL
changes in v3:
- rebase on top of 6.3-rc2
- rebase on top of vector-v14 patchset
- add the missing Co-developed-by mentions to showcase the people that did the actual openSSL crypto code
changes in v2:
- rebased on 6.2 + zbb series, so don't include already applied changes anymore
- refresh code picked from openssl as that side matures
- more algorithms (SHA512, AES, SM3, SM4)
Heiko Stuebner (3):
RISC-V: expose Zbc as Kconfig option
RISC-V: hook new crypto subdir into build-system
RISC-V: crypto: add accelerated GCM GHASH implementation
arch/riscv/Kbuild | 1 + arch/riscv/Kconfig | 23 ++ arch/riscv/crypto/Kconfig | 18 ++ arch/riscv/crypto/Makefile | 18 ++ arch/riscv/crypto/ghash-riscv64-glue.c | 291 +++++++++++++++++ arch/riscv/crypto/ghash-riscv64-zbc.pl | 430 +++++++++++++++++++++++++ arch/riscv/crypto/riscv.pm | 261 +++++++++++++++ crypto/Kconfig | 3 + 8 files changed, 1045 insertions(+) create mode 100644 arch/riscv/crypto/Kconfig create mode 100644 arch/riscv/crypto/Makefile create mode 100644 arch/riscv/crypto/ghash-riscv64-glue.c create mode 100644 arch/riscv/crypto/ghash-riscv64-zbc.pl create mode 100644 arch/riscv/crypto/riscv.pm
Signature · 1 line
2.39.2
PATCH v6 1/3 RISC-V: expose Zbc as Kconfig option
From: Heiko Stuebner <[email protected]>
Similar to Zbb add a Zbc option to allow making further functionality depend on it.
--- arch/riscv/Kconfig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
arch/riscv/Kconfig +23 -0
@@ -531,6 +531,29 @@ config RISCV_ISA_ZBB If you don't know what to do here, say Y. +config TOOLCHAIN_HAS_ZBC + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbc) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbc) + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBC + bool "Zbc extension support for bit manipulation instructions" + depends on TOOLCHAIN_HAS_ZBC + depends on MMU + depends on RISCV_ALTERNATIVE + default y + help + Adds support to dynamically detect the presence of the ZBC + extension (carry-less multiplication) and enable its usage. + + The Zbc extension provides instructions clmul, clmulh and clmulr + to accelerate carry-less multiplications. + + If you don't know what to do here, say Y. + config RISCV_ISA_ZICBOM bool "Zicbom extension support for non-coherent DMA operation" depends on MMU
Signature · 1 line
2.39.2
PATCH v6 2/3 RISC-V: hook new crypto subdir into build-system
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
Create a crypto subdirectory for added accelerated cryptography routines and hook it into the riscv Kbuild and the main crypto Kconfig.
--- arch/riscv/Kbuild | 1 + arch/riscv/crypto/Kconfig | 5 +++++ arch/riscv/crypto/Makefile | 4 ++++ crypto/Kconfig | 3 +++ 4 files changed, 13 insertions(+) create mode 100644 arch/riscv/crypto/Kconfig create mode 100644 arch/riscv/crypto/Makefile
arch/riscv/Kbuild +1 -0
@@ -2,6 +2,7 @@ obj-y += kernel/ mm/ net/ obj-$(CONFIG_BUILTIN_DTB) += boot/dts/ +obj-$(CONFIG_CRYPTO) += crypto/ obj-y += errata/ obj-$(CONFIG_KVM) += kvm/
arch/riscv/crypto/Kconfig new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +menu "Accelerated Cryptographic Algorithms for CPU (riscv)" + +endmenu
arch/riscv/crypto/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# linux/arch/riscv/crypto/Makefile +#
crypto/Kconfig +3 -0
@@ -1436,6 +1436,9 @@ endif if PPC source "arch/powerpc/crypto/Kconfig" endif +if RISCV +source "arch/riscv/crypto/Kconfig" +endif if S390 source "arch/s390/crypto/Kconfig" endif
Signature · 1 line
2.39.2
PATCH v6 3/3 RISC-V: crypto: add accelerated GCM GHASH implementation
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
With different sets of available extensions a number of different implementation variants are possible. Quite a number of them are already implemented in openSSL or are in the process of being implemented, so pick the relevant openSSL coden and add suitable glue code similar to arm64 and powerpc to use it for kernel-specific cryptography.
The prioritization of the algorithms follows the ifdef chain for the assembly callbacks done in openssl but here algorithms will get registered separately so that all of them can be part of the crypto selftests.
The crypto subsystem will select the most performant of all registered algorithms on the running system but will selftest all registered ones.
In a first step this adds scalar variants using the Zbc, Zbb and possible Zbkb (bitmanip crypto extension) and the perl implementation stems from openSSL pull request on
https://github.com/openssl/openssl/pull/20078
--- arch/riscv/crypto/Kconfig | 13 + arch/riscv/crypto/Makefile | 14 + arch/riscv/crypto/ghash-riscv64-glue.c | 291 +++++++++++++++++ arch/riscv/crypto/ghash-riscv64-zbc.pl | 430 +++++++++++++++++++++++++ arch/riscv/crypto/riscv.pm | 261 +++++++++++++++ 5 files changed, 1009 insertions(+) create mode 100644 arch/riscv/crypto/ghash-riscv64-glue.c create mode 100644 arch/riscv/crypto/ghash-riscv64-zbc.pl create mode 100644 arch/riscv/crypto/riscv.pm
arch/riscv/crypto/Kconfig +13 -0
@@ -2,4 +2,17 @@ menu "Accelerated Cryptographic Algorithms for CPU (riscv)" +config CRYPTO_GHASH_RISCV64 + tristate "Hash functions: GHASH" + depends on 64BIT && RISCV_ISA_ZBC + select CRYPTO_HASH + select CRYPTO_LIB_GF128MUL + help + GCM GHASH function (NIST SP800-38D) + + Architecture: riscv64 using one of: + - Zbc extension + - Zbc + Zbb extensions + - Zbc + Zbkb extensions + endmenu
arch/riscv/crypto/Makefile +14 -0
@@ -2,3 +2,17 @@ # # linux/arch/riscv/crypto/Makefile # + +obj-$(CONFIG_CRYPTO_GHASH_RISCV64) += ghash-riscv64.o +ghash-riscv64-y := ghash-riscv64-glue.o +ifdef CONFIG_RISCV_ISA_ZBC +ghash-riscv64-y += ghash-riscv64-zbc.o +endif + +quiet_cmd_perlasm = PERLASM $@ + cmd_perlasm = $(PERL) $(<) void $(@) + +$(obj)/ghash-riscv64-zbc.S: $(src)/ghash-riscv64-zbc.pl + $(call cmd,perlasm) + +clean-files += ghash-riscv64-zbc.S
arch/riscv/crypto/ghash-riscv64-glue.c new file +291 -0
291 lines not on this page · raw message
arch/riscv/crypto/ghash-riscv64-zbc.pl new file +430 -0
430 lines not on this page · raw message
arch/riscv/crypto/riscv.pm new file +261 -0
261 lines not on this page · raw message
Signature · 7 lines
2.39.2 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv