Architecture-optimized SHA-256 library API
Subsystems (16)
Herbert Xu
maintainerv3 cover Architecture-optimized SHA-256 library API
Changes in v3:
- Add shash sha256-lib/sha224-lib to provide test coverage for libsha256.
This is based on
https://patchwork.kernel.org/project/linux-crypto/list/?series=957558
Original description:
Following the example of several other algorithms (e.g. CRC32, ChaCha, Poly1305, BLAKE2s), this series refactors the kernel's existing architecture-optimized SHA-256 code to be available via the library API, instead of just via the crypto_shash API as it was before. It also reimplements the SHA-256 crypto_shash API on top of the library API.
This makes it possible to use the SHA-256 library in performance-critical cases. The new design is also much simpler, with a negative diffstat of over 1200 lines. Finally, this also fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default, so people often forgot to enable it.
For now the SHA-256 library is well-covered by the crypto_shash self-tests, but I plan to add a test for the library directly later. I've fully tested this series on arm, arm64, riscv, and x86. On mips, powerpc, s390, and sparc I've only been able to partially test it, since QEMU does not support the SHA-256 instructions on those platforms. If anyone with access to a mips, powerpc, s390, or sparc system that has SHA-256 instructions can verify that the crypto self-tests still pass, that would be appreciated. But I don't expect any issues, especially since the new code is more straightforward than the old code.
Eric Biggers (13):
crypto: sha256 - support arch-optimized lib and expose through shash
crypto: arm/sha256 - implement library instead of shash
crypto: arm64/sha256 - remove obsolete chunking logic
crypto: arm64/sha256 - implement library instead of shash
crypto: mips/sha256 - implement library instead of shash
crypto: powerpc/sha256 - implement library instead of shash
crypto: riscv/sha256 - implement library instead of shash
crypto: s390/sha256 - implement library instead of shash
crypto: sparc - move opcodes.h into asm directory
crypto: sparc/sha256 - implement library instead of shash
crypto: x86/sha256 - implement library instead of shash
crypto: sha256 - remove sha256_base.h
crypto: lib/sha256 - improve function prototypes
arch/arm/configs/exynos_defconfig | 1 -
arch/arm/configs/milbeaut_m10v_defconfig | 1 -
arch/arm/configs/multi_v7_defconfig | 1 -
arch/arm/configs/omap2plus_defconfig | 1 -
arch/arm/configs/pxa_defconfig | 1 -
arch/arm/crypto/Kconfig | 21 -
arch/arm/crypto/Makefile | 8 +-
arch/arm/crypto/sha2-ce-glue.c | 87 ----
arch/arm/crypto/sha256_glue.c | 107 -----
arch/arm/crypto/sha256_glue.h | 9 -
arch/arm/crypto/sha256_neon_glue.c | 75 ---
arch/arm/lib/crypto/.gitignore | 1 +
arch/arm/lib/crypto/Kconfig | 7 +
arch/arm/lib/crypto/Makefile | 8 +-
arch/arm/{ => lib}/crypto/sha256-armv4.pl | 20 +-
.../sha2-ce-core.S => lib/crypto/sha256-ce.S} | 10 +-
arch/arm/lib/crypto/sha256.c | 64 +++
arch/arm64/configs/defconfig | 1 -
arch/arm64/crypto/Kconfig | 19 -
arch/arm64/crypto/Makefile | 13 +-
arch/arm64/crypto/sha2-ce-glue.c | 138 ------
arch/arm64/crypto/sha256-glue.c | 171 -------
arch/arm64/crypto/sha512-glue.c | 6 +-
arch/arm64/lib/crypto/.gitignore | 1 +
arch/arm64/lib/crypto/Kconfig | 6 +
arch/arm64/lib/crypto/Makefile | 9 +-
.../crypto/sha2-armv8.pl} | 2 +-
.../sha2-ce-core.S => lib/crypto/sha256-ce.S} | 36 +-
arch/arm64/lib/crypto/sha256.c | 75 +++
arch/mips/cavium-octeon/Kconfig | 6 +
.../mips/cavium-octeon/crypto/octeon-sha256.c | 139 ++----
arch/mips/configs/cavium_octeon_defconfig | 1 -
arch/mips/crypto/Kconfig | 10 -
arch/powerpc/crypto/Kconfig | 11 -
arch/powerpc/crypto/Makefile | 2 -
arch/powerpc/crypto/sha256-spe-glue.c | 128 ------
arch/powerpc/lib/crypto/Kconfig | 6 +
arch/powerpc/lib/crypto/Makefile | 3 +
.../powerpc/{ => lib}/crypto/sha256-spe-asm.S | 0
arch/powerpc/lib/crypto/sha256.c | 70 +++
arch/riscv/crypto/Kconfig | 11 -
arch/riscv/crypto/Makefile | 3 -
arch/riscv/crypto/sha256-riscv64-glue.c | 125 -----
arch/riscv/lib/crypto/Kconfig | 8 +
arch/riscv/lib/crypto/Makefile | 3 +
.../sha256-riscv64-zvknha_or_zvknhb-zvkb.S | 4 +-
arch/riscv/lib/crypto/sha256.c | 67 +++
arch/s390/configs/debug_defconfig | 1 -
arch/s390/configs/defconfig | 1 -
arch/s390/crypto/Kconfig | 10 -
arch/s390/crypto/Makefile | 1 -
arch/s390/crypto/sha256_s390.c | 144 ------
arch/s390/lib/crypto/Kconfig | 6 +
arch/s390/lib/crypto/Makefile | 2 +
arch/s390/lib/crypto/sha256.c | 47 ++
arch/sparc/crypto/Kconfig | 10 -
arch/sparc/crypto/Makefile | 2 -
arch/sparc/crypto/aes_asm.S | 3 +-
arch/sparc/crypto/aes_glue.c | 3 +-
arch/sparc/crypto/camellia_asm.S | 3 +-
arch/sparc/crypto/camellia_glue.c | 3 +-
arch/sparc/crypto/des_asm.S | 3 +-
arch/sparc/crypto/des_glue.c | 3 +-
arch/sparc/crypto/md5_asm.S | 3 +-
arch/sparc/crypto/md5_glue.c | 3 +-
arch/sparc/crypto/sha1_asm.S | 3 +-
arch/sparc/crypto/sha1_glue.c | 3 +-
arch/sparc/crypto/sha256_glue.c | 129 ------
arch/sparc/crypto/sha512_asm.S | 3 +-
arch/sparc/crypto/sha512_glue.c | 3 +-
arch/sparc/{crypto => include/asm}/opcodes.h | 6 +-
arch/sparc/lib/Makefile | 1 +
arch/sparc/lib/crc32c_asm.S | 3 +-
arch/sparc/lib/crypto/Kconfig | 8 +
arch/sparc/lib/crypto/Makefile | 4 +
arch/sparc/lib/crypto/sha256.c | 64 +++
arch/sparc/{ => lib}/crypto/sha256_asm.S | 5 +-
arch/x86/crypto/Kconfig | 14 -
arch/x86/crypto/Makefile | 3 -
arch/x86/crypto/sha256_ssse3_glue.c | 432 ------------------
arch/x86/lib/crypto/Kconfig | 8 +
arch/x86/lib/crypto/Makefile | 3 +
arch/x86/{ => lib}/crypto/sha256-avx-asm.S | 12 +-
arch/x86/{ => lib}/crypto/sha256-avx2-asm.S | 12 +-
.../crypto/sha256-ni-asm.S} | 36 +-
arch/x86/{ => lib}/crypto/sha256-ssse3-asm.S | 14 +-
arch/x86/lib/crypto/sha256.c | 80 ++++
arch/x86/purgatory/Makefile | 3 -
arch/x86/purgatory/sha256.c | 15 +
crypto/Kconfig | 1 +
crypto/Makefile | 3 +-
crypto/sha256.c | 289 ++++++++++++
crypto/sha256_generic.c | 102 -----
include/crypto/internal/sha2.h | 75 +++
include/crypto/sha2.h | 37 +-
include/crypto/sha256_base.h | 148 ------
lib/crypto/Kconfig | 30 ++
lib/crypto/Makefile | 1 +
lib/crypto/sha256-generic.c | 139 ++++++
lib/crypto/sha256.c | 150 ++----
100 files changed, 1268 insertions(+), 2315 deletions(-)
delete mode 100644 arch/arm/crypto/sha2-ce-glue.c
delete mode 100644 arch/arm/crypto/sha256_glue.c
delete mode 100644 arch/arm/crypto/sha256_glue.h
delete mode 100644 arch/arm/crypto/sha256_neon_glue.c
rename arch/arm/{ => lib}/crypto/sha256-armv4.pl (97%)
rename arch/arm/{crypto/sha2-ce-core.S => lib/crypto/sha256-ce.S} (91%)
create mode 100644 arch/arm/lib/crypto/sha256.c
delete mode 100644 arch/arm64/crypto/sha2-ce-glue.c
delete mode 100644 arch/arm64/crypto/sha256-glue.c
rename arch/arm64/{crypto/sha512-armv8.pl => lib/crypto/sha2-armv8.pl} (99%)
rename arch/arm64/{crypto/sha2-ce-core.S => lib/crypto/sha256-ce.S} (80%)
create mode 100644 arch/arm64/lib/crypto/sha256.c
delete mode 100644 arch/powerpc/crypto/sha256-spe-glue.c
rename arch/powerpc/{ => lib}/crypto/sha256-spe-asm.S (100%)
create mode 100644 arch/powerpc/lib/crypto/sha256.c
delete mode 100644 arch/riscv/crypto/sha256-riscv64-glue.c
rename arch/riscv/{ => lib}/crypto/sha256-riscv64-zvknha_or_zvknhb-zvkb.S (98%)
create mode 100644 arch/riscv/lib/crypto/sha256.c
delete mode 100644 arch/s390/crypto/sha256_s390.c
create mode 100644 arch/s390/lib/crypto/sha256.c
delete mode 100644 arch/sparc/crypto/sha256_glue.c
rename arch/sparc/{crypto => include/asm}/opcodes.h (96%)
create mode 100644 arch/sparc/lib/crypto/Kconfig
create mode 100644 arch/sparc/lib/crypto/Makefile
create mode 100644 arch/sparc/lib/crypto/sha256.c
rename arch/sparc/{ => lib}/crypto/sha256_asm.S (95%)
delete mode 100644 arch/x86/crypto/sha256_ssse3_glue.c
rename arch/x86/{ => lib}/crypto/sha256-avx-asm.S (98%)
rename arch/x86/{ => lib}/crypto/sha256-avx2-asm.S (98%)
rename arch/x86/{crypto/sha256_ni_asm.S => lib/crypto/sha256-ni-asm.S} (85%)
rename arch/x86/{ => lib}/crypto/sha256-ssse3-asm.S (98%)
create mode 100644 arch/x86/lib/crypto/sha256.c
create mode 100644 arch/x86/purgatory/sha256.c
create mode 100644 crypto/sha256.c
delete mode 100644 crypto/sha256_generic.c
create mode 100644 include/crypto/internal/sha2.h
delete mode 100644 include/crypto/sha256_base.h
create mode 100644 lib/crypto/sha256-generic.cSignature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 1/13 crypto: sha256 - support arch-optimized lib and expose through shash
From: Eric Biggers <[email protected]>
As has been done for various other algorithms, rework the design of the SHA-256 library to support arch-optimized implementations, and make crypto/sha256.c expose both generic and arch-optimized shash algorithms that wrap the library functions.
This allows users of the SHA-256 library functions to take advantage of the arch-optimized code, and this makes it much simpler to integrate SHA-256 for each architecture.
Note that sha256_base.h is not used in the new design. It will be removed once all the architecture-specific code has been updated.
Expose the blocks interface and use that for shash. Add a direct entry point for the SIMD blocks functions so that the decision to use SIMD or not occurs in the generic code.
Register a separate shash algorithm "sha256-lib" to provide test coverage for the libsha256 interface.
Split the libsha256 module into two so that the arch sha256 module can invoke the generic block function without creating a cycle. Rejig the purgatory sha256 setup to make this work.
--- arch/x86/purgatory/Makefile | 3 - arch/x86/purgatory/sha256.c | 15 ++ crypto/Kconfig | 1 + crypto/Makefile | 3 +- crypto/sha256.c | 289 +++++++++++++++++++++++++++++++++ crypto/sha256_generic.c | 102 ------------ include/crypto/internal/sha2.h | 75 +++++++++ include/crypto/sha2.h | 29 ++-- include/crypto/sha256_base.h | 9 +- lib/crypto/Kconfig | 27 +++ lib/crypto/Makefile | 1 + lib/crypto/sha256-generic.c | 139 ++++++++++++++++ lib/crypto/sha256.c | 144 +++------------- 13 files changed, 597 insertions(+), 240 deletions(-) create mode 100644 arch/x86/purgatory/sha256.c create mode 100644 crypto/sha256.c delete mode 100644 crypto/sha256_generic.c create mode 100644 include/crypto/internal/sha2.h create mode 100644 lib/crypto/sha256-generic.c
arch/x86/purgatory/Makefile +0 -3
@@ -8,9 +8,6 @@ PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) $(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE $(call if_changed_rule,cc_o_c) -$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE - $(call if_changed_rule,cc_o_c) - CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY # When profile-guided optimization is enabled, llvm emits two different
arch/x86/purgatory/sha256.c new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* SHA-256, as specified in +* http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf +* +* SHA-256 code by Jean-Luc Cooke <[email protected]>. +* +* Copyright (c) Jean-Luc Cooke <[email protected]> +* Copyright (c) Andrew McDonald <[email protected]> +* Copyright (c) 2002 James Morris <[email protected]> +* Copyright (c) 2014 Red Hat Inc. +*/ + +#include "../../../lib/crypto/sha256-generic.c" +#include "../../../lib/crypto/sha256.c"
crypto/Kconfig +1 -0
@@ -982,6 +982,7 @@ config CRYPTO_SHA256 tristate "SHA-224 and SHA-256" select CRYPTO_HASH select CRYPTO_LIB_SHA256 + select CRYPTO_LIB_SHA256_GENERIC help SHA-224 and SHA-256 secure hash algorithms (FIPS 180, ISO/IEC 10118-3)
crypto/Makefile +2 -1
@@ -76,7 +76,8 @@ obj-$(CONFIG_CRYPTO_MD4) += md4.o obj-$(CONFIG_CRYPTO_MD5) += md5.o obj-$(CONFIG_CRYPTO_RMD160) += rmd160.o obj-$(CONFIG_CRYPTO_SHA1) += sha1_generic.o -obj-$(CONFIG_CRYPTO_SHA256) += sha256_generic.o +obj-$(CONFIG_CRYPTO_SHA256) += sha256.o +CFLAGS_sha256.o += -DARCH=$(ARCH) obj-$(CONFIG_CRYPTO_SHA512) += sha512_generic.o obj-$(CONFIG_CRYPTO_SHA3) += sha3_generic.o obj-$(CONFIG_CRYPTO_SM3_GENERIC) += sm3_generic.o
crypto/sha256.c new file +289 -0
289 lines not on this page · raw message
crypto/sha256_generic.c deleted +0 -102
102 lines not on this page · raw message
include/crypto/internal/sha2.h new file +75 -0
75 lines not on this page · raw message
include/crypto/sha2.h +15 -14
@@ -13,6 +13,7 @@#define SHA256_DIGEST_SIZE 32#define SHA256_BLOCK_SIZE 64 +#define SHA256_STATE_WORDS 8#define SHA384_DIGEST_SIZE 48#define SHA384_BLOCK_SIZE 128
@@ -66,7 +67,7 @@ extern const u8 sha384_zero_message_hash[SHA384_DIGEST_SIZE];extern const u8 sha512_zero_message_hash[SHA512_DIGEST_SIZE ];struct crypto_sha256_state { -u32 state[SHA256_DIGEST_SIZE /4 ]; +u32 state[SHA256_STATE_WORDS ];u64 count; };
@@ -74,7 +75,7 @@ struct sha256_state {union {struct crypto_sha256_state ctx;struct { -u32 state[SHA256_DIGEST_SIZE /4 ]; +u32 state[SHA256_STATE_WORDS ];u64 count; }; };
@@ -87,17 +88,7 @@ struct sha512_state {u8 buf[SHA512_BLOCK_SIZE ]; }; -/* -* Stand-alone implementation of the SHA256 algorithm. It is designed to -* have as little dependencies as possible so it can be used in the -* kexec_file purgatory. In other cases you should generally use the -* hash APIs from include/crypto/hash.h. Especially when hashing large -* amounts of data as those APIs may be hw-accelerated. -* -* For details see lib/crypto/sha256.c -*/ - -static inline void sha256_init (struct sha256_state *sctx) +static inline void sha256_block_init (struct crypto_sha256_state *sctx) { sctx->state[0 ] =SHA256_H0 ; sctx->state[1 ] =SHA256_H1 ;
@@ -109,11 +100,16 @@ static inline void sha256_init(struct sha256_state *sctx) sctx->state[7 ] =SHA256_H7 ; sctx->count =0 ; } + +static inline void sha256_init (struct sha256_state *sctx) +{ +sha256_block_init (&sctx->ctx); +}void sha256_update (struct sha256_state *sctx,const u8 *data,unsigned int len);void sha256_final (struct sha256_state *sctx,u8 *out);void sha256 (const u8 *data,unsigned int len,u8 *out); -static inline void sha224_init (struct sha256_state *sctx) +static inline void sha224_block_init (struct crypto_sha256_state *sctx) { sctx->state[0 ] =SHA224_H0 ; sctx->state[1 ] =SHA224_H1 ;
@@ -125,6 +121,11 @@ static inline void sha224_init(struct sha256_state *sctx) sctx->state[7 ] =SHA224_H7 ; sctx->count =0 ; } + +static inline void sha224_init (struct sha256_state *sctx) +{ +sha224_block_init (&sctx->ctx); +}/* Simply use sha256_update as it is equivalent to sha224_update. */ void sha224_final (struct sha256_state *sctx,u8 *out);
include/crypto/sha256_base.h +6 -3
@@ -10,7 +10,7 @@#include <crypto/internal/blockhash.h> #include <crypto/internal/hash.h> -#include <crypto/sha2.h> +#include <crypto/internal/sha2.h> #include <linux/math.h> #include <linux/string.h> #include <linux/types.h>
@@ -142,7 +142,10 @@ static inline int sha256_base_finish(struct shash_desc *desc, u8 *out) return __sha256_base_finish(sctx->state, out, digest_size); } -void sha256_transform_blocks (struct crypto_sha256_state *sst, -const u8 *input,int blocks); +static inline void sha256_transform_blocks (struct crypto_sha256_state *sst, +const u8 *input,int blocks) +{ +sha256_blocks_generic (sst->state, input, blocks); +}#endif /* _CRYPTO_SHA256_BASE_H */
lib/crypto/Kconfig +27 -0
@@ -139,6 +139,33 @@ config CRYPTO_LIB_SHA1 config CRYPTO_LIB_SHA256 tristate + help + Enable the SHA-256 library interface. This interface may be fulfilled + by either the generic implementation or an arch-specific one, if one + is available and enabled. + +config CRYPTO_ARCH_HAVE_LIB_SHA256 + bool + help + Declares whether the architecture provides an arch-specific + accelerated implementation of the SHA-256 library interface. + +config CRYPTO_ARCH_HAVE_LIB_SHA256_SIMD + bool + help + Declares whether the architecture provides an arch-specific + accelerated implementation of the SHA-256 library interface + that is SIMD-based and therefore not usable in hardirq + context. + +config CRYPTO_LIB_SHA256_GENERIC + tristate + default CRYPTO_LIB_SHA256 if !CRYPTO_ARCH_HAVE_LIB_SHA256 + help + This symbol can be selected by arch implementations of the SHA-256 + library interface that require the generic code as a fallback, e.g., + for SIMD implementations. If no arch specific implementation is + enabled, this implementation serves the users of CRYPTO_LIB_SHA256. config CRYPTO_LIB_SM3 tristate
lib/crypto/Makefile +1 -0
@@ -50,6 +50,7 @@ libsha1-y := sha1.o obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o libsha256-y := sha256.o +obj-$(CONFIG_CRYPTO_LIB_SHA256_GENERIC) += sha256-generic.o ifneq ($(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS),y) libblake2s-y += blake2s-selftest.o
lib/crypto/sha256-generic.c new file +139 -0
139 lines not on this page · raw message
lib/crypto/sha256.c +27 -117
175 lines not on this page · raw message
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 2/13 crypto: arm/sha256 - implement library instead of shash
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Instead of providing crypto_shash algorithms for the arch-optimized SHA-256 code, instead implement the SHA-256 library. This is much simpler, it makes the SHA-256 library functions be arch-optimized, and it fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default. SHA-256 still remains available through crypto_shash, but individual architectures no longer need to handle it.
To merge the scalar, NEON, and CE code all into one module cleanly, add !CPU_V7M as a direct dependency of the CE code. Previously, !CPU_V7M was only a direct dependency of the scalar and NEON code. The result is still the same because CPU_V7M implies !KERNEL_MODE_NEON, so !CPU_V7M was already an indirect dependency of the CE code.
To match sha256_blocks_arch(), change the type of the nblocks parameter of the assembly functions from int to size_t. The assembly functions actually already treated it as size_t.
While renaming the assembly files, also fix the naming quirk where "sha2" meant sha256. (SHA-512 is also part of SHA-2.)
---
arch/arm/configs/exynos_defconfig | 1 -
arch/arm/configs/milbeaut_m10v_defconfig | 1 -
arch/arm/configs/multi_v7_defconfig | 1 -
arch/arm/configs/omap2plus_defconfig | 1 -
arch/arm/configs/pxa_defconfig | 1 -
arch/arm/crypto/Kconfig | 21 ----
arch/arm/crypto/Makefile | 8 +-
arch/arm/crypto/sha2-ce-glue.c | 87 --------------
arch/arm/crypto/sha256_glue.c | 107 ------------------
arch/arm/crypto/sha256_glue.h | 9 --
arch/arm/crypto/sha256_neon_glue.c | 75 ------------
arch/arm/lib/crypto/.gitignore | 1 +
arch/arm/lib/crypto/Kconfig | 7 ++
arch/arm/lib/crypto/Makefile | 8 +-
arch/arm/{ => lib}/crypto/sha256-armv4.pl | 20 ++--
.../sha2-ce-core.S => lib/crypto/sha256-ce.S} | 10 +-
arch/arm/lib/crypto/sha256.c | 64 +++++++++++
17 files changed, 95 insertions(+), 327 deletions(-)
delete mode 100644 arch/arm/crypto/sha2-ce-glue.c
delete mode 100644 arch/arm/crypto/sha256_glue.c
delete mode 100644 arch/arm/crypto/sha256_glue.h
delete mode 100644 arch/arm/crypto/sha256_neon_glue.c
rename arch/arm/{ => lib}/crypto/sha256-armv4.pl (97%)
rename arch/arm/{crypto/sha2-ce-core.S => lib/crypto/sha256-ce.S} (91%)
create mode 100644 arch/arm/lib/crypto/sha256.carch/arm/configs/exynos_defconfig +0 -1
@@ -364,7 +364,6 @@ CONFIG_CRYPTO_USER_API_SKCIPHER=m CONFIG_CRYPTO_USER_API_RNG=m CONFIG_CRYPTO_USER_API_AEAD=m CONFIG_CRYPTO_SHA1_ARM_NEON=m -CONFIG_CRYPTO_SHA256_ARM=m CONFIG_CRYPTO_SHA512_ARM=m CONFIG_CRYPTO_AES_ARM_BS=m CONFIG_CRYPTO_CHACHA20_NEON=m
arch/arm/configs/milbeaut_m10v_defconfig +0 -1
@@ -101,7 +101,6 @@ CONFIG_CRYPTO_SEQIV=m CONFIG_CRYPTO_GHASH_ARM_CE=m CONFIG_CRYPTO_SHA1_ARM_NEON=m CONFIG_CRYPTO_SHA1_ARM_CE=m -CONFIG_CRYPTO_SHA2_ARM_CE=m CONFIG_CRYPTO_SHA512_ARM=m CONFIG_CRYPTO_AES_ARM=m CONFIG_CRYPTO_AES_ARM_BS=m
arch/arm/configs/multi_v7_defconfig +0 -1
@@ -1301,7 +1301,6 @@ CONFIG_CRYPTO_USER_API_AEAD=m CONFIG_CRYPTO_GHASH_ARM_CE=m CONFIG_CRYPTO_SHA1_ARM_NEON=m CONFIG_CRYPTO_SHA1_ARM_CE=m -CONFIG_CRYPTO_SHA2_ARM_CE=m CONFIG_CRYPTO_SHA512_ARM=m CONFIG_CRYPTO_AES_ARM=m CONFIG_CRYPTO_AES_ARM_BS=m
arch/arm/configs/omap2plus_defconfig +0 -1
@@ -697,7 +697,6 @@ CONFIG_SECURITY=y CONFIG_CRYPTO_MICHAEL_MIC=y CONFIG_CRYPTO_GHASH_ARM_CE=m CONFIG_CRYPTO_SHA1_ARM_NEON=m -CONFIG_CRYPTO_SHA256_ARM=m CONFIG_CRYPTO_SHA512_ARM=m CONFIG_CRYPTO_AES_ARM=m CONFIG_CRYPTO_AES_ARM_BS=m
arch/arm/configs/pxa_defconfig +0 -1
@@ -660,7 +660,6 @@ CONFIG_CRYPTO_XCBC=m CONFIG_CRYPTO_DEFLATE=y CONFIG_CRYPTO_LZO=y CONFIG_CRYPTO_SHA1_ARM=m -CONFIG_CRYPTO_SHA256_ARM=m CONFIG_CRYPTO_SHA512_ARM=m CONFIG_CRYPTO_AES_ARM=m CONFIG_CRC_CCITT=y
arch/arm/crypto/Kconfig +0 -21
@@ -93,27 +93,6 @@ config CRYPTO_SHA1_ARM_CE Architecture: arm using ARMv8 Crypto Extensions -config CRYPTO_SHA2_ARM_CE - tristate "Hash functions: SHA-224 and SHA-256 (ARMv8 Crypto Extensions)" - depends on KERNEL_MODE_NEON - select CRYPTO_SHA256_ARM - select CRYPTO_HASH - help - SHA-224 and SHA-256 secure hash algorithms (FIPS 180) - - Architecture: arm using - - ARMv8 Crypto Extensions - -config CRYPTO_SHA256_ARM - tristate "Hash functions: SHA-224 and SHA-256 (NEON)" - select CRYPTO_HASH - depends on !CPU_V7M - help - SHA-224 and SHA-256 secure hash algorithms (FIPS 180) - - Architecture: arm using - - NEON (Advanced SIMD) extensions - config CRYPTO_SHA512_ARM tristate "Hash functions: SHA-384 and SHA-512 (NEON)" select CRYPTO_HASH
arch/arm/crypto/Makefile +1 -7
@@ -7,7 +7,6 @@ obj-$(CONFIG_CRYPTO_AES_ARM) += aes-arm.o obj-$(CONFIG_CRYPTO_AES_ARM_BS) += aes-arm-bs.o obj-$(CONFIG_CRYPTO_SHA1_ARM) += sha1-arm.o obj-$(CONFIG_CRYPTO_SHA1_ARM_NEON) += sha1-arm-neon.o -obj-$(CONFIG_CRYPTO_SHA256_ARM) += sha256-arm.o obj-$(CONFIG_CRYPTO_SHA512_ARM) += sha512-arm.o obj-$(CONFIG_CRYPTO_BLAKE2B_NEON) += blake2b-neon.o obj-$(CONFIG_CRYPTO_NHPOLY1305_NEON) += nhpoly1305-neon.o
@@ -15,20 +14,16 @@ obj-$(CONFIG_CRYPTO_CURVE25519_NEON) += curve25519-neon.o obj-$(CONFIG_CRYPTO_AES_ARM_CE) += aes-arm-ce.o obj-$(CONFIG_CRYPTO_SHA1_ARM_CE) += sha1-arm-ce.o -obj-$(CONFIG_CRYPTO_SHA2_ARM_CE) += sha2-arm-ce.o obj-$(CONFIG_CRYPTO_GHASH_ARM_CE) += ghash-arm-ce.o aes-arm-y := aes-cipher-core.o aes-cipher-glue.o aes-arm-bs-y := aes-neonbs-core.o aes-neonbs-glue.o sha1-arm-y := sha1-armv4-large.o sha1_glue.o sha1-arm-neon-y := sha1-armv7-neon.o sha1_neon_glue.o -sha256-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha256_neon_glue.o -sha256-arm-y := sha256-core.o sha256_glue.o $(sha256-arm-neon-y) sha512-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha512-neon-glue.o sha512-arm-y := sha512-core.o sha512-glue.o $(sha512-arm-neon-y) blake2b-neon-y := blake2b-neon-core.o blake2b-neon-glue.o sha1-arm-ce-y := sha1-ce-core.o sha1-ce-glue.o -sha2-arm-ce-y := sha2-ce-core.o sha2-ce-glue.o aes-arm-ce-y := aes-ce-core.o aes-ce-glue.o ghash-arm-ce-y := ghash-ce-core.o ghash-ce-glue.o nhpoly1305-neon-y := nh-neon-core.o nhpoly1305-neon-glue.o
@@ -40,9 +35,8 @@ quiet_cmd_perl = PERL $@ $(obj)/%-core.S: $(src)/%-armv4.pl $(call cmd,perl) -clean-files += sha256-core.S sha512-core.S +clean-files += sha512-core.S aflags-thumb2-$(CONFIG_THUMB2_KERNEL) := -U__thumb2__ -D__thumb2__=1 -AFLAGS_sha256-core.o += $(aflags-thumb2-y) AFLAGS_sha512-core.o += $(aflags-thumb2-y)
arch/arm/crypto/sha2-ce-glue.c deleted +0 -87
87 lines not on this page · raw message
arch/arm/crypto/sha256_glue.c deleted +0 -107
107 lines not on this page · raw message
arch/arm/crypto/sha256_glue.h deleted +0 -9
@@ -1,9 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _CRYPTO_SHA256_GLUE_H -#define _CRYPTO_SHA256_GLUE_H - -#include <crypto/hash.h> - -extern struct shash_alg sha256_neon_algs[2 ]; - -#endif /* _CRYPTO_SHA256_GLUE_H */
arch/arm/crypto/sha256_neon_glue.c deleted +0 -75
75 lines not on this page · raw message
arch/arm/lib/crypto/.gitignore +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only poly1305-core.S +sha256-core.S
arch/arm/lib/crypto/Kconfig +7 -0
@@ -22,3 +22,10 @@ config CRYPTO_POLY1305_ARM tristate default CRYPTO_LIB_POLY1305 select CRYPTO_ARCH_HAVE_LIB_POLY1305 + +config CRYPTO_SHA256_ARM + tristate + depends on !CPU_V7M + default CRYPTO_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256_SIMD
arch/arm/lib/crypto/Makefile +7 -1
@@ -10,13 +10,17 @@ chacha-neon-$(CONFIG_KERNEL_MODE_NEON) += chacha-neon-core.o obj-$(CONFIG_CRYPTO_POLY1305_ARM) += poly1305-arm.o poly1305-arm-y := poly1305-core.o poly1305-glue.o +obj-$(CONFIG_CRYPTO_SHA256_ARM) += sha256-arm.o +sha256-arm-y := sha256.o sha256-core.o +sha256-arm-$(CONFIG_KERNEL_MODE_NEON) += sha256-ce.o + quiet_cmd_perl = PERL $@ cmd_perl = $(PERL) $(<) > $(@) $(obj)/%-core.S: $(src)/%-armv4.pl $(call cmd,perl) -clean-files += poly1305-core.S +clean-files += poly1305-core.S sha256-core.S aflags-thumb2-$(CONFIG_THUMB2_KERNEL) := -U__thumb2__ -D__thumb2__=1
@@ -24,3 +28,5 @@ aflags-thumb2-$(CONFIG_THUMB2_KERNEL) := -U__thumb2__ -D__thumb2__=1 poly1305-aflags-$(CONFIG_CPU_V7) := -U__LINUX_ARM_ARCH__ -D__LINUX_ARM_ARCH__=5 poly1305-aflags-$(CONFIG_KERNEL_MODE_NEON) := -U__LINUX_ARM_ARCH__ -D__LINUX_ARM_ARCH__=7 AFLAGS_poly1305-core.o += $(poly1305-aflags-y) $(aflags-thumb2-y) + +AFLAGS_sha256-core.o += $(aflags-thumb2-y)
arch/arm/lib/crypto/sha256-armv4.pl renamed from arch/arm/crypto/sha256-armv4.pl +10 -10
@@ -204,18 +204,18 @@ K256: .word 0 @ terminator #if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__) .LOPENSSL_armcap: -.word OPENSSL_armcap_P-sha256_block_data_order +.word OPENSSL_armcap_P-sha256_blocks_arch #endif .align 5 -.global sha256_block_data_order -.type sha256_block_data_order,%function -sha256_block_data_order: -.Lsha256_block_data_order: +.global sha256_blocks_arch +.type sha256_blocks_arch,%function +sha256_blocks_arch: +.Lsha256_blocks_arch: #if __ARM_ARCH__<7 - sub r3,pc,#8 @ sha256_block_data_order + sub r3,pc,#8 @ sha256_blocks_arch #else - adr r3,.Lsha256_block_data_order + adr r3,.Lsha256_blocks_arch #endif #if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__) ldr r12,.LOPENSSL_armcap
@@ -282,7 +282,7 @@ $code.=<<___; moveq pc,lr @ be binary compatible with V4, yet bx lr @ interoperable with Thumb ISA:-) #endif -.size sha256_block_data_order,.-sha256_block_data_order +.size sha256_blocks_arch,.-sha256_blocks_arch ___ ###################################################################### # NEON stuff
@@ -470,8 +470,8 @@ sha256_block_data_order_neon: stmdb sp!,{r4-r12,lr} sub $H,sp,#16*4+16 - adr $Ktbl,.Lsha256_block_data_order - sub $Ktbl,$Ktbl,#.Lsha256_block_data_order-K256 + adr $Ktbl,.Lsha256_blocks_arch + sub $Ktbl,$Ktbl,#.Lsha256_blocks_arch-K256 bic $H,$H,#15 @ align for 128-bit stores mov $t2,sp mov sp,$H @ alloca
arch/arm/lib/crypto/sha256-ce.S renamed from arch/arm/crypto/sha2-ce-core.S +5 -5
@@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * sha2-ce-core.S - SHA-224/256 secure hash using ARMv8 Crypto Extensions + * sha256-ce.S - SHA-224/256 secure hash using ARMv8 Crypto Extensions * * Copyright (C) 2015 Linaro Ltd. * Author: Ard Biesheuvel <[email protected]>
@@ -67,10 +67,10 @@ .word 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 /* - * void sha2_ce_transform(struct sha256_state *sst, u8 const *src, - int blocks); + * void sha256_ce_transform(u32 state[SHA256_STATE_WORDS], + * const u8 *data, size_t nblocks); */ -ENTRY(sha2_ce_transform) +ENTRY(sha256_ce_transform) /* load state */ vld1.32 {dga-dgb}, [r0]
@@ -120,4 +120,4 @@ ENTRY(sha2_ce_transform) /* store new state */ vst1.32 {dga-dgb}, [r0] bx lr -ENDPROC(sha2_ce_transform) +ENDPROC(sha256_ce_transform)
arch/arm/lib/crypto/sha256.c new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 3/13 crypto: arm64/sha256 - remove obsolete chunking logic
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Since kernel-mode NEON sections are now preemptible on arm64, there is no longer any need to limit the length of them.
--- arch/arm64/crypto/sha256-glue.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-)
arch/arm64/crypto/sha256-glue.c +2 -17
@@ -86,23 +86,8 @@ static struct shash_alg algs[] = { {static int sha256_update_neon (struct shash_desc *desc,const u8 *data,unsigned int len) { -do { -unsigned int chunk = len; - -/* -* Don't hog the CPU for the entire time it takes to process all -* input when running on a preemptible kernel, but process the -* data block by block instead. -*/ -if (IS_ENABLED (CONFIG_PREEMPTION )) - chunk =SHA256_BLOCK_SIZE ; - - chunk -=sha256_base_do_update_blocks (desc, data, chunk, - sha256_neon_transform); - data += chunk; - len -= chunk; - }while (len >=SHA256_BLOCK_SIZE ); -return len; +return sha256_base_do_update_blocks (desc, data, len, + sha256_neon_transform); } static int sha256_finup_neon(struct shash_desc *desc, const u8 *data,
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 4/13 crypto: arm64/sha256 - implement library instead of shash
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Instead of providing crypto_shash algorithms for the arch-optimized SHA-256 code, instead implement the SHA-256 library. This is much simpler, it makes the SHA-256 library functions be arch-optimized, and it fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default. SHA-256 still remains available through crypto_shash, but individual architectures no longer need to handle it.
Remove support for SHA-256 finalization from the ARMv8 CE assembly code, since the library does not yet support architecture-specific overrides of the finalization. (Support for that has been omitted for now, for simplicity and because usually it isn't performance-critical.)
To match sha256_blocks_arch(), change the type of the nblocks parameter of the assembly functions from int or 'unsigned int' to size_t. Update the ARMv8 CE assembly function accordingly. The scalar and NEON assembly functions actually already treated it as size_t.
While renaming the assembly files, also fix the naming quirks where "sha2" meant sha256, and "sha512" meant both sha256 and sha512.
---
arch/arm64/configs/defconfig | 1 -
arch/arm64/crypto/Kconfig | 19 ---
arch/arm64/crypto/Makefile | 13 +-
arch/arm64/crypto/sha2-ce-glue.c | 138 ----------------
arch/arm64/crypto/sha256-glue.c | 156 ------------------
arch/arm64/crypto/sha512-glue.c | 6 +-
arch/arm64/lib/crypto/.gitignore | 1 +
arch/arm64/lib/crypto/Kconfig | 6 +
arch/arm64/lib/crypto/Makefile | 9 +-
.../crypto/sha2-armv8.pl} | 2 +-
.../sha2-ce-core.S => lib/crypto/sha256-ce.S} | 36 +---
arch/arm64/lib/crypto/sha256.c | 75 +++++++++
12 files changed, 103 insertions(+), 359 deletions(-)
delete mode 100644 arch/arm64/crypto/sha2-ce-glue.c
delete mode 100644 arch/arm64/crypto/sha256-glue.c
rename arch/arm64/{crypto/sha512-armv8.pl => lib/crypto/sha2-armv8.pl} (99%)
rename arch/arm64/{crypto/sha2-ce-core.S => lib/crypto/sha256-ce.S} (80%)
create mode 100644 arch/arm64/lib/crypto/sha256.carch/arm64/configs/defconfig +0 -1
@@ -1737,7 +1737,6 @@ CONFIG_CRYPTO_USER_API_RNG=m CONFIG_CRYPTO_CHACHA20_NEON=m CONFIG_CRYPTO_GHASH_ARM64_CE=y CONFIG_CRYPTO_SHA1_ARM64_CE=y -CONFIG_CRYPTO_SHA2_ARM64_CE=y CONFIG_CRYPTO_SHA512_ARM64_CE=m CONFIG_CRYPTO_SHA3_ARM64=m CONFIG_CRYPTO_SM3_ARM64_CE=m
arch/arm64/crypto/Kconfig +0 -19
@@ -36,25 +36,6 @@ config CRYPTO_SHA1_ARM64_CE Architecture: arm64 using: - ARMv8 Crypto Extensions -config CRYPTO_SHA256_ARM64 - tristate "Hash functions: SHA-224 and SHA-256" - select CRYPTO_HASH - help - SHA-224 and SHA-256 secure hash algorithms (FIPS 180) - - Architecture: arm64 - -config CRYPTO_SHA2_ARM64_CE - tristate "Hash functions: SHA-224 and SHA-256 (ARMv8 Crypto Extensions)" - depends on KERNEL_MODE_NEON - select CRYPTO_HASH - select CRYPTO_SHA256_ARM64 - help - SHA-224 and SHA-256 secure hash algorithms (FIPS 180) - - Architecture: arm64 using: - - ARMv8 Crypto Extensions - config CRYPTO_SHA512_ARM64 tristate "Hash functions: SHA-384 and SHA-512" select CRYPTO_HASH
arch/arm64/crypto/Makefile +2 -11
@@ -8,9 +8,6 @@ obj-$(CONFIG_CRYPTO_SHA1_ARM64_CE) += sha1-ce.o sha1-ce-y := sha1-ce-glue.o sha1-ce-core.o -obj-$(CONFIG_CRYPTO_SHA2_ARM64_CE) += sha2-ce.o -sha2-ce-y := sha2-ce-glue.o sha2-ce-core.o - obj-$(CONFIG_CRYPTO_SHA512_ARM64_CE) += sha512-ce.o sha512-ce-y := sha512-ce-glue.o sha512-ce-core.o
@@ -56,9 +53,6 @@ aes-ce-blk-y := aes-glue-ce.o aes-ce.o obj-$(CONFIG_CRYPTO_AES_ARM64_NEON_BLK) += aes-neon-blk.o aes-neon-blk-y := aes-glue-neon.o aes-neon.o -obj-$(CONFIG_CRYPTO_SHA256_ARM64) += sha256-arm64.o -sha256-arm64-y := sha256-glue.o sha256-core.o - obj-$(CONFIG_CRYPTO_SHA512_ARM64) += sha512-arm64.o sha512-arm64-y := sha512-glue.o sha512-core.o
@@ -74,10 +68,7 @@ aes-neon-bs-y := aes-neonbs-core.o aes-neonbs-glue.o quiet_cmd_perlasm = PERLASM $@ cmd_perlasm = $(PERL) $(<) void $(@) -$(obj)/%-core.S: $(src)/%-armv8.pl +$(obj)/sha512-core.S: $(src)/../lib/crypto/sha2-armv8.pl $(call cmd,perlasm) -$(obj)/sha256-core.S: $(src)/sha512-armv8.pl - $(call cmd,perlasm) - -clean-files += sha256-core.S sha512-core.S +clean-files += sha512-core.S
arch/arm64/crypto/sha2-ce-glue.c deleted +0 -138
138 lines not on this page · raw message
arch/arm64/crypto/sha256-glue.c deleted +0 -156
156 lines not on this page · raw message
arch/arm64/crypto/sha512-glue.c +3 -3
@@ -18,13 +18,13 @@ MODULE_LICENSE("GPL v2");MODULE_ALIAS_CRYPTO ("sha384" );MODULE_ALIAS_CRYPTO ("sha512" ); -asmlinkage void sha512_block_data_order(u64 *digest, const void *data, -unsigned int num_blks); +asmlinkage void sha512_blocks_arch(u64 *digest, const void *data, +unsigned int num_blks);static void sha512_arm64_transform (struct sha512_state *sst,u8 const *src,int blocks) { -sha512_block_data_order (sst->state, src, blocks); +sha512_blocks_arch (sst->state, src, blocks); } static int sha512_update(struct shash_desc *desc, const u8 *data,
arch/arm64/lib/crypto/.gitignore +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only poly1305-core.S +sha256-core.S
arch/arm64/lib/crypto/Kconfig +6 -0
@@ -12,3 +12,9 @@ config CRYPTO_POLY1305_NEON depends on KERNEL_MODE_NEON default CRYPTO_LIB_POLY1305 select CRYPTO_ARCH_HAVE_LIB_POLY1305 + +config CRYPTO_SHA256_ARM64 + tristate + default CRYPTO_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256_SIMD
arch/arm64/lib/crypto/Makefile +8 -1
@@ -8,10 +8,17 @@ poly1305-neon-y := poly1305-core.o poly1305-glue.o AFLAGS_poly1305-core.o += -Dpoly1305_init=poly1305_block_init_arch AFLAGS_poly1305-core.o += -Dpoly1305_emit=poly1305_emit_arch +obj-$(CONFIG_CRYPTO_SHA256_ARM64) += sha256-arm64.o +sha256-arm64-y := sha256.o sha256-core.o +sha256-arm64-$(CONFIG_KERNEL_MODE_NEON) += sha256-ce.o + quiet_cmd_perlasm = PERLASM $@ cmd_perlasm = $(PERL) $(<) void $(@) $(obj)/%-core.S: $(src)/%-armv8.pl $(call cmd,perlasm) -clean-files += poly1305-core.S +$(obj)/sha256-core.S: $(src)/sha2-armv8.pl + $(call cmd,perlasm) + +clean-files += poly1305-core.S sha256-core.S
arch/arm64/lib/crypto/sha2-armv8.pl renamed from arch/arm64/crypto/sha512-armv8.pl +1 -1
@@ -95,7 +95,7 @@ if ($output =~ /512/) { $reg_t="w"; } -$func="sha${BITS}_block_data_order"; +$func="sha${BITS}_blocks_arch"; ($ctx,$inp,$num,$Ktbl)=map("x$_",(0..2,30));
arch/arm64/lib/crypto/sha256-ce.S renamed from arch/arm64/crypto/sha2-ce-core.S +7 -29
@@ -71,8 +71,8 @@ .word 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 /* - * int __sha256_ce_transform(struct sha256_ce_state *sst, u8 const *src, - * int blocks) + * size_t __sha256_ce_transform(u32 state[SHA256_STATE_WORDS], + * const u8 *data, size_t nblocks); */ .text SYM_FUNC_START(__sha256_ce_transform)
@@ -86,20 +86,16 @@ SYM_FUNC_START(__sha256_ce_transform) /* load state */ ld1 {dgav.4s, dgbv.4s}, [x0] - /* load sha256_ce_state::finalize */ - ldr_l w4, sha256_ce_offsetof_finalize, x4 - ldr w4, [x0, x4] - /* load input */ 0: ld1 {v16.4s-v19.4s}, [x1], #64 - sub w2, w2, #1 + sub x2, x2, #1 CPU_LE( rev32 v16.16b, v16.16b ) CPU_LE( rev32 v17.16b, v17.16b ) CPU_LE( rev32 v18.16b, v18.16b ) CPU_LE( rev32 v19.16b, v19.16b ) -1: add t0.4s, v16.4s, v0.4s + add t0.4s, v16.4s, v0.4s mov dg0v.16b, dgav.16b mov dg1v.16b, dgbv.16b
@@ -128,30 +124,12 @@ CPU_LE( rev32 v19.16b, v19.16b ) add dgbv.4s, dgbv.4s, dg1v.4s /* handled all input blocks? */ - cbz w2, 2f + cbz x2, 1f cond_yield 3f, x5, x6 b 0b - /* - * Final block: add padding and total bit count. - * Skip if the input size was not a round multiple of the block size, - * the padding is handled by the C code in that case. - */ -2: cbz x4, 3f - ldr_l w4, sha256_ce_offsetof_count, x4 - ldr x4, [x0, x4] - movi v17.2d, #0 - mov x8, #0x80000000 - movi v18.2d, #0 - ror x7, x4, #29 // ror(lsl(x4, 3), 32) - fmov d16, x8 - mov x4, #0 - mov v19.d[0], xzr - mov v19.d[1], x7 - b 1b - /* store new state */ -3: st1 {dgav.4s, dgbv.4s}, [x0] - mov w0, w2 +1: st1 {dgav.4s, dgbv.4s}, [x0] + mov x0, x2 ret SYM_FUNC_END(__sha256_ce_transform)
arch/arm64/lib/crypto/sha256.c new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 5/13 crypto: mips/sha256 - implement library instead of shash
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Instead of providing crypto_shash algorithms for the arch-optimized SHA-256 code, instead implement the SHA-256 library. This is much simpler, it makes the SHA-256 library functions be arch-optimized, and it fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default. SHA-256 still remains available through crypto_shash, but individual architectures no longer need to handle it.
--- arch/mips/cavium-octeon/Kconfig | 6 + .../mips/cavium-octeon/crypto/octeon-sha256.c | 139 ++++-------------- arch/mips/configs/cavium_octeon_defconfig | 1 - arch/mips/crypto/Kconfig | 10 -- 4 files changed, 35 insertions(+), 121 deletions(-)
arch/mips/cavium-octeon/Kconfig +6 -0
@@ -23,6 +23,12 @@ config CAVIUM_OCTEON_CVMSEG_SIZE legally range is from zero to 54 cache blocks (i.e. CVMSEG LM is between zero and 6192 bytes). +config CRYPTO_SHA256_OCTEON + tristate + default CRYPTO_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256 + select CRYPTO_LIB_SHA256_GENERIC + endif # CPU_CAVIUM_OCTEON if CAVIUM_OCTEON_SOC
arch/mips/cavium-octeon/crypto/octeon-sha256.c +29 -110
170 lines not on this page · raw message
arch/mips/configs/cavium_octeon_defconfig +0 -1
@@ -157,7 +157,6 @@ CONFIG_CRYPTO_CBC=y CONFIG_CRYPTO_HMAC=y CONFIG_CRYPTO_MD5_OCTEON=y CONFIG_CRYPTO_SHA1_OCTEON=m -CONFIG_CRYPTO_SHA256_OCTEON=m CONFIG_CRYPTO_SHA512_OCTEON=m CONFIG_CRYPTO_DES=y CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
arch/mips/crypto/Kconfig +0 -10
@@ -22,16 +22,6 @@ config CRYPTO_SHA1_OCTEON Architecture: mips OCTEON -config CRYPTO_SHA256_OCTEON - tristate "Hash functions: SHA-224 and SHA-256 (OCTEON)" - depends on CPU_CAVIUM_OCTEON - select CRYPTO_SHA256 - select CRYPTO_HASH - help - SHA-224 and SHA-256 secure hash algorithms (FIPS 180) - - Architecture: mips OCTEON using crypto instructions, when available - config CRYPTO_SHA512_OCTEON tristate "Hash functions: SHA-384 and SHA-512 (OCTEON)" depends on CPU_CAVIUM_OCTEON
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 6/13 crypto: powerpc/sha256 - implement library instead of shash
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Instead of providing crypto_shash algorithms for the arch-optimized SHA-256 code, instead implement the SHA-256 library. This is much simpler, it makes the SHA-256 library functions be arch-optimized, and it fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default. SHA-256 still remains available through crypto_shash, but individual architectures no longer need to handle it.
---
arch/powerpc/crypto/Kconfig | 11 --
arch/powerpc/crypto/Makefile | 2 -
arch/powerpc/crypto/sha256-spe-glue.c | 128 ------------------
arch/powerpc/lib/crypto/Kconfig | 6 +
arch/powerpc/lib/crypto/Makefile | 3 +
.../powerpc/{ => lib}/crypto/sha256-spe-asm.S | 0
arch/powerpc/lib/crypto/sha256.c | 70 ++++++++++
7 files changed, 79 insertions(+), 141 deletions(-)
delete mode 100644 arch/powerpc/crypto/sha256-spe-glue.c
rename arch/powerpc/{ => lib}/crypto/sha256-spe-asm.S (100%)
create mode 100644 arch/powerpc/lib/crypto/sha256.carch/powerpc/crypto/Kconfig +0 -11
@@ -39,17 +39,6 @@ config CRYPTO_SHA1_PPC_SPE Architecture: powerpc using - SPE (Signal Processing Engine) extensions -config CRYPTO_SHA256_PPC_SPE - tristate "Hash functions: SHA-224 and SHA-256 (SPE)" - depends on SPE - select CRYPTO_SHA256 - select CRYPTO_HASH - help - SHA-224 and SHA-256 secure hash algorithms (FIPS 180) - - Architecture: powerpc using - - SPE (Signal Processing Engine) extensions - config CRYPTO_AES_PPC_SPE tristate "Ciphers: AES, modes: ECB/CBC/CTR/XTS (SPE)" depends on SPE
arch/powerpc/crypto/Makefile +0 -2
@@ -9,7 +9,6 @@ obj-$(CONFIG_CRYPTO_AES_PPC_SPE) += aes-ppc-spe.o obj-$(CONFIG_CRYPTO_MD5_PPC) += md5-ppc.o obj-$(CONFIG_CRYPTO_SHA1_PPC) += sha1-powerpc.o obj-$(CONFIG_CRYPTO_SHA1_PPC_SPE) += sha1-ppc-spe.o -obj-$(CONFIG_CRYPTO_SHA256_PPC_SPE) += sha256-ppc-spe.o obj-$(CONFIG_CRYPTO_AES_GCM_P10) += aes-gcm-p10-crypto.o obj-$(CONFIG_CRYPTO_DEV_VMX_ENCRYPT) += vmx-crypto.o obj-$(CONFIG_CRYPTO_CURVE25519_PPC64) += curve25519-ppc64le.o
@@ -18,7 +17,6 @@ aes-ppc-spe-y := aes-spe-core.o aes-spe-keys.o aes-tab-4k.o aes-spe-modes.o aes- md5-ppc-y := md5-asm.o md5-glue.o sha1-powerpc-y := sha1-powerpc-asm.o sha1.o sha1-ppc-spe-y := sha1-spe-asm.o sha1-spe-glue.o -sha256-ppc-spe-y := sha256-spe-asm.o sha256-spe-glue.o aes-gcm-p10-crypto-y := aes-gcm-p10-glue.o aes-gcm-p10.o ghashp10-ppc.o aesp10-ppc.o vmx-crypto-objs := vmx.o aesp8-ppc.o ghashp8-ppc.o aes.o aes_cbc.o aes_ctr.o aes_xts.o ghash.o curve25519-ppc64le-y := curve25519-ppc64le-core.o curve25519-ppc64le_asm.o
arch/powerpc/crypto/sha256-spe-glue.c deleted +0 -128
128 lines not on this page · raw message
arch/powerpc/lib/crypto/Kconfig +6 -0
@@ -13,3 +13,9 @@ config CRYPTO_POLY1305_P10 default CRYPTO_LIB_POLY1305 select CRYPTO_ARCH_HAVE_LIB_POLY1305 select CRYPTO_LIB_POLY1305_GENERIC + +config CRYPTO_SHA256_PPC_SPE + tristate + depends on SPE + default CRYPTO_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256
arch/powerpc/lib/crypto/Makefile +3 -0
@@ -5,3 +5,6 @@ chacha-p10-crypto-y := chacha-p10-glue.o chacha-p10le-8x.o obj-$(CONFIG_CRYPTO_POLY1305_P10) += poly1305-p10-crypto.o poly1305-p10-crypto-y := poly1305-p10-glue.o poly1305-p10le_64.o + +obj-$(CONFIG_CRYPTO_SHA256_PPC_SPE) += sha256-ppc-spe.o +sha256-ppc-spe-y := sha256.o sha256-spe-asm.o
arch/powerpc/lib/crypto/sha256-spe-asm.S renamed from arch/powerpc/crypto/sha256-spe-asm.S +0 -0
arch/powerpc/lib/crypto/sha256.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 7/13 crypto: riscv/sha256 - implement library instead of shash
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Instead of providing crypto_shash algorithms for the arch-optimized SHA-256 code, instead implement the SHA-256 library. This is much simpler, it makes the SHA-256 library functions be arch-optimized, and it fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default. SHA-256 still remains available through crypto_shash, but individual architectures no longer need to handle it.
To match sha256_blocks_arch(), change the type of the nblocks parameter of the assembly function from int to size_t. The assembly function actually already treated it as size_t.
---
arch/riscv/crypto/Kconfig | 11 --
arch/riscv/crypto/Makefile | 3 -
arch/riscv/crypto/sha256-riscv64-glue.c | 125 ------------------
arch/riscv/lib/crypto/Kconfig | 8 ++
arch/riscv/lib/crypto/Makefile | 3 +
.../sha256-riscv64-zvknha_or_zvknhb-zvkb.S | 4 +-
arch/riscv/lib/crypto/sha256.c | 67 ++++++++++
7 files changed, 80 insertions(+), 141 deletions(-)
delete mode 100644 arch/riscv/crypto/sha256-riscv64-glue.c
rename arch/riscv/{ => lib}/crypto/sha256-riscv64-zvknha_or_zvknhb-zvkb.S (98%)
create mode 100644 arch/riscv/lib/crypto/sha256.carch/riscv/crypto/Kconfig +0 -11
@@ -28,17 +28,6 @@ config CRYPTO_GHASH_RISCV64 Architecture: riscv64 using: - Zvkg vector crypto extension -config CRYPTO_SHA256_RISCV64 - tristate "Hash functions: SHA-224 and SHA-256" - depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO - select CRYPTO_SHA256 - help - SHA-224 and SHA-256 secure hash algorithm (FIPS 180) - - Architecture: riscv64 using: - - Zvknha or Zvknhb vector crypto extensions - - Zvkb vector crypto extension - config CRYPTO_SHA512_RISCV64 tristate "Hash functions: SHA-384 and SHA-512" depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO
arch/riscv/crypto/Makefile +0 -3
@@ -7,9 +7,6 @@ aes-riscv64-y := aes-riscv64-glue.o aes-riscv64-zvkned.o \ obj-$(CONFIG_CRYPTO_GHASH_RISCV64) += ghash-riscv64.o ghash-riscv64-y := ghash-riscv64-glue.o ghash-riscv64-zvkg.o -obj-$(CONFIG_CRYPTO_SHA256_RISCV64) += sha256-riscv64.o -sha256-riscv64-y := sha256-riscv64-glue.o sha256-riscv64-zvknha_or_zvknhb-zvkb.o - obj-$(CONFIG_CRYPTO_SHA512_RISCV64) += sha512-riscv64.o sha512-riscv64-y := sha512-riscv64-glue.o sha512-riscv64-zvknhb-zvkb.o
arch/riscv/crypto/sha256-riscv64-glue.c deleted +0 -125
125 lines not on this page · raw message
arch/riscv/lib/crypto/Kconfig +8 -0
@@ -6,3 +6,11 @@ config CRYPTO_CHACHA_RISCV64 default CRYPTO_LIB_CHACHA select CRYPTO_ARCH_HAVE_LIB_CHACHA select CRYPTO_LIB_CHACHA_GENERIC + +config CRYPTO_SHA256_RISCV64 + tristate + depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO + default CRYPTO_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256_SIMD + select CRYPTO_LIB_SHA256_GENERIC
arch/riscv/lib/crypto/Makefile +3 -0
@@ -2,3 +2,6 @@ obj-$(CONFIG_CRYPTO_CHACHA_RISCV64) += chacha-riscv64.o chacha-riscv64-y := chacha-riscv64-glue.o chacha-riscv64-zvkb.o + +obj-$(CONFIG_CRYPTO_SHA256_RISCV64) += sha256-riscv64.o +sha256-riscv64-y := sha256.o sha256-riscv64-zvknha_or_zvknhb-zvkb.o
arch/riscv/lib/crypto/sha256-riscv64-zvknha_or_zvknhb-zvkb.S renamed from arch/riscv/crypto/sha256-riscv64-zvknha_or_zvknhb-zvkb.S +2 -2
@@ -106,8 +106,8 @@ sha256_4rounds \last, \k3, W3, W0, W1, W2 .endm -// void sha256_transform_zvknha_or_zvknhb_zvkb(u32 state[8], const u8 *data, -// int num_blocks); +// void sha256_transform_zvknha_or_zvknhb_zvkb(u32 state[SHA256_STATE_WORDS], +// const u8 *data, size_t nblocks); SYM_FUNC_START(sha256_transform_zvknha_or_zvknhb_zvkb) // Load the round constants into K0-K15.
arch/riscv/lib/crypto/sha256.c new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 8/13 crypto: s390/sha256 - implement library instead of shash
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Instead of providing crypto_shash algorithms for the arch-optimized SHA-256 code, instead implement the SHA-256 library. This is much simpler, it makes the SHA-256 library functions be arch-optimized, and it fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default. SHA-256 still remains available through crypto_shash, but individual architectures no longer need to handle it.
--- arch/s390/configs/debug_defconfig | 1 - arch/s390/configs/defconfig | 1 - arch/s390/crypto/Kconfig | 10 --- arch/s390/crypto/Makefile | 1 - arch/s390/crypto/sha256_s390.c | 144 ------------------------------ arch/s390/lib/crypto/Kconfig | 6 ++ arch/s390/lib/crypto/Makefile | 2 + arch/s390/lib/crypto/sha256.c | 47 ++++++++++ 8 files changed, 55 insertions(+), 157 deletions(-) delete mode 100644 arch/s390/crypto/sha256_s390.c create mode 100644 arch/s390/lib/crypto/sha256.c
arch/s390/configs/debug_defconfig +0 -1
@@ -795,7 +795,6 @@ CONFIG_CRYPTO_USER_API_RNG=m CONFIG_CRYPTO_USER_API_AEAD=m CONFIG_CRYPTO_SHA512_S390=m CONFIG_CRYPTO_SHA1_S390=m -CONFIG_CRYPTO_SHA256_S390=m CONFIG_CRYPTO_SHA3_256_S390=m CONFIG_CRYPTO_SHA3_512_S390=m CONFIG_CRYPTO_GHASH_S390=m
arch/s390/configs/defconfig +0 -1
@@ -782,7 +782,6 @@ CONFIG_CRYPTO_USER_API_RNG=m CONFIG_CRYPTO_USER_API_AEAD=m CONFIG_CRYPTO_SHA512_S390=m CONFIG_CRYPTO_SHA1_S390=m -CONFIG_CRYPTO_SHA256_S390=m CONFIG_CRYPTO_SHA3_256_S390=m CONFIG_CRYPTO_SHA3_512_S390=m CONFIG_CRYPTO_GHASH_S390=m
arch/s390/crypto/Kconfig +0 -10
@@ -22,16 +22,6 @@ config CRYPTO_SHA1_S390 It is available as of z990. -config CRYPTO_SHA256_S390 - tristate "Hash functions: SHA-224 and SHA-256" - select CRYPTO_HASH - help - SHA-224 and SHA-256 secure hash algorithms (FIPS 180) - - Architecture: s390 - - It is available as of z9. - config CRYPTO_SHA3_256_S390 tristate "Hash functions: SHA3-224 and SHA3-256" select CRYPTO_HASH
arch/s390/crypto/Makefile +0 -1
@@ -4,7 +4,6 @@ # obj-$(CONFIG_CRYPTO_SHA1_S390) += sha1_s390.o sha_common.o -obj-$(CONFIG_CRYPTO_SHA256_S390) += sha256_s390.o sha_common.o obj-$(CONFIG_CRYPTO_SHA512_S390) += sha512_s390.o sha_common.o obj-$(CONFIG_CRYPTO_SHA3_256_S390) += sha3_256_s390.o sha_common.o obj-$(CONFIG_CRYPTO_SHA3_512_S390) += sha3_512_s390.o sha_common.o
arch/s390/crypto/sha256_s390.c deleted +0 -144
144 lines not on this page · raw message
arch/s390/lib/crypto/Kconfig +6 -0
@@ -5,3 +5,9 @@ config CRYPTO_CHACHA_S390 default CRYPTO_LIB_CHACHA select CRYPTO_LIB_CHACHA_GENERIC select CRYPTO_ARCH_HAVE_LIB_CHACHA + +config CRYPTO_SHA256_S390 + tristate + default CRYPTO_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256 + select CRYPTO_LIB_SHA256_GENERIC
arch/s390/lib/crypto/Makefile +2 -0
@@ -2,3 +2,5 @@ obj-$(CONFIG_CRYPTO_CHACHA_S390) += chacha_s390.o chacha_s390-y := chacha-glue.o chacha-s390.o + +obj-$(CONFIG_CRYPTO_SHA256_S390) += sha256.o
arch/s390/lib/crypto/sha256.c new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 9/13 crypto: sparc - move opcodes.h into asm directory
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Since arch/sparc/crypto/opcodes.h is now needed outside the arch/sparc/crypto/ directory, move it into arch/sparc/include/asm/ so that it can be included as <asm/opcodes.h>.
---
arch/sparc/crypto/aes_asm.S | 3 +--
arch/sparc/crypto/aes_glue.c | 3 +--
arch/sparc/crypto/camellia_asm.S | 3 +--
arch/sparc/crypto/camellia_glue.c | 3 +--
arch/sparc/crypto/des_asm.S | 3 +--
arch/sparc/crypto/des_glue.c | 3 +--
arch/sparc/crypto/md5_asm.S | 3 +--
arch/sparc/crypto/md5_glue.c | 3 +--
arch/sparc/crypto/sha1_asm.S | 3 +--
arch/sparc/crypto/sha1_glue.c | 3 +--
arch/sparc/crypto/sha256_asm.S | 3 +--
arch/sparc/crypto/sha256_glue.c | 3 +--
arch/sparc/crypto/sha512_asm.S | 3 +--
arch/sparc/crypto/sha512_glue.c | 3 +--
arch/sparc/{crypto => include/asm}/opcodes.h | 6 +++---
arch/sparc/lib/crc32c_asm.S | 3 +--
16 files changed, 18 insertions(+), 33 deletions(-)
rename arch/sparc/{crypto => include/asm}/opcodes.h (96%)arch/sparc/crypto/aes_asm.S +1 -2
@@ -1,9 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <linux/linkage.h> +#include <asm/opcodes.h> #include <asm/visasm.h> -#include "opcodes.h" - #define ENCRYPT_TWO_ROUNDS(KEY_BASE, I0, I1, T0, T1) \ AES_EROUND01(KEY_BASE + 0, I0, I1, T0) \ AES_EROUND23(KEY_BASE + 2, I0, I1, T1) \
arch/sparc/crypto/aes_glue.c +1 -2
@@ -27,11 +27,10 @@#include <crypto/internal/skcipher.h> #include <asm/fpumacro.h> +#include <asm/opcodes.h> #include <asm/pstate.h> #include <asm/elf.h> -#include "opcodes.h" -struct aes_ops {void (*encrypt)(const u64 *key,const u32 *input,u32 *output);void (*decrypt)(const u64 *key,const u32 *input,u32 *output);
arch/sparc/crypto/camellia_asm.S +1 -2
@@ -1,9 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <linux/linkage.h> +#include <asm/opcodes.h> #include <asm/visasm.h> -#include "opcodes.h" - #define CAMELLIA_6ROUNDS(KEY_BASE, I0, I1) \ CAMELLIA_F(KEY_BASE + 0, I1, I0, I1) \ CAMELLIA_F(KEY_BASE + 2, I0, I1, I0) \
arch/sparc/crypto/camellia_glue.c +1 -2
@@ -15,11 +15,10 @@#include <crypto/internal/skcipher.h> #include <asm/fpumacro.h> +#include <asm/opcodes.h> #include <asm/pstate.h> #include <asm/elf.h> -#include "opcodes.h" -#define CAMELLIA_MIN_KEY_SIZE 16#define CAMELLIA_MAX_KEY_SIZE 32#define CAMELLIA_BLOCK_SIZE 16
arch/sparc/crypto/des_asm.S +1 -2
@@ -1,9 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <linux/linkage.h> +#include <asm/opcodes.h> #include <asm/visasm.h> -#include "opcodes.h" - .align 32 ENTRY(des_sparc64_key_expand) /* %o0=input_key, %o1=output_key */
arch/sparc/crypto/des_glue.c +1 -2
@@ -16,11 +16,10 @@#include <crypto/internal/skcipher.h> #include <asm/fpumacro.h> +#include <asm/opcodes.h> #include <asm/pstate.h> #include <asm/elf.h> -#include "opcodes.h" -struct des_sparc64_ctx {u64 encrypt_expkey[DES_EXPKEY_WORDS /2 ];u64 decrypt_expkey[DES_EXPKEY_WORDS /2 ];
arch/sparc/crypto/md5_asm.S +1 -2
@@ -1,9 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <linux/linkage.h> +#include <asm/opcodes.h> #include <asm/visasm.h> -#include "opcodes.h" - ENTRY(md5_sparc64_transform) /* %o0 = digest, %o1 = data, %o2 = rounds */ VISEntryHalf
arch/sparc/crypto/md5_glue.c +1 -2
@@ -15,6 +15,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <asm/elf.h> +#include <asm/opcodes.h> #include <asm/pstate.h> #include <crypto/internal/hash.h> #include <crypto/md5.h>
@@ -24,8 +25,6 @@#include <linux/string.h> #include <linux/unaligned.h> -#include "opcodes.h" -struct sparc_md5_state {__le32 hash[MD5_HASH_WORDS ];u64 byte_count;
arch/sparc/crypto/sha1_asm.S +1 -2
@@ -1,9 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <linux/linkage.h> +#include <asm/opcodes.h> #include <asm/visasm.h> -#include "opcodes.h" - ENTRY(sha1_sparc64_transform) /* %o0 = digest, %o1 = data, %o2 = rounds */ VISEntryHalf
arch/sparc/crypto/sha1_glue.c +1 -2
@@ -12,6 +12,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <asm/elf.h> +#include <asm/opcodes.h> #include <asm/pstate.h> #include <crypto/internal/hash.h> #include <crypto/sha1.h>
@@ -19,8 +20,6 @@#include <linux/kernel.h> #include <linux/module.h> -#include "opcodes.h" - asmlinkage void sha1_sparc64_transform(struct sha1_state *digest,const u8 *data,int rounds);
arch/sparc/crypto/sha256_asm.S +1 -2
@@ -1,9 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <linux/linkage.h> +#include <asm/opcodes.h> #include <asm/visasm.h> -#include "opcodes.h" - ENTRY(sha256_sparc64_transform) /* %o0 = digest, %o1 = data, %o2 = rounds */ VISEntryHalf
arch/sparc/crypto/sha256_glue.c +1 -2
@@ -12,6 +12,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <asm/elf.h> +#include <asm/opcodes.h> #include <asm/pstate.h> #include <crypto/internal/hash.h> #include <crypto/sha2.h>
@@ -19,8 +20,6 @@#include <linux/kernel.h> #include <linux/module.h> -#include "opcodes.h" - asmlinkage void sha256_sparc64_transform(u32 *digest, const char *data,unsigned int rounds);
arch/sparc/crypto/sha512_asm.S +1 -2
@@ -1,9 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <linux/linkage.h> +#include <asm/opcodes.h> #include <asm/visasm.h> -#include "opcodes.h" - ENTRY(sha512_sparc64_transform) /* %o0 = digest, %o1 = data, %o2 = rounds */ VISEntry
arch/sparc/crypto/sha512_glue.c +1 -2
@@ -11,6 +11,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <asm/elf.h> +#include <asm/opcodes.h> #include <asm/pstate.h> #include <crypto/internal/hash.h> #include <crypto/sha2.h>
@@ -18,8 +19,6 @@#include <linux/kernel.h> #include <linux/module.h> -#include "opcodes.h" - asmlinkage void sha512_sparc64_transform(u64 *digest, const char *data,unsigned int rounds);
arch/sparc/include/asm/opcodes.h renamed from arch/sparc/crypto/opcodes.h +3 -3
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _OPCODES_H -#define _OPCODES_H +#ifndef _SPARC_ASM_OPCODES_H +#define _SPARC_ASM_OPCODES_H#define SPARC_CR_OPCODE_PRIORITY 300
@@ -97,4 +97,4 @@#define MOVXTOD_G7_F62 \ .word 0xbfb02307; -#endif /* _OPCODES_H */ +#endif /* _SPARC_ASM_OPCODES_H */
arch/sparc/lib/crc32c_asm.S +1 -2
@@ -1,10 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <linux/linkage.h> +#include <asm/opcodes.h> #include <asm/visasm.h> #include <asm/asi.h> -#include "../crypto/opcodes.h" - ENTRY(crc32c_sparc64) /* %o0=crc32p, %o1=data_ptr, %o2=len */ VISEntryHalf
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 10/13 crypto: sparc/sha256 - implement library instead of shash
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Instead of providing crypto_shash algorithms for the arch-optimized SHA-256 code, instead implement the SHA-256 library. This is much simpler, it makes the SHA-256 library functions be arch-optimized, and it fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default. SHA-256 still remains available through crypto_shash, but individual architectures no longer need to handle it.
---
arch/sparc/crypto/Kconfig | 10 --
arch/sparc/crypto/Makefile | 2 -
arch/sparc/crypto/sha256_glue.c | 128 -----------------------
arch/sparc/lib/Makefile | 1 +
arch/sparc/lib/crypto/Kconfig | 8 ++
arch/sparc/lib/crypto/Makefile | 4 +
arch/sparc/lib/crypto/sha256.c | 64 ++++++++++++
arch/sparc/{ => lib}/crypto/sha256_asm.S | 2 +-
lib/crypto/Kconfig | 3 +
9 files changed, 81 insertions(+), 141 deletions(-)
delete mode 100644 arch/sparc/crypto/sha256_glue.c
create mode 100644 arch/sparc/lib/crypto/Kconfig
create mode 100644 arch/sparc/lib/crypto/Makefile
create mode 100644 arch/sparc/lib/crypto/sha256.c
rename arch/sparc/{ => lib}/crypto/sha256_asm.S (96%)arch/sparc/crypto/Kconfig +0 -10
@@ -36,16 +36,6 @@ config CRYPTO_SHA1_SPARC64 Architecture: sparc64 -config CRYPTO_SHA256_SPARC64 - tristate "Hash functions: SHA-224 and SHA-256" - depends on SPARC64 - select CRYPTO_SHA256 - select CRYPTO_HASH - help - SHA-224 and SHA-256 secure hash algorithms (FIPS 180) - - Architecture: sparc64 using crypto instructions, when available - config CRYPTO_SHA512_SPARC64 tristate "Hash functions: SHA-384 and SHA-512" depends on SPARC64
arch/sparc/crypto/Makefile +0 -2
@@ -4,7 +4,6 @@ # obj-$(CONFIG_CRYPTO_SHA1_SPARC64) += sha1-sparc64.o -obj-$(CONFIG_CRYPTO_SHA256_SPARC64) += sha256-sparc64.o obj-$(CONFIG_CRYPTO_SHA512_SPARC64) += sha512-sparc64.o obj-$(CONFIG_CRYPTO_MD5_SPARC64) += md5-sparc64.o
@@ -13,7 +12,6 @@ obj-$(CONFIG_CRYPTO_DES_SPARC64) += des-sparc64.o obj-$(CONFIG_CRYPTO_CAMELLIA_SPARC64) += camellia-sparc64.o sha1-sparc64-y := sha1_asm.o sha1_glue.o -sha256-sparc64-y := sha256_asm.o sha256_glue.o sha512-sparc64-y := sha512_asm.o sha512_glue.o md5-sparc64-y := md5_asm.o md5_glue.o
arch/sparc/crypto/sha256_glue.c deleted +0 -128
128 lines not on this page · raw message
arch/sparc/lib/Makefile +1 -0
@@ -4,6 +4,7 @@ asflags-y := -ansi -DST_DIV0=0x02 +obj-y += crypto/ lib-$(CONFIG_SPARC32) += ashrdi3.o lib-$(CONFIG_SPARC32) += memcpy.o memset.o lib-y += strlen.o
arch/sparc/lib/crypto/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config CRYPTO_SHA256_SPARC64 + tristate + depends on SPARC64 + default CRYPTO_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256 + select CRYPTO_LIB_SHA256_GENERIC
arch/sparc/lib/crypto/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_CRYPTO_SHA256_SPARC64) += sha256-sparc64.o +sha256-sparc64-y := sha256.o sha256_asm.o
arch/sparc/lib/crypto/sha256.c new file +64 -0
64 lines not on this page · raw message
arch/sparc/lib/crypto/sha256_asm.S renamed from arch/sparc/crypto/sha256_asm.S +1 -1
@@ -4,7 +4,7 @@ #include <asm/visasm.h> ENTRY(sha256_sparc64_transform) - /* %o0 = digest, %o1 = data, %o2 = rounds */ + /* %o0 = state, %o1 = data, %o2 = nblocks */ VISEntryHalf ld [%o0 + 0x00], %f0 ld [%o0 + 0x04], %f1
lib/crypto/Kconfig +3 -0
@@ -189,6 +189,9 @@ endif if S390 source "arch/s390/lib/crypto/Kconfig" endif +if SPARC +source "arch/sparc/lib/crypto/Kconfig" +endif if X86 source "arch/x86/lib/crypto/Kconfig" endif
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 11/13 crypto: x86/sha256 - implement library instead of shash
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Instead of providing crypto_shash algorithms for the arch-optimized SHA-256 code, instead implement the SHA-256 library. This is much simpler, it makes the SHA-256 library functions be arch-optimized, and it fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default. SHA-256 still remains available through crypto_shash, but individual architectures no longer need to handle it.
To match sha256_blocks_arch(), change the type of the nblocks parameter of the assembly functions from int to size_t. The assembly functions actually already treated it as size_t.
---
arch/x86/crypto/Kconfig | 14 -
arch/x86/crypto/Makefile | 3 -
arch/x86/crypto/sha256_ssse3_glue.c | 432 ------------------
arch/x86/lib/crypto/Kconfig | 8 +
arch/x86/lib/crypto/Makefile | 3 +
arch/x86/{ => lib}/crypto/sha256-avx-asm.S | 12 +-
arch/x86/{ => lib}/crypto/sha256-avx2-asm.S | 12 +-
.../crypto/sha256-ni-asm.S} | 36 +-
arch/x86/{ => lib}/crypto/sha256-ssse3-asm.S | 14 +-
arch/x86/lib/crypto/sha256.c | 80 ++++
10 files changed, 125 insertions(+), 489 deletions(-)
delete mode 100644 arch/x86/crypto/sha256_ssse3_glue.c
rename arch/x86/{ => lib}/crypto/sha256-avx-asm.S (98%)
rename arch/x86/{ => lib}/crypto/sha256-avx2-asm.S (98%)
rename arch/x86/{crypto/sha256_ni_asm.S => lib/crypto/sha256-ni-asm.S} (85%)
rename arch/x86/{ => lib}/crypto/sha256-ssse3-asm.S (98%)
create mode 100644 arch/x86/lib/crypto/sha256.carch/x86/crypto/Kconfig +0 -14
@@ -390,20 +390,6 @@ config CRYPTO_SHA1_SSSE3 - AVX2 (Advanced Vector Extensions 2) - SHA-NI (SHA Extensions New Instructions) -config CRYPTO_SHA256_SSSE3 - tristate "Hash functions: SHA-224 and SHA-256 (SSSE3/AVX/AVX2/SHA-NI)" - depends on 64BIT - select CRYPTO_SHA256 - select CRYPTO_HASH - help - SHA-224 and SHA-256 secure hash algorithms (FIPS 180) - - Architecture: x86_64 using: - - SSSE3 (Supplemental SSE3) - - AVX (Advanced Vector Extensions) - - AVX2 (Advanced Vector Extensions 2) - - SHA-NI (SHA Extensions New Instructions) - config CRYPTO_SHA512_SSSE3 tristate "Hash functions: SHA-384 and SHA-512 (SSSE3/AVX/AVX2)" depends on 64BIT
arch/x86/crypto/Makefile +0 -3
@@ -54,9 +54,6 @@ endif obj-$(CONFIG_CRYPTO_SHA1_SSSE3) += sha1-ssse3.o sha1-ssse3-y := sha1_avx2_x86_64_asm.o sha1_ssse3_asm.o sha1_ni_asm.o sha1_ssse3_glue.o -obj-$(CONFIG_CRYPTO_SHA256_SSSE3) += sha256-ssse3.o -sha256-ssse3-y := sha256-ssse3-asm.o sha256-avx-asm.o sha256-avx2-asm.o sha256_ni_asm.o sha256_ssse3_glue.o - obj-$(CONFIG_CRYPTO_SHA512_SSSE3) += sha512-ssse3.o sha512-ssse3-y := sha512-ssse3-asm.o sha512-avx-asm.o sha512-avx2-asm.o sha512_ssse3_glue.o
arch/x86/crypto/sha256_ssse3_glue.c deleted +0 -432
432 lines not on this page · raw message
arch/x86/lib/crypto/Kconfig +8 -0
@@ -24,3 +24,11 @@ config CRYPTO_POLY1305_X86_64 depends on 64BIT default CRYPTO_LIB_POLY1305 select CRYPTO_ARCH_HAVE_LIB_POLY1305 + +config CRYPTO_SHA256_X86_64 + tristate + depends on 64BIT + default CRYPTO_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256 + select CRYPTO_ARCH_HAVE_LIB_SHA256_SIMD + select CRYPTO_LIB_SHA256_GENERIC
arch/x86/lib/crypto/Makefile +3 -0
@@ -10,6 +10,9 @@ obj-$(CONFIG_CRYPTO_POLY1305_X86_64) += poly1305-x86_64.o poly1305-x86_64-y := poly1305-x86_64-cryptogams.o poly1305_glue.o targets += poly1305-x86_64-cryptogams.S +obj-$(CONFIG_CRYPTO_SHA256_X86_64) += sha256-x86_64.o +sha256-x86_64-y := sha256.o sha256-ssse3-asm.o sha256-avx-asm.o sha256-avx2-asm.o sha256-ni-asm.o + quiet_cmd_perlasm = PERLASM $@ cmd_perlasm = $(PERL) $< > $@
arch/x86/lib/crypto/sha256-avx-asm.S renamed from arch/x86/crypto/sha256-avx-asm.S +6 -6
@@ -48,7 +48,7 @@ ######################################################################## #include <linux/linkage.h> -#include <linux/cfi_types.h> +#include <linux/objtool.h> ## assume buffers not aligned #define VMOVDQ vmovdqu
@@ -341,13 +341,13 @@ a = TMP_ .endm ######################################################################## -## void sha256_transform_avx(state sha256_state *state, const u8 *data, int blocks) -## arg 1 : pointer to state -## arg 2 : pointer to input data -## arg 3 : Num blocks +## void sha256_transform_avx(u32 state[SHA256_STATE_WORDS], +## const u8 *data, size_t nblocks); ######################################################################## .text -SYM_TYPED_FUNC_START(sha256_transform_avx) +SYM_FUNC_START(sha256_transform_avx) + ANNOTATE_NOENDBR # since this is called only via static_call + pushq %rbx pushq %r12 pushq %r13
arch/x86/lib/crypto/sha256-avx2-asm.S renamed from arch/x86/crypto/sha256-avx2-asm.S +6 -6
@@ -49,7 +49,7 @@ ######################################################################## #include <linux/linkage.h> -#include <linux/cfi_types.h> +#include <linux/objtool.h> ## assume buffers not aligned #define VMOVDQ vmovdqu
@@ -518,13 +518,13 @@ STACK_SIZE = _CTX + _CTX_SIZE .endm ######################################################################## -## void sha256_transform_rorx(struct sha256_state *state, const u8 *data, int blocks) -## arg 1 : pointer to state -## arg 2 : pointer to input data -## arg 3 : Num blocks +## void sha256_transform_rorx(u32 state[SHA256_STATE_WORDS], +## const u8 *data, size_t nblocks); ######################################################################## .text -SYM_TYPED_FUNC_START(sha256_transform_rorx) +SYM_FUNC_START(sha256_transform_rorx) + ANNOTATE_NOENDBR # since this is called only via static_call + pushq %rbx pushq %r12 pushq %r13
arch/x86/lib/crypto/sha256-ni-asm.S renamed from arch/x86/crypto/sha256_ni_asm.S +16 -20
@@ -54,9 +54,9 @@ */ #include <linux/linkage.h> -#include <linux/cfi_types.h> +#include <linux/objtool.h> -#define DIGEST_PTR %rdi /* 1st arg */ +#define STATE_PTR %rdi /* 1st arg */ #define DATA_PTR %rsi /* 2nd arg */ #define NUM_BLKS %rdx /* 3rd arg */
@@ -98,24 +98,20 @@ .endm /* - * Intel SHA Extensions optimized implementation of a SHA-256 update function + * Intel SHA Extensions optimized implementation of a SHA-256 block function * - * The function takes a pointer to the current hash values, a pointer to the - * input data, and a number of 64 byte blocks to process. Once all blocks have - * been processed, the digest pointer is updated with the resulting hash value. - * The function only processes complete blocks, there is no functionality to - * store partial blocks. All message padding and hash value initialization must - * be done outside the update function. + * This function takes a pointer to the current SHA-256 state, a pointer to the + * input data, and the number of 64-byte blocks to process. Once all blocks + * have been processed, the state is updated with the new state. This function + * only processes complete blocks. State initialization, buffering of partial + * blocks, and digest finalization is expected to be handled elsewhere. * - * void sha256_ni_transform(uint32_t *digest, const void *data, - uint32_t numBlocks); - * digest : pointer to digest - * data: pointer to input data - * numBlocks: Number of blocks to process + * void sha256_ni_transform(u32 state[SHA256_STATE_WORDS], + * const u8 *data, size_t nblocks); */ - .text -SYM_TYPED_FUNC_START(sha256_ni_transform) +SYM_FUNC_START(sha256_ni_transform) + ANNOTATE_NOENDBR # since this is called only via static_call shl $6, NUM_BLKS /* convert to bytes */ jz .Ldone_hash
@@ -126,8 +122,8 @@ SYM_TYPED_FUNC_START(sha256_ni_transform) * Need to reorder these appropriately * DCBA, HGFE -> ABEF, CDGH */ - movdqu 0*16(DIGEST_PTR), STATE0 /* DCBA */ - movdqu 1*16(DIGEST_PTR), STATE1 /* HGFE */ + movdqu 0*16(STATE_PTR), STATE0 /* DCBA */ + movdqu 1*16(STATE_PTR), STATE1 /* HGFE */ movdqa STATE0, TMP punpcklqdq STATE1, STATE0 /* FEBA */
@@ -166,8 +162,8 @@ SYM_TYPED_FUNC_START(sha256_ni_transform) pshufd $0xB1, STATE0, STATE0 /* HGFE */ pshufd $0x1B, STATE1, STATE1 /* DCBA */ - movdqu STATE1, 0*16(DIGEST_PTR) - movdqu STATE0, 1*16(DIGEST_PTR) + movdqu STATE1, 0*16(STATE_PTR) + movdqu STATE0, 1*16(STATE_PTR) .Ldone_hash:
arch/x86/lib/crypto/sha256-ssse3-asm.S renamed from arch/x86/crypto/sha256-ssse3-asm.S +6 -8
@@ -47,7 +47,7 @@ ######################################################################## #include <linux/linkage.h> -#include <linux/cfi_types.h> +#include <linux/objtool.h> ## assume buffers not aligned #define MOVDQ movdqu
@@ -348,15 +348,13 @@ a = TMP_ .endm ######################################################################## -## void sha256_transform_ssse3(struct sha256_state *state, const u8 *data, -## int blocks); -## arg 1 : pointer to state -## (struct sha256_state is assumed to begin with u32 state[8]) -## arg 2 : pointer to input data -## arg 3 : Num blocks +## void sha256_transform_ssse3(u32 state[SHA256_STATE_WORDS], +## const u8 *data, size_t nblocks); ######################################################################## .text -SYM_TYPED_FUNC_START(sha256_transform_ssse3) +SYM_FUNC_START(sha256_transform_ssse3) + ANNOTATE_NOENDBR # since this is called only via static_call + pushq %rbx pushq %r12 pushq %r13
arch/x86/lib/crypto/sha256.c new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 12/13 crypto: sha256 - remove sha256_base.h
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
sha256_base.h is no longer used, so remove it.
--- include/crypto/sha256_base.h | 151 ----------------------------------- 1 file changed, 151 deletions(-) delete mode 100644 include/crypto/sha256_base.h
include/crypto/sha256_base.h deleted +0 -151
@@ -1,151 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* sha256_base.h - core logic for SHA-256 implementations -* -* Copyright (C) 2015 Linaro Ltd <[email protected]> -*/ - -#ifndef _CRYPTO_SHA256_BASE_H -#define _CRYPTO_SHA256_BASE_H - -#include <crypto/internal/blockhash.h> -#include <crypto/internal/hash.h> -#include <crypto/internal/sha2.h> -#include <linux/math.h> -#include <linux/string.h> -#include <linux/types.h> -#include <linux/unaligned.h> - -typedef void (sha256_block_fn )(struct crypto_sha256_state *sst,u8 const *src, -int blocks); - -static inline int sha224_base_init (struct shash_desc *desc) -{ -struct sha256_state *sctx =shash_desc_ctx (desc); - -sha224_init (sctx); -return 0 ; -} - -static inline int sha256_base_init (struct shash_desc *desc) -{ -struct sha256_state *sctx =shash_desc_ctx (desc); - -sha256_init (sctx); -return 0 ; -} - -static inline int lib_sha256_base_do_update (struct sha256_state *sctx, -const u8 *data, -unsigned int len, -sha256_block_fn *block_fn) -{ -unsigned int partial = sctx->count %SHA256_BLOCK_SIZE ; - - sctx->count += len; -BLOCK_HASH_UPDATE_BLOCKS (block_fn, &sctx->ctx, data, len, -SHA256_BLOCK_SIZE , sctx->buf, partial); -return 0 ; -} - -static inline int lib_sha256_base_do_update_blocks ( -struct crypto_sha256_state *sctx,const u8 *data,unsigned int len, -sha256_block_fn *block_fn) -{ -unsigned int remain = len -round_down (len,SHA256_BLOCK_SIZE ); - - sctx->count += len - remain; -block_fn (sctx, data, len /SHA256_BLOCK_SIZE ); -return remain; -} - -static inline int sha256_base_do_update_blocks ( -struct shash_desc *desc,const u8 *data,unsigned int len, -sha256_block_fn *block_fn) -{ -return lib_sha256_base_do_update_blocks (shash_desc_ctx (desc), data, - len, block_fn); -} - -static inline int lib_sha256_base_do_finup (struct crypto_sha256_state *sctx, -const u8 *src,unsigned int len, -sha256_block_fn *block_fn) -{ -unsigned int bit_offset =SHA256_BLOCK_SIZE /8 -1 ; -union { -__be64 b64[SHA256_BLOCK_SIZE /4 ]; -u8 u8[SHA256_BLOCK_SIZE *2 ]; - } block = {}; - -if (len >= bit_offset *8 ) - bit_offset +=SHA256_BLOCK_SIZE /8 ; -memcpy (&block, src, len); - block.u8[len] =0x80 ; - sctx->count += len; - block.b64[bit_offset] =cpu_to_be64 (sctx->count <<3 ); -block_fn (sctx, block.u8, (bit_offset +1 ) *8 /SHA256_BLOCK_SIZE ); -memzero_explicit (&block,sizeof (block)); - -return 0 ; -} - -static inline int sha256_base_do_finup (struct shash_desc *desc, -const u8 *src,unsigned int len, -sha256_block_fn *block_fn) -{ -struct crypto_sha256_state *sctx =shash_desc_ctx (desc); - -if (len >=SHA256_BLOCK_SIZE ) { -int remain; - - remain =lib_sha256_base_do_update_blocks (sctx, src, len, - block_fn); - src += len - remain; - len = remain; - } -return lib_sha256_base_do_finup (sctx, src, len, block_fn); -} - -static inline int lib_sha256_base_do_finalize (struct sha256_state *sctx, -sha256_block_fn *block_fn) -{ -unsigned int partial = sctx->count %SHA256_BLOCK_SIZE ; -struct crypto_sha256_state *state = (void *)sctx; - - sctx->count -= partial; -return lib_sha256_base_do_finup (state, sctx->buf, partial, block_fn); -} - -static inline int __sha256_base_finish (u32 state[SHA256_DIGEST_SIZE /4 ], -u8 *out,unsigned int digest_size) -{ -__be32 *digest = (__be32 *)out; -int i; - -for (i =0 ; digest_size >0 ; i++, digest_size -=sizeof (__be32)) -put_unaligned_be32 (state[i], digest++); -return 0 ; -} - -static inline void lib_sha256_base_finish (struct sha256_state *sctx,u8 *out, -unsigned int digest_size) -{ -__sha256_base_finish (sctx->state, out, digest_size); -memzero_explicit (sctx,sizeof (*sctx)); -} - -static inline int sha256_base_finish (struct shash_desc *desc,u8 *out) -{ -unsigned int digest_size =crypto_shash_digestsize (desc->tfm); -struct crypto_sha256_state *sctx =shash_desc_ctx (desc); - -return __sha256_base_finish (sctx->state, out, digest_size); -} - -static inline void sha256_transform_blocks (struct crypto_sha256_state *sst, -const u8 *input,int blocks) -{ -sha256_blocks_generic (sst->state, input, blocks); -} - -#endif /* _CRYPTO_SHA256_BASE_H */
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v3 13/13 crypto: lib/sha256 - improve function prototypes
In reply to Herbert XuFrom: Eric Biggers <[email protected]>
Follow best practices by changing the length parameters to size_t and explicitly specifying the length of the output digest arrays.
--- include/crypto/internal/sha2.h | 2 +- include/crypto/sha2.h | 8 ++++---- lib/crypto/sha256.c | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-)
include/crypto/internal/sha2.h +1 -1
@@ -46,7 +46,7 @@ static inline void sha256_choose_blocks( static __always_inline void sha256_finup(struct crypto_sha256_state *sctx,const u8 *src,unsigned int len, -u8 *out,size_t digest_size,bool force_generic, +u8 out[SHA256_DIGEST_SIZE ],size_t digest_size,bool force_generic,bool force_simd) {unsigned int bit_offset =SHA256_BLOCK_SIZE /8 -1 ;
include/crypto/sha2.h +4 -4
@@ -105,9 +105,9 @@ static inline void sha256_init(struct sha256_state *sctx) {sha256_block_init (&sctx->ctx); } -void sha256_update (struct sha256_state *sctx,const u8 *data,unsigned int len); -void sha256_final (struct sha256_state *sctx,u8 *out); -void sha256 (const u8 *data,unsigned int len,u8 *out); +void sha256_update (struct sha256_state *sctx,const u8 *data,size_t len); +void sha256_final (struct sha256_state *sctx,u8 out[SHA256_DIGEST_SIZE ]); +void sha256 (const u8 *data,size_t len,u8 out[SHA256_DIGEST_SIZE ]);static inline void sha224_block_init (struct crypto_sha256_state *sctx) {
@@ -127,6 +127,6 @@ static inline void sha224_init(struct sha256_state *sctx) sha224_block_init(&sctx->ctx); }/* Simply use sha256_update as it is equivalent to sha224_update. */ -void sha224_final (struct sha256_state *sctx,u8 *out); +void sha224_final (struct sha256_state *sctx,u8 out[SHA224_DIGEST_SIZE ]);#endif /* _CRYPTO_SHA2_H */
lib/crypto/sha256.c +6 -6
@@ -33,7 +33,7 @@ static inline void sha256_blocks(u32 state[SHA256_STATE_WORDS], const u8 *data, sha256_force_generic(), false); } -void sha256_update (struct sha256_state *sctx,const u8 *data,unsigned int len) +void sha256_update (struct sha256_state *sctx,const u8 *data,size_t len) {size_t partial = sctx->count %SHA256_BLOCK_SIZE ;
@@ -43,8 +43,8 @@ void sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len) }EXPORT_SYMBOL (sha256_update); -static void __sha256_final (struct sha256_state *sctx,u8 *out, -size_t digest_size) +static void __sha256_final (struct sha256_state *sctx, +u8 out[SHA256_DIGEST_SIZE ],size_t digest_size) {unsigned int len = sctx->count %SHA256_BLOCK_SIZE ;
@@ -54,19 +54,19 @@ static void __sha256_final(struct sha256_state *sctx, u8 *out,memzero_explicit (sctx,sizeof (*sctx)); } -void sha256_final (struct sha256_state *sctx,u8 *out) +void sha256_final (struct sha256_state *sctx,u8 out[SHA256_DIGEST_SIZE ]) {__sha256_final (sctx, out,SHA256_DIGEST_SIZE ); }EXPORT_SYMBOL (sha256_final); -void sha224_final (struct sha256_state *sctx,u8 *out) +void sha224_final (struct sha256_state *sctx,u8 out[SHA224_DIGEST_SIZE ]) {__sha256_final (sctx, out,SHA224_DIGEST_SIZE ); }EXPORT_SYMBOL (sha224_final); -void sha256 (const u8 *data,unsigned int len,u8 *out) +void sha256 (const u8 *data,size_t len,u8 out[SHA256_DIGEST_SIZE ]) {struct sha256_state sctx;
Signature · 1 line
2.39.5
Eric Biggers
maintainerQuoted 31 lines · Herbert Xu
Changes in v3:
- Add shash sha256-lib/sha224-lib to provide test coverage for libsha256.This is based on
https://patchwork.kernel.org/project/linux-crypto/list/?series=957558Original description:
Following the example of several other algorithms (e.g. CRC32, ChaCha, Poly1305, BLAKE2s), this series refactors the kernel's existing architecture-optimized SHA-256 code to be available via the library API, instead of just via the
crypto_shashAPI as it was before. It also reimplements the SHA-256crypto_shashAPI on top of the library API.This makes it possible to use the SHA-256 library in performance-critical cases. The new design is also much simpler, with a negative diffstat of over 1200 lines. Finally, this also fixes the longstanding issue where the arch-optimized SHA-256 was disabled by default, so people often forgot to enable it.
For now the SHA-256 library is well-covered by the
crypto_shashself-tests, but I plan to add a test for the library directly later. I've fully tested this series on arm, arm64, riscv, and x86. On mips, powerpc, s390, and sparc I've only been able to partially test it, since QEMU does not support the SHA-256 instructions on those platforms. If anyone with access to a mips, powerpc, s390, or sparc system that has SHA-256 instructions can verify that the crypto self-tests still pass, that would be appreciated. But I don't expect any issues, especially since the new code is more straightforward than the old code.
Quoted 14 lines
Eric Biggers (13):
crypto: sha256 - support arch-optimized lib and expose through shash
crypto: arm/sha256 - implement library instead of shash
crypto: arm64/sha256 - remove obsolete chunking logic
crypto: arm64/sha256 - implement library instead of shash
crypto: mips/sha256 - implement library instead of shash
crypto: powerpc/sha256 - implement library instead of shash
crypto: riscv/sha256 - implement library instead of shash
crypto: s390/sha256 - implement library instead of shash
crypto: sparc - moveopcodes.hinto asm directory
crypto: sparc/sha256 - implement library instead of shash
crypto: x86/sha256 - implement library instead of shash
crypto: sha256 - removesha256_base.h
crypto: lib/sha256 - improve function prototypes
To be clear, the objections I have on your v2 patchset still hold. Your unsolicited changes to my patches add unnecessary complexity and redundancy, make the crypto_shash API even harder to use correctly, and also break the build for several architectures. If you're going to again use your maintainer privileges to push these out anyway over my objections, I'd appreciate it if you at least made your dubious changes as incremental patches using your own authorship so that they can be properly reviewed/blamed.
Please also note that I've sent a v4 which fixes the one real issue that my v1 patchset had: https://lore.kernel.org/r/[email protected]
- Eric
Herbert Xu
maintainerQuoted 8 lines · Eric Biggers
To be clear, the objections I have on your v2 patchset still hold. Your unsolicited changes to my patches add unnecessary complexity and redundancy, make the
crypto_shashAPI even harder to use correctly, and also break the build for several architectures. If you're going to again use your maintainer privileges to push these out anyway over my objections, I'd appreciate it if you at least made your dubious changes as incremental patches using your own authorship so that they can be properly reviewed/blamed.
Well the main problem is that your patch introduces a regression in the shash sha256 code by making its export format differ from other shash sha256 implementations (e.g., padlock-sha).
So your first patch cannot stand as is. What I could do is split up the first patch so that the lib/crypto sha stuff goes in by itself followed by a separate patch replacing the crypto/sha256 code.
Quoted 2 lines
Please also note that I've sent a v4 which fixes the one real issue that my v1 patchset had: https://lore.kernel.org/r/[email protected]
Yes I've seen it but it still has the same issue of changing the shash sha256 export format.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Eric Biggers
maintainerQuoted 18 lines · Herbert Xu
Quoted 8 lines · Eric Biggers
To be clear, the objections I have on your v2 patchset still hold. Your unsolicited changes to my patches add unnecessary complexity and redundancy, make the
crypto_shashAPI even harder to use correctly, and also break the build for several architectures. If you're going to again use your maintainer privileges to push these out anyway over my objections, I'd appreciate it if you at least made your dubious changes as incremental patches using your own authorship so that they can be properly reviewed/blamed.Well the main problem is that your patch introduces a regression in the shash sha256 code by making its export format differ from other shash sha256 implementations (e.g., padlock-sha).
So your first patch cannot stand as is. What I could do is split up the first patch so that the lib/crypto sha stuff goes in by itself followed by a separate patch replacing the
crypto/sha256code.
Quoted 5 lines
Quoted 2 lines
Please also note that I've sent a v4 which fixes the one real issue that my v1 patchset had: https://lore.kernel.org/r/[email protected]
Yes I've seen it but it still has the same issue of changing the shash sha256 export format.
Nothing requires that the export formats be consistent, but also the fact that padlock-sha uses a weird format in the first place is an artificial problem that you introduced just a couple weeks ago. And even if we *must* use the same format as padlock-sha, that can be done by using your crypto_sha256_export_lib and crypto_sha256_import_lib, without all your other changes.
- Eric
Herbert Xu
maintainerQuoted 6 lines · Eric Biggers
Nothing requires that the export formats be consistent, but also the fact that padlock-sha uses a weird format in the first place is an artificial problem that you introduced just a couple weeks ago. And even if we *must* use the same format as padlock-sha, that can be done by using your
crypto_sha256_export_libandcrypto_sha256_import_lib, without all your other changes.
That was just the reason of why I can't take your first patch as is and then add my changes as incremental patches.
I do still want to bypass the partial block handling in lib/crypto.
But alright I will do it like this:
Patch 1 is just your existing patch + my export/import functions.
Then I will add the rest of my changes as incremental patches.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt