SHA-1 library functions
Subsystems (33)
Eric Biggers
maintainercover SHA-1 library functions
This series is also available at:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git sha1-lib-v1
Patches 1-14 reorganize the kernel's SHA-1 code to be consistent with the way the SHA-2 code is now organized:
- Add SHA-1 and HMAC-SHA1 library functions.
- Make the SHA-1 (and HMAC-SHA1) library functions use the existing architecture-optimized SHA-1 code, which is moved into lib/crypto/.
- Reimplement the old-school crypto API's "sha1" and "hmac(sha1)" algorithms on top of the SHA-1 and HMAC-SHA1 library functions.
The diffstat for that part is:
65 files changed, 1052 insertions(+), 1582 deletions(-)
This hopefully should look quite boring and familiar by now, as essentially the same cleanup was already applied to SHA-2.
Patch 15 adds sha1_kunit.
Note that while SHA-1 is a legacy algorithm, it still has many in-kernel users for legacy protocols. So it's not like we'll be able to remove the SHA-1 code from the kernel anytime soon. And some of these users are currently having to jump through some *major* hoops to work around the limitations of the old-school crypto API. The library API greatly simplifies things, and it makes the SHA-1 code consistent with the SHA-2 code. So, IMO it's well worth doing this reorganization of the SHA-1 code, even though SHA-1 is a legacy algorithm.
To show this even more clearly, patches 16-26 convert various users to use the SHA-1 library API (or both SHA-1 and SHA-2, in the case of some users that use both algorithms). The diffstat for that part is:
27 files changed, 169 insertions(+), 903 deletions(-)
For 6.17, I'd like to take patches 1-15 at the most. Patches 16-26 would be for later, and I'll probably resend them individually later for subsystem maintainers to take.
Eric Biggers (26):
crypto: x86/sha1 - Rename conflicting symbol lib/crypto: sha1: Rename sha1_init() to sha1_init_raw() lib/crypto: sha1: Add SHA-1 library functions lib/crypto: sha1: Add HMAC support
crypto: sha1 - Wrap library and add HMAC support
crypto: sha1 - Use same state format as legacy drivers lib/crypto: arm/sha1: Migrate optimized code into library lib/crypto: arm64/sha1: Migrate optimized code into library lib/crypto: mips/sha1: Migrate optimized code into library lib/crypto: powerpc/sha1: Migrate optimized code into library lib/crypto: s390/sha1: Migrate optimized code into library lib/crypto: sparc/sha1: Migrate optimized code into library lib/crypto: x86/sha1: Migrate optimized code into library
crypto: sha1 - Remove sha1_base.h
lib/crypto: tests: Add KUnit tests for SHA-1 and HMAC-SHA1
bpf: Use sha1() instead of sha1_transform() in bpf_prog_calc_tag()
sctp: Use HMAC-SHA1 and HMAC-SHA256 library functions
ipv6: sr: Use HMAC-SHA1 and HMAC-SHA256 library functions
tee: Use SHA-1 library instead of crypto_shash lib/digsig: Use SHA-1 library instead of crypto_shash drm/bridge: it6505: Use SHA-1 library instead of crypto_shash
nfc: s3fwrn5: Use SHA-1 library instead of crypto_shash
ppp: mppe: Use SHA-1 library instead of crypto_shash
KEYS: trusted_tpm1: Use SHA-1 library instead of crypto_shash
ipv6: Switch to higher-level SHA-1 functions lib/crypto: sha1: Remove low-level functions from API
arch/arm/configs/exynos_defconfig | 1 -
arch/arm/configs/milbeaut_m10v_defconfig | 2 -
arch/arm/configs/multi_v7_defconfig | 2 -
arch/arm/configs/omap2plus_defconfig | 1 -
arch/arm/configs/pxa_defconfig | 1 -
arch/arm/crypto/Kconfig | 31 --
arch/arm/crypto/Makefile | 6 -
arch/arm/crypto/sha1-ce-glue.c | 72 ----
arch/arm/crypto/sha1_glue.c | 75 ----
arch/arm/crypto/sha1_neon_glue.c | 83 -----
arch/arm64/configs/defconfig | 1 -
arch/arm64/crypto/Kconfig | 11 -
arch/arm64/crypto/Makefile | 3 -
arch/arm64/crypto/sha1-ce-glue.c | 118 -------
arch/mips/cavium-octeon/crypto/Makefile | 1 -
arch/mips/cavium-octeon/crypto/octeon-sha1.c | 146 --------
arch/mips/configs/cavium_octeon_defconfig | 1 -
arch/mips/crypto/Kconfig | 10 -
arch/powerpc/configs/44x/akebono_defconfig | 1 -
arch/powerpc/configs/powernv_defconfig | 1 -
arch/powerpc/configs/ppc64_defconfig | 1 -
arch/powerpc/crypto/Kconfig | 16 -
arch/powerpc/crypto/Makefile | 4 -
arch/powerpc/crypto/sha1-spe-glue.c | 107 ------
arch/powerpc/crypto/sha1.c | 78 -----
arch/s390/configs/debug_defconfig | 1 -
arch/s390/configs/defconfig | 1 -
arch/s390/crypto/Kconfig | 10 -
arch/s390/crypto/Makefile | 1 -
arch/s390/crypto/sha1_s390.c | 103 ------
arch/sparc/crypto/Kconfig | 10 -
arch/sparc/crypto/Makefile | 2 -
arch/sparc/crypto/sha1_glue.c | 94 -----
arch/x86/crypto/Kconfig | 14 -
arch/x86/crypto/Makefile | 3 -
arch/x86/crypto/sha1_ssse3_glue.c | 324 ------------------
crypto/Makefile | 2 +-
crypto/sha1.c | 201 +++++++++++
crypto/sha1_generic.c | 87 -----
crypto/testmgr.c | 6 +
drivers/crypto/img-hash.c | 2 +-
drivers/gpu/drm/bridge/Kconfig | 3 +-
drivers/gpu/drm/bridge/ite-it6505.c | 33 +-
drivers/net/ppp/Kconfig | 3 +-
drivers/net/ppp/ppp_mppe.c | 109 +-----
drivers/nfc/s3fwrn5/Kconfig | 3 +-
drivers/nfc/s3fwrn5/firmware.c | 17 +-
drivers/tee/Kconfig | 3 +-
drivers/tee/tee_core.c | 55 +--
include/crypto/sha1.h | 186 +++++++++-
include/crypto/sha1_base.h | 82 -----
include/linux/filter.h | 6 -
include/net/sctp/auth.h | 12 +-
include/net/sctp/constants.h | 2 -
include/net/sctp/structs.h | 5 -
include/net/seg6_hmac.h | 12 -
kernel/bpf/core.c | 49 +--
lib/Kconfig | 3 +-
lib/crypto/Kconfig | 14 +
lib/crypto/Makefile | 23 +-
.../crypto/arm}/sha1-armv4-large.S | 0
.../crypto/arm}/sha1-armv7-neon.S | 13 +-
.../crypto => lib/crypto/arm}/sha1-ce-core.S | 4 +-
lib/crypto/arm/sha1.h | 46 +++
.../crypto/arm64}/sha1-ce-core.S | 40 +--
lib/crypto/arm64/sha1.h | 39 +++
lib/crypto/mips/sha1.h | 81 +++++
.../crypto/powerpc}/sha1-powerpc-asm.S | 0
.../crypto/powerpc}/sha1-spe-asm.S | 0
lib/crypto/powerpc/sha1.h | 67 ++++
lib/crypto/s390/sha1.h | 28 ++
lib/crypto/sha1.c | 267 ++++++++++++---
lib/crypto/sparc/sha1.h | 43 +++
.../crypto => lib/crypto/sparc}/sha1_asm.S | 0
lib/crypto/tests/Kconfig | 10 +
lib/crypto/tests/Makefile | 1 +
lib/crypto/tests/sha1-testvecs.h | 212 ++++++++++++
lib/crypto/tests/sha1_kunit.c | 39 +++
.../crypto/x86/sha1-avx2-asm.S | 7 +-
.../crypto/x86/sha1-ni-asm.S | 23 +-
.../crypto/x86/sha1-ssse3-and-avx.S | 13 +-
lib/crypto/x86/sha1.h | 75 ++++
lib/digsig.c | 46 +--
net/ipv6/Kconfig | 6 +-
net/ipv6/addrconf.c | 23 +-
net/ipv6/seg6.c | 7 -
net/ipv6/seg6_hmac.c | 199 ++---------
net/sctp/Kconfig | 15 +-
net/sctp/auth.c | 153 ++-------
net/sctp/socket.c | 10 -
security/keys/trusted-keys/Kconfig | 4 +-
security/keys/trusted-keys/trusted_tpm1.c | 221 ++----------
92 files changed, 1472 insertions(+), 2474 deletions(-)
delete mode 100644 arch/arm/crypto/sha1-ce-glue.c
delete mode 100644 arch/arm/crypto/sha1_glue.c
delete mode 100644 arch/arm/crypto/sha1_neon_glue.c
delete mode 100644 arch/arm64/crypto/sha1-ce-glue.c
delete mode 100644 arch/mips/cavium-octeon/crypto/octeon-sha1.c
delete mode 100644 arch/powerpc/crypto/sha1-spe-glue.c
delete mode 100644 arch/powerpc/crypto/sha1.c
delete mode 100644 arch/s390/crypto/sha1_s390.c
delete mode 100644 arch/sparc/crypto/sha1_glue.c
delete mode 100644 arch/x86/crypto/sha1_ssse3_glue.c
create mode 100644 crypto/sha1.c
delete mode 100644 crypto/sha1_generic.c
delete mode 100644 include/crypto/sha1_base.h
rename {arch/arm/crypto => lib/crypto/arm}/sha1-armv4-large.S (100%)
rename {arch/arm/crypto => lib/crypto/arm}/sha1-armv7-neon.S (98%)
rename {arch/arm/crypto => lib/crypto/arm}/sha1-ce-core.S (96%)
create mode 100644 lib/crypto/arm/sha1.h
rename {arch/arm64/crypto => lib/crypto/arm64}/sha1-ce-core.S (76%)
create mode 100644 lib/crypto/arm64/sha1.h
create mode 100644 lib/crypto/mips/sha1.h
rename {arch/powerpc/crypto => lib/crypto/powerpc}/sha1-powerpc-asm.S (100%)
rename {arch/powerpc/crypto => lib/crypto/powerpc}/sha1-spe-asm.S (100%)
create mode 100644 lib/crypto/powerpc/sha1.h
create mode 100644 lib/crypto/s390/sha1.h
create mode 100644 lib/crypto/sparc/sha1.h
rename {arch/sparc/crypto => lib/crypto/sparc}/sha1_asm.S (100%)
create mode 100644 lib/crypto/tests/sha1-testvecs.h
create mode 100644 lib/crypto/tests/sha1_kunit.c
rename arch/x86/crypto/sha1_avx2_x86_64_asm.S => lib/crypto/x86/sha1-avx2-asm.S (98%)
rename arch/x86/crypto/sha1_ni_asm.S => lib/crypto/x86/sha1-ni-asm.S (90%)
rename arch/x86/crypto/sha1_ssse3_asm.S => lib/crypto/x86/sha1-ssse3-and-avx.S (97%)
create mode 100644 lib/crypto/x86/sha1.hSignature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 1/26 crypto: x86/sha1 - Rename conflicting symbol
Rename x86's sha1_update() to sha1_update_x86(), since it conflicts with the upcoming sha1_update() library function.
Note: the affected code will be superseded by later commits that migrate the arch-optimized SHA-1 code into the library. This commit simply keeps the kernel building for the initial introduction of the library.
--- arch/x86/crypto/sha1_ssse3_glue.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/crypto/sha1_ssse3_glue.c +5 -5
@@ -32,11 +32,11 @@ static const struct x86_cpu_id module_cpu_ids[] = { X86_MATCH_FEATURE(X86_FEATURE_SSSE3, NULL), {} };MODULE_DEVICE_TABLE (x86cpu, module_cpu_ids); -static inline int sha1_update (struct shash_desc *desc,const u8 *data, +static inline int sha1_update_x86 (struct shash_desc *desc,const u8 *data,unsigned int len,sha1_block_fn *sha1_xform) {int remain;/*
@@ -67,11 +67,11 @@ asmlinkage void sha1_transform_ssse3(struct sha1_state *state, const u8 *data, int blocks);static int sha1_ssse3_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -return sha1_update (desc, data, len, sha1_transform_ssse3); +return sha1_update_x86 (desc, data, len, sha1_transform_ssse3); }static int sha1_ssse3_finup (struct shash_desc *desc,const u8 *data,unsigned int len,u8 *out) {
@@ -111,11 +111,11 @@ asmlinkage void sha1_transform_avx(struct sha1_state *state, const u8 *data, int blocks);static int sha1_avx_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -return sha1_update (desc, data, len, sha1_transform_avx); +return sha1_update_x86 (desc, data, len, sha1_transform_avx); }static int sha1_avx_finup (struct shash_desc *desc,const u8 *data,unsigned int len,u8 *out) {
@@ -188,11 +188,11 @@ static inline void sha1_apply_transform_avx2(struct sha1_state *state, }static int sha1_avx2_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -return sha1_update (desc, data, len, sha1_apply_transform_avx2); +return sha1_update_x86 (desc, data, len, sha1_apply_transform_avx2); }static int sha1_avx2_finup (struct shash_desc *desc,const u8 *data,unsigned int len,u8 *out) {
@@ -232,11 +232,11 @@ asmlinkage void sha1_ni_transform(struct sha1_state *digest, const u8 *data, int rounds);static int sha1_ni_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -return sha1_update (desc, data, len, sha1_ni_transform); +return sha1_update_x86 (desc, data, len, sha1_ni_transform); }static int sha1_ni_finup (struct shash_desc *desc,const u8 *data,unsigned int len,u8 *out) {
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 2/26 lib/crypto: sha1: Rename sha1_init() to sha1_init_raw()
In reply to Eric BiggersRename the existing sha1_init() to sha1_init_raw(), since it conflicts with the upcoming library function. This will later be removed, but this keeps the kernel building for the introduction of the library.
--- include/crypto/sha1.h | 2 +- kernel/bpf/core.c | 2 +- lib/crypto/sha1.c | 6 +++--- net/ipv6/addrconf.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
include/crypto/sha1.h +1 -1
@@ -31,9 +31,9 @@ struct sha1_state {* You shouldn't be using SHA-1, and even if you *have* to use SHA-1, this isn't * the correct way to hash something with SHA-1 (use crypto_shash instead). */ #define SHA1_DIGEST_WORDS (SHA1_DIGEST_SIZE / 4)#define SHA1_WORKSPACE_WORDS 16 -void sha1_init (__u32 *buf); +void sha1_init_raw (__u32 *buf);void sha1_transform (__u32 *digest,const char *data,__u32 *W );#endif /* _CRYPTO_SHA1_H */
kernel/bpf/core.c +1 -1
@@ -302,11 +302,11 @@ int bpf_prog_calc_tag(struct bpf_prog *fp) raw =vmalloc (raw_size);if (!raw)return -ENOMEM ; -sha1_init (digest); +sha1_init_raw (digest);memset (ws,0 ,sizeof (ws));/* We need to take out the map fd for the digest calculation * since they are unstable from user space side. */
lib/crypto/sha1.c +3 -3
@@ -122,20 +122,20 @@ void sha1_transform(__u32 *digest, const char *data, __u32 *array) digest[4 ] +=E ; }EXPORT_SYMBOL (sha1_transform);/** -* sha1_init - initialize the vectors for a SHA1 digest +* sha1_init_raw - initialize the vectors for a SHA1 digest * @buf: vector to initialize */ -void sha1_init (__u32 *buf) +void sha1_init_raw (__u32 *buf) { buf[0 ] =0x67452301 ; buf[1 ] =0xefcdab89 ; buf[2 ] =0x98badcfe ; buf[3 ] =0x10325476 ; buf[4 ] =0xc3d2e1f0 ; } -EXPORT_SYMBOL (sha1_init); +EXPORT_SYMBOL (sha1_init_raw);MODULE_DESCRIPTION ("SHA-1 Algorithm" );MODULE_LICENSE ("GPL" );
net/ipv6/addrconf.c +1 -1
@@ -3365,11 +3365,11 @@ static int ipv6_generate_stable_address(struct in6_addr *address,return -1 ; retry:spin_lock_bh (&lock); -sha1_init (digest); +sha1_init_raw (digest);memset (&data,0 ,sizeof (data));memset (workspace,0 ,sizeof (workspace));memcpy (data.hwaddr, idev->dev->perm_addr, idev->dev->addr_len); data.prefix[0 ] = address->s6_addr32[0 ]; data.prefix[1 ] = address->s6_addr32[1 ];
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 3/26 lib/crypto: sha1: Add SHA-1 library functions
In reply to Eric BiggersAdd a library interface for SHA-1, following the SHA-2 one. As was the case with SHA-2, this will be useful for various in-kernel users. The crypto_shash interface will be reimplemented on top of it as well.
--- include/crypto/sha1.h | 60 +++++++++++++++++++++++ lib/crypto/Kconfig | 7 +++ lib/crypto/Makefile | 9 +++- lib/crypto/sha1.c | 110 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 183 insertions(+), 3 deletions(-)
include/crypto/sha1.h +60 -0
@@ -34,6 +34,66 @@ struct sha1_state {#define SHA1_DIGEST_WORDS (SHA1_DIGEST_SIZE / 4)#define SHA1_WORKSPACE_WORDS 16void sha1_init_raw (__u32 *buf);void sha1_transform (__u32 *digest,const char *data,__u32 *W ); +/* State for the SHA-1 compression function */ +struct sha1_block_state { +u32 h[SHA1_DIGEST_SIZE /4 ]; +}; + +/** +* struct sha1_ctx - Context for hashing a message with SHA-1 +* @state: the compression function state +* @bytecount: number of bytes processed so far +* @buf: partial block buffer; bytecount % SHA1_BLOCK_SIZE bytes are valid +*/ +struct sha1_ctx { +struct sha1_block_state state; +u64 bytecount; +u8 buf[SHA1_BLOCK_SIZE ]; +}; + +/** +* sha1_init() - Initialize a SHA-1 context for a new message +* @ctx: the context to initialize +* +* If you don't need incremental computation, consider sha1() instead. +* +* Context: Any context. +*/ +void sha1_init (struct sha1_ctx *ctx); + +/** +* sha1_update() - Update a SHA-1 context with message data +* @ctx: the context to update; must have been initialized +* @data: the message data +* @len: the data length in bytes +* +* This can be called any number of times. +* +* Context: Any context. +*/ +void sha1_update (struct sha1_ctx *ctx,const u8 *data,size_t len); + +/** +* sha1_final() - Finish computing a SHA-1 message digest +* @ctx: the context to finalize; must have been initialized +* @out: (output) the resulting SHA-1 message digest +* +* After finishing, this zeroizes @ctx. So the caller does not need to do it. +* +* Context: Any context. +*/ +void sha1_final (struct sha1_ctx *ctx,u8 out[SHA1_DIGEST_SIZE ]); + +/** +* sha1() - Compute SHA-1 message digest in one shot +* @data: the message data +* @len: the data length in bytes +* @out: (output) the resulting SHA-1 message digest +* +* Context: Any context. +*/ +void sha1 (const u8 *data,size_t len,u8 out[SHA1_DIGEST_SIZE ]); +#endif /* _CRYPTO_SHA1_H */
lib/crypto/Kconfig +7 -0
@@ -137,10 +137,17 @@ config CRYPTO_LIB_CHACHA20POLY1305 select CRYPTO_LIB_POLY1305 select CRYPTO_LIB_UTILS config CRYPTO_LIB_SHA1 tristate + help + The SHA-1 library functions. Select this if your module uses any of + the functions from <crypto/sha1.h>. + +config CRYPTO_LIB_SHA1_ARCH + bool + depends on CRYPTO_LIB_SHA1 && !UML config CRYPTO_LIB_SHA256 tristate help Enable the SHA-256 library interface. This interface may be fulfilled
lib/crypto/Makefile +7 -2
@@ -65,12 +65,17 @@ libpoly1305-y += poly1305.o obj-$(CONFIG_CRYPTO_LIB_POLY1305_GENERIC) += libpoly1305-generic.o libpoly1305-generic-y := poly1305-donna32.o libpoly1305-generic-$(CONFIG_ARCH_SUPPORTS_INT128) := poly1305-donna64.o libpoly1305-generic-y += poly1305-generic.o -obj-$(CONFIG_CRYPTO_LIB_SHA1) += libsha1.o -libsha1-y := sha1.o +################################################################################ + +obj-$(CONFIG_CRYPTO_LIB_SHA1) += libsha1.o +libsha1-y := sha1.o +ifeq ($(CONFIG_CRYPTO_LIB_SHA1_ARCH),y) +CFLAGS_sha1.o += -I$(src)/$(SRCARCH) +endif # CONFIG_CRYPTO_LIB_SHA1_ARCH ################################################################################ obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o libsha256-y := sha256.o
lib/crypto/sha1.c +109 -1
126 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 4/26 lib/crypto: sha1: Add HMAC support
In reply to Eric BiggersAdd HMAC support to the SHA-1 library, again following what was done for SHA-2. Besides providing the basis for a more streamlined "hmac(sha1)" shash, this will also be useful for multiple in-kernel users such as net/sctp/auth.c, net/ipv6/seg6_hmac.c, and security/keys/trusted-keys/trusted_tpm1.c. Those are currently using crypto_shash, but using the library functions would be much simpler.
--- include/crypto/sha1.h | 118 ++++++++++++++++++++++++++++++++++++++++++ lib/crypto/sha1.c | 106 ++++++++++++++++++++++++++++++++++++- 2 files changed, 222 insertions(+), 2 deletions(-)
include/crypto/sha1.h +118 -0
@@ -94,6 +94,124 @@ void sha1_final(struct sha1_ctx *ctx, u8 out[SHA1_DIGEST_SIZE]);* * Context: Any context. */ void sha1 (const u8 *data,size_t len,u8 out[SHA1_DIGEST_SIZE ]); +/** +* struct hmac_sha1_key - Prepared key for HMAC-SHA1 +* @istate: private +* @ostate: private +*/ +struct hmac_sha1_key { +struct sha1_block_state istate; +struct sha1_block_state ostate; +}; + +/** +* struct hmac_sha1_ctx - Context for computing HMAC-SHA1 of a message +* @sha_ctx: private +* @ostate: private +*/ +struct hmac_sha1_ctx { +struct sha1_ctx sha_ctx; +struct sha1_block_state ostate; +}; + +/** +* hmac_sha1_preparekey() - Prepare a key for HMAC-SHA1 +* @key: (output) the key structure to initialize +* @raw_key: the raw HMAC-SHA1 key +* @raw_key_len: the key length in bytes. All key lengths are supported. +* +* Note: the caller is responsible for zeroizing both the struct hmac_sha1_key +* and the raw key once they are no longer needed. +* +* Context: Any context. +*/ +void hmac_sha1_preparekey (struct hmac_sha1_key *key, +const u8 *raw_key,size_t raw_key_len); + +/** +* hmac_sha1_init() - Initialize an HMAC-SHA1 context for a new message +* @ctx: (output) the HMAC context to initialize +* @key: the prepared HMAC key +* +* If you don't need incremental computation, consider hmac_sha1() instead. +* +* Context: Any context. +*/ +void hmac_sha1_init (struct hmac_sha1_ctx *ctx,const struct hmac_sha1_key *key); + +/** +* hmac_sha1_init_usingrawkey() - Initialize an HMAC-SHA1 context for a new +* message, using a raw key +* @ctx: (output) the HMAC context to initialize +* @raw_key: the raw HMAC-SHA1 key +* @raw_key_len: the key length in bytes. All key lengths are supported. +* +* If you don't need incremental computation, consider hmac_sha1_usingrawkey() +* instead. +* +* Context: Any context. +*/ +void hmac_sha1_init_usingrawkey (struct hmac_sha1_ctx *ctx, +const u8 *raw_key,size_t raw_key_len); + +/** +* hmac_sha1_update() - Update an HMAC-SHA1 context with message data +* @ctx: the HMAC context to update; must have been initialized +* @data: the message data +* @data_len: the data length in bytes +* +* This can be called any number of times. +* +* Context: Any context. +*/ +static inline void hmac_sha1_update (struct hmac_sha1_ctx *ctx, +const u8 *data,size_t data_len) +{ +sha1_update (&ctx->sha_ctx, data, data_len); +} + +/** +* hmac_sha1_final() - Finish computing an HMAC-SHA1 value +* @ctx: the HMAC context to finalize; must have been initialized +* @out: (output) the resulting HMAC-SHA1 value +* +* After finishing, this zeroizes @ctx. So the caller does not need to do it. +* +* Context: Any context. +*/ +void hmac_sha1_final (struct hmac_sha1_ctx *ctx,u8 out[SHA1_DIGEST_SIZE ]); + +/** +* hmac_sha1() - Compute HMAC-SHA1 in one shot, using a prepared key +* @key: the prepared HMAC key +* @data: the message data +* @data_len: the data length in bytes +* @out: (output) the resulting HMAC-SHA1 value +* +* If you're using the key only once, consider using hmac_sha1_usingrawkey(). +* +* Context: Any context. +*/ +void hmac_sha1 (const struct hmac_sha1_key *key, +const u8 *data,size_t data_len,u8 out[SHA1_DIGEST_SIZE ]); + +/** +* hmac_sha1_usingrawkey() - Compute HMAC-SHA1 in one shot, using a raw key +* @raw_key: the raw HMAC-SHA1 key +* @raw_key_len: the key length in bytes. All key lengths are supported. +* @data: the message data +* @data_len: the data length in bytes +* @out: (output) the resulting HMAC-SHA1 value +* +* If you're using the key multiple times, prefer to use hmac_sha1_preparekey() +* followed by multiple calls to hmac_sha1() instead. +* +* Context: Any context. +*/ +void hmac_sha1_usingrawkey (const u8 *raw_key,size_t raw_key_len, +const u8 *data,size_t data_len, +u8 out[SHA1_DIGEST_SIZE ]); +#endif /* _CRYPTO_SHA1_H */
lib/crypto/sha1.c +104 -2
159 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 5/26 crypto: sha1 - Wrap library and add HMAC support
In reply to Eric BiggersLike I did for crypto/sha512.c, rework crypto/sha1_generic.c (renamed to crypto/sha1.c) to simply wrap the normal library functions instead of accessing the low-level block function directly. Also add support for HMAC-SHA1, again just wrapping the library functions.
Since the replacement crypto_shash algorithms are implemented using the (potentially arch-optimized) library functions, give them driver names ending with "-lib" rather than "-generic". Update crypto/testmgr.c and an odd driver to take this change in driver name into account.
Note: to see the diff from crypto/sha1_generic.c to crypto/sha1.c, view this commit with 'git show -M10'.
--- crypto/Makefile | 2 +- crypto/sha1.c | 135 ++++++++++++++++++++++++++++++++++++++ crypto/sha1_generic.c | 87 ------------------------ crypto/testmgr.c | 6 ++ drivers/crypto/img-hash.c | 2 +- 5 files changed, 143 insertions(+), 89 deletions(-) create mode 100644 crypto/sha1.c delete mode 100644 crypto/sha1_generic.c
crypto/Makefile +1 -1
@@ -73,11 +73,11 @@ obj-$(CONFIG_CRYPTO_HMAC) += hmac.o obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o obj-$(CONFIG_CRYPTO_NULL) += crypto_null.o 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_SHA1) += sha1.o obj-$(CONFIG_CRYPTO_SHA256) += sha256.o obj-$(CONFIG_CRYPTO_SHA512) += sha512.o obj-$(CONFIG_CRYPTO_SHA3) += sha3_generic.o obj-$(CONFIG_CRYPTO_SM3_GENERIC) += sm3_generic.o obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o
crypto/sha1.c new file +135 -0
135 lines not on this page · raw message
crypto/sha1_generic.c deleted +0 -87
87 lines not on this page · raw message
crypto/testmgr.c +6 -0
@@ -4235,33 +4235,37 @@ static const struct alg_test_desc alg_test_descs[] = { .suite = { .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template) } }, { .alg = "authenc(hmac(sha1),cbc(aes))", + .generic_driver = "authenc(hmac-sha1-lib,cbc(aes-generic))", .test = alg_test_aead, .fips_allowed = 1, .suite = { .aead = __VECS(hmac_sha1_aes_cbc_tv_temp) } }, { .alg = "authenc(hmac(sha1),cbc(des))", + .generic_driver = "authenc(hmac-sha1-lib,cbc(des-generic))", .test = alg_test_aead, .suite = { .aead = __VECS(hmac_sha1_des_cbc_tv_temp) } }, { .alg = "authenc(hmac(sha1),cbc(des3_ede))", + .generic_driver = "authenc(hmac-sha1-lib,cbc(des3_ede-generic))", .test = alg_test_aead, .suite = { .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp) } }, { .alg = "authenc(hmac(sha1),ctr(aes))", .test = alg_test_null, .fips_allowed = 1, }, { .alg = "authenc(hmac(sha1),ecb(cipher_null))", + .generic_driver = "authenc(hmac-sha1-lib,ecb-cipher_null)", .test = alg_test_aead, .suite = { .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp) } }, {
@@ -5120,10 +5124,11 @@ static const struct alg_test_desc alg_test_descs[] = { .suite = { .hash = __VECS(hmac_rmd160_tv_template) } }, { .alg = "hmac(sha1)", + .generic_driver = "hmac-sha1-lib", .test = alg_test_hash, .fips_allowed = 1, .suite = { .hash =__VECS (hmac_sha1_tv_template) }
@@ -5460,10 +5465,11 @@ static const struct alg_test_desc alg_test_descs[] = { .suite = { .akcipher = __VECS(rsa_tv_template) } }, { .alg = "sha1", + .generic_driver = "sha1-lib", .test = alg_test_hash, .fips_allowed = 1, .suite = { .hash =__VECS (sha1_tv_template) }
drivers/crypto/img-hash.c +1 -1
@@ -703,11 +703,11 @@ static int img_hash_cra_md5_init(struct crypto_tfm *tfm)return img_hash_cra_init (tfm,"md5-generic" ); }static int img_hash_cra_sha1_init (struct crypto_tfm *tfm) { -return img_hash_cra_init (tfm,"sha1-generic" ); +return img_hash_cra_init (tfm,"sha1-lib" ); }static int img_hash_cra_sha224_init (struct crypto_tfm *tfm) {return img_hash_cra_init (tfm,"sha224-lib" );
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 6/26 crypto: sha1 - Use same state format as legacy drivers
In reply to Eric BiggersSame as sha256 and sha512: Use the state format that the generic partial block handling code produces, as requested by Herbert, even though this is applicable only to legacy drivers.
--- crypto/sha1.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
crypto/sha1.c +66 -0
@@ -10,10 +10,47 @@#include <crypto/internal/hash.h> #include <crypto/sha1.h> #include <linux/kernel.h> #include <linux/module.h> +/* +* Export and import functions. crypto_shash wants a particular format that +* matches that used by some legacy drivers. It currently is the same as the +* library SHA context, except the value in bytecount must be block-aligned and +* the remainder must be stored in an extra u8 appended to the struct. +*/ + +#define SHA1_SHASH_STATE_SIZE (sizeof(struct sha1_ctx) + 1) +static_assert (sizeof (struct sha1_ctx ) ==sizeof (struct sha1_state )); +static_assert (offsetof(struct sha1_ctx , state) == offsetof(struct sha1_state , state)); +static_assert (offsetof(struct sha1_ctx , bytecount) == offsetof(struct sha1_state , count)); +static_assert (offsetof(struct sha1_ctx , buf) == offsetof(struct sha1_state , buffer)); + +static int __crypto_sha1_export (const struct sha1_ctx *ctx0,void *out) +{ +struct sha1_ctx ctx = *ctx0; +unsigned int partial; +u8 *p = out; + + partial = ctx.bytecount %SHA1_BLOCK_SIZE ; + ctx.bytecount -= partial; +memcpy (p, &ctx,sizeof (ctx)); + p +=sizeof (ctx); + *p = partial; +return 0 ; +} + +static int __crypto_sha1_import (struct sha1_ctx *ctx,const void *in) +{ +const u8 *p = in; + +memcpy (ctx, p,sizeof (*ctx)); + p +=sizeof (*ctx); + ctx->bytecount += *p; +return 0 ; +} +const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE ] = {0xda ,0x39 ,0xa3 ,0xee ,0x5e ,0x6b ,0x4b ,0x0d ,0x32 ,0x55 ,0xbf ,0xef ,0x95 ,0x60 ,0x18 ,0x90 ,0xaf ,0xd8 ,0x07 ,0x09 };
@@ -45,10 +82,20 @@ static int crypto_sha1_digest(struct shash_desc *desc, {sha1 (data, len, out);return 0 ; } +static int crypto_sha1_export (struct shash_desc *desc,void *out) +{ +return __crypto_sha1_export (SHA1_CTX (desc), out); +} + +static int crypto_sha1_import (struct shash_desc *desc,const void *in) +{ +return __crypto_sha1_import (SHA1_CTX (desc), in); +} +#define HMAC_SHA1_KEY (tfm) ((struct hmac_sha1_key *)crypto_shash_ctx(tfm))#define HMAC_SHA1_CTX (desc) ((struct hmac_sha1_ctx *)shash_desc_ctx(desc))static int crypto_hmac_sha1_setkey (struct crypto_shash *tfm,const u8 *raw_key,unsigned int keylen)
@@ -81,10 +128,23 @@ static int crypto_hmac_sha1_digest(struct shash_desc *desc, {hmac_sha1 (HMAC_SHA1_KEY (desc->tfm), data, len, out);return 0 ; } +static int crypto_hmac_sha1_export (struct shash_desc *desc,void *out) +{ +return __crypto_sha1_export (&HMAC_SHA1_CTX (desc)->sha_ctx, out); +} + +static int crypto_hmac_sha1_import (struct shash_desc *desc,const void *in) +{ +struct hmac_sha1_ctx *ctx =HMAC_SHA1_CTX (desc); + + ctx->ostate =HMAC_SHA1_KEY (desc->tfm)->ostate; +return __crypto_sha1_import (&ctx->sha_ctx, in); +} +static struct shash_alg algs[] = { { .base.cra_name ="sha1" , .base.cra_driver_name ="sha1-lib" , .base.cra_priority =300 ,
@@ -93,11 +153,14 @@ static struct shash_alg algs[] = { .digestsize = SHA1_DIGEST_SIZE, .init = crypto_sha1_init, .update = crypto_sha1_update, .final = crypto_sha1_final, .digest = crypto_sha1_digest, + .export = crypto_sha1_export, + .import = crypto_sha1_import, .descsize = sizeof(struct sha1_ctx), + .statesize = SHA1_SHASH_STATE_SIZE, }, { .base.cra_name = "hmac(sha1)", .base.cra_driver_name = "hmac-sha1-lib", .base.cra_priority = 300,
@@ -108,11 +171,14 @@ static struct shash_alg algs[] = { .setkey = crypto_hmac_sha1_setkey, .init = crypto_hmac_sha1_init, .update = crypto_hmac_sha1_update, .final = crypto_hmac_sha1_final, .digest = crypto_hmac_sha1_digest, + .export = crypto_hmac_sha1_export, + .import = crypto_hmac_sha1_import, .descsize = sizeof(struct hmac_sha1_ctx), + .statesize = SHA1_SHASH_STATE_SIZE, }, };static int __init crypto_sha1_mod_init (void ) {
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 7/26 lib/crypto: arm/sha1: Migrate optimized code into library
In reply to Eric BiggersInstead of exposing the arm-optimized SHA-1 code via arm-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be arm-optimized, and it fixes the longstanding issue where the arm-optimized SHA-1 code was disabled by default. SHA-1 still remains available through crypto_shash, but individual architectures no longer need to handle it.
To match sha1_blocks(), 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/arm/configs/exynos_defconfig | 1 -
arch/arm/configs/milbeaut_m10v_defconfig | 2 -
arch/arm/configs/multi_v7_defconfig | 2 -
arch/arm/configs/omap2plus_defconfig | 1 -
arch/arm/configs/pxa_defconfig | 1 -
arch/arm/crypto/Kconfig | 31 -------
arch/arm/crypto/Makefile | 6 --
arch/arm/crypto/sha1-ce-glue.c | 72 ----------------
arch/arm/crypto/sha1_glue.c | 75 -----------------
arch/arm/crypto/sha1_neon_glue.c | 83 -------------------
lib/crypto/Kconfig | 1 +
lib/crypto/Makefile | 5 ++
.../crypto/arm}/sha1-armv4-large.S | 0
.../crypto/arm}/sha1-armv7-neon.S | 13 ++-
.../crypto => lib/crypto/arm}/sha1-ce-core.S | 4 +-
lib/crypto/arm/sha1.h | 46 ++++++++++
16 files changed, 60 insertions(+), 283 deletions(-)
delete mode 100644 arch/arm/crypto/sha1-ce-glue.c
delete mode 100644 arch/arm/crypto/sha1_glue.c
delete mode 100644 arch/arm/crypto/sha1_neon_glue.c
rename {arch/arm/crypto => lib/crypto/arm}/sha1-armv4-large.S (100%)
rename {arch/arm/crypto => lib/crypto/arm}/sha1-armv7-neon.S (98%)
rename {arch/arm/crypto => lib/crypto/arm}/sha1-ce-core.S (96%)
create mode 100644 lib/crypto/arm/sha1.harch/arm/configs/exynos_defconfig +0 -1
@@ -361,11 +361,10 @@ CONFIG_CRYPTO_LZO=m CONFIG_CRYPTO_LZ4=m CONFIG_CRYPTO_USER_API_HASH=m 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_AES_ARM_BS=m CONFIG_CRYPTO_CHACHA20_NEON=m CONFIG_CRYPTO_DEV_EXYNOS_RNG=y CONFIG_CRYPTO_DEV_S5P=y CONFIG_DMA_CMA=y
arch/arm/configs/milbeaut_m10v_defconfig +0 -2
@@ -96,12 +96,10 @@ CONFIG_KEYS=y CONFIG_CRYPTO_SELFTESTS=y # CONFIG_CRYPTO_ECHAINIV is not set CONFIG_CRYPTO_AES=y CONFIG_CRYPTO_SEQIV=m CONFIG_CRYPTO_GHASH_ARM_CE=m -CONFIG_CRYPTO_SHA1_ARM_NEON=m -CONFIG_CRYPTO_SHA1_ARM_CE=m CONFIG_CRYPTO_AES_ARM=m CONFIG_CRYPTO_AES_ARM_BS=m CONFIG_CRYPTO_AES_ARM_CE=m CONFIG_CRYPTO_CHACHA20_NEON=m # CONFIG_CRYPTO_HW is not set
arch/arm/configs/multi_v7_defconfig +0 -2
@@ -1278,12 +1278,10 @@ CONFIG_CRYPTO_USER=m CONFIG_CRYPTO_USER_API_HASH=m CONFIG_CRYPTO_USER_API_SKCIPHER=m CONFIG_CRYPTO_USER_API_RNG=m 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_AES_ARM=m CONFIG_CRYPTO_AES_ARM_BS=m CONFIG_CRYPTO_AES_ARM_CE=m CONFIG_CRYPTO_CHACHA20_NEON=m CONFIG_CRYPTO_DEV_SUN4I_SS=m
arch/arm/configs/omap2plus_defconfig +0 -1
@@ -702,11 +702,10 @@ CONFIG_ROOT_NFS=y CONFIG_NLS_CODEPAGE_437=y CONFIG_NLS_ISO8859_1=y CONFIG_SECURITY=y CONFIG_CRYPTO_MICHAEL_MIC=y CONFIG_CRYPTO_GHASH_ARM_CE=m -CONFIG_CRYPTO_SHA1_ARM_NEON=m CONFIG_CRYPTO_AES_ARM=m CONFIG_CRYPTO_AES_ARM_BS=m CONFIG_CRYPTO_CHACHA20_NEON=m CONFIG_CRYPTO_DEV_OMAP=m CONFIG_CRYPTO_DEV_OMAP_SHAM=m
arch/arm/configs/pxa_defconfig +0 -1
@@ -656,11 +656,10 @@ CONFIG_CRYPTO_TGR192=m CONFIG_CRYPTO_WP512=m CONFIG_CRYPTO_ANUBIS=m CONFIG_CRYPTO_XCBC=m CONFIG_CRYPTO_DEFLATE=y CONFIG_CRYPTO_LZO=y -CONFIG_CRYPTO_SHA1_ARM=m CONFIG_CRYPTO_AES_ARM=m CONFIG_FONTS=y CONFIG_FONT_8x8=y CONFIG_FONT_8x16=y CONFIG_FONT_6x11=y
arch/arm/crypto/Kconfig +0 -31
@@ -60,41 +60,10 @@ config CRYPTO_BLAKE2B_NEON On ARM processors that have NEON support but not the ARMv8 Crypto Extensions, typically this BLAKE2b implementation is much faster than the SHA-2 family and slightly faster than SHA-1. -config CRYPTO_SHA1_ARM - tristate "Hash functions: SHA-1" - select CRYPTO_SHA1 - select CRYPTO_HASH - help - SHA-1 secure hash algorithm (FIPS 180) - - Architecture: arm - -config CRYPTO_SHA1_ARM_NEON - tristate "Hash functions: SHA-1 (NEON)" - depends on KERNEL_MODE_NEON - select CRYPTO_SHA1_ARM - select CRYPTO_SHA1 - select CRYPTO_HASH - help - SHA-1 secure hash algorithm (FIPS 180) - - Architecture: arm using - - NEON (Advanced SIMD) extensions - -config CRYPTO_SHA1_ARM_CE - tristate "Hash functions: SHA-1 (ARMv8 Crypto Extensions)" - depends on KERNEL_MODE_NEON - select CRYPTO_SHA1_ARM - select CRYPTO_HASH - help - SHA-1 secure hash algorithm (FIPS 180) - - Architecture: arm using ARMv8 Crypto Extensions - config CRYPTO_AES_ARM tristate "Ciphers: AES" select CRYPTO_ALGAPI select CRYPTO_AES help
arch/arm/crypto/Makefile +0 -6
@@ -3,25 +3,19 @@ # Arch-specific CryptoAPI modules. # 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_BLAKE2B_NEON) += blake2b-neon.o obj-$(CONFIG_CRYPTO_NHPOLY1305_NEON) += nhpoly1305-neon.o 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_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 blake2b-neon-y := blake2b-neon-core.o blake2b-neon-glue.o -sha1-arm-ce-y := sha1-ce-core.o sha1-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 curve25519-neon-y := curve25519-core.o curve25519-glue.o
arch/arm/crypto/sha1-ce-glue.c deleted +0 -72
72 lines not on this page · raw message
arch/arm/crypto/sha1_glue.c deleted +0 -75
75 lines not on this page · raw message
arch/arm/crypto/sha1_neon_glue.c deleted +0 -83
83 lines not on this page · raw message
lib/crypto/Kconfig +1 -0
@@ -144,10 +144,11 @@ config CRYPTO_LIB_SHA1 the functions from <crypto/sha1.h>. config CRYPTO_LIB_SHA1_ARCH bool depends on CRYPTO_LIB_SHA1 && !UML + default y if ARM config CRYPTO_LIB_SHA256 tristate help Enable the SHA-256 library interface. This interface may be fulfilled
lib/crypto/Makefile +5 -0
@@ -71,10 +71,15 @@ libpoly1305-generic-y += poly1305-generic.o obj-$(CONFIG_CRYPTO_LIB_SHA1) += libsha1.o libsha1-y := sha1.o ifeq ($(CONFIG_CRYPTO_LIB_SHA1_ARCH),y) CFLAGS_sha1.o += -I$(src)/$(SRCARCH) +ifeq ($(CONFIG_ARM),y) +libsha1-y += arm/sha1-armv4-large.o +libsha1-$(CONFIG_KERNEL_MODE_NEON) += arm/sha1-armv7-neon.o \ + arm/sha1-ce-core.o +endif endif # CONFIG_CRYPTO_LIB_SHA1_ARCH ################################################################################ obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o
lib/crypto/arm/sha1-armv4-large.S renamed from arch/arm/crypto/sha1-armv4-large.S +0 -0
lib/crypto/arm/sha1-armv7-neon.S renamed from arch/arm/crypto/sha1-armv7-neon.S +6 -7
@@ -280,22 +280,21 @@ #define WPRECALC_32_79_9(i,W,W_m04,W_m08,W_m12,W_m16,W_m20,W_m24,W_m28) \ vst1.32 {tmp0}, [RWK]; /* - * Transform nblks*64 bytes (nblks*16 32-bit words) at DATA. + * Transform nblocks*64 bytes (nblocks*16 32-bit words) at DATA. * - * unsigned int - * sha1_transform_neon (void *ctx, const unsigned char *data, - * unsigned int nblks) + * void sha1_transform_neon(struct sha1_block_state *state, + * const u8 *data, size_t nblocks); */ .align 3 ENTRY(sha1_transform_neon) /* input: - * r0: ctx, CTX - * r1: data (64*nblks bytes) - * r2: nblks + * r0: state + * r1: data (64*nblocks bytes) + * r2: nblocks */ cmp RNBLKS, #0; beq .Ldo_nothing;
lib/crypto/arm/sha1-ce-core.S renamed from arch/arm/crypto/sha1-ce-core.S +2 -2
@@ -57,12 +57,12 @@ .word 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1 .word 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc .word 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6 /* - * void sha1_ce_transform(struct sha1_state *sst, u8 const *src, - * int blocks); + * void sha1_ce_transform(struct sha1_block_state *state, + * const u8 *data, size_t nblocks); */ ENTRY(sha1_ce_transform) /* load round constants */ adr ip, .Lsha1_rcon vld1.32 {k0-k1}, [ip, :128]!
lib/crypto/arm/sha1.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 8/26 lib/crypto: arm64/sha1: Migrate optimized code into library
In reply to Eric BiggersInstead of exposing the arm64-optimized SHA-1 code via arm64-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be arm64-optimized, and it fixes the longstanding issue where the arm64-optimized SHA-1 code was disabled by default. SHA-1 still remains available through crypto_shash, but individual architectures no longer need to handle it.
Remove support for SHA-1 finalization from 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 sha1_blocks(), change the type of the nblocks parameter and the return value of __sha1_ce_transform() from int to size_t. Update the assembly code accordingly.
---
arch/arm64/configs/defconfig | 1 -
arch/arm64/crypto/Kconfig | 11 --
arch/arm64/crypto/Makefile | 3 -
arch/arm64/crypto/sha1-ce-glue.c | 118 ------------------
lib/crypto/Kconfig | 1 +
lib/crypto/Makefile | 1 +
.../crypto/arm64}/sha1-ce-core.S | 40 ++----
lib/crypto/arm64/sha1.h | 39 ++++++
8 files changed, 51 insertions(+), 163 deletions(-)
delete mode 100644 arch/arm64/crypto/sha1-ce-glue.c
rename {arch/arm64/crypto => lib/crypto/arm64}/sha1-ce-core.S (76%)
create mode 100644 lib/crypto/arm64/sha1.harch/arm64/configs/defconfig +0 -1
@@ -1741,11 +1741,10 @@ CONFIG_CRYPTO_BENCHMARK=m CONFIG_CRYPTO_ECHAINIV=y CONFIG_CRYPTO_MICHAEL_MIC=m CONFIG_CRYPTO_ANSI_CPRNG=y CONFIG_CRYPTO_USER_API_RNG=m CONFIG_CRYPTO_GHASH_ARM64_CE=y -CONFIG_CRYPTO_SHA1_ARM64_CE=y CONFIG_CRYPTO_SHA3_ARM64=m CONFIG_CRYPTO_SM3_ARM64_CE=m CONFIG_CRYPTO_AES_ARM64_CE_BLK=y CONFIG_CRYPTO_AES_ARM64_BS=m CONFIG_CRYPTO_AES_ARM64_CE_CCM=y
arch/arm64/crypto/Kconfig +0 -11
@@ -23,21 +23,10 @@ config CRYPTO_NHPOLY1305_NEON NHPoly1305 hash function (Adiantum) Architecture: arm64 using: - NEON (Advanced SIMD) extensions -config CRYPTO_SHA1_ARM64_CE - tristate "Hash functions: SHA-1 (ARMv8 Crypto Extensions)" - depends on KERNEL_MODE_NEON - select CRYPTO_HASH - select CRYPTO_SHA1 - help - SHA-1 secure hash algorithm (FIPS 180) - - Architecture: arm64 using: - - ARMv8 Crypto Extensions - config CRYPTO_SHA3_ARM64 tristate "Hash functions: SHA-3 (ARMv8.2 Crypto Extensions)" depends on KERNEL_MODE_NEON select CRYPTO_HASH select CRYPTO_SHA3
arch/arm64/crypto/Makefile +0 -3
@@ -3,13 +3,10 @@ # linux/arch/arm64/crypto/Makefile # # Copyright (C) 2014 Linaro Ltd <[email protected]> # -obj-$(CONFIG_CRYPTO_SHA1_ARM64_CE) += sha1-ce.o -sha1-ce-y := sha1-ce-glue.o sha1-ce-core.o - obj-$(CONFIG_CRYPTO_SHA3_ARM64) += sha3-ce.o sha3-ce-y := sha3-ce-glue.o sha3-ce-core.o obj-$(CONFIG_CRYPTO_SM3_NEON) += sm3-neon.o sm3-neon-y := sm3-neon-glue.o sm3-neon-core.o
arch/arm64/crypto/sha1-ce-glue.c deleted +0 -118
118 lines not on this page · raw message
lib/crypto/Kconfig +1 -0
@@ -145,10 +145,11 @@ config CRYPTO_LIB_SHA1 config CRYPTO_LIB_SHA1_ARCH bool depends on CRYPTO_LIB_SHA1 && !UML default y if ARM + default y if ARM64 && KERNEL_MODE_NEON config CRYPTO_LIB_SHA256 tristate help Enable the SHA-256 library interface. This interface may be fulfilled
lib/crypto/Makefile +1 -0
@@ -76,10 +76,11 @@ CFLAGS_sha1.o += -I$(src)/$(SRCARCH) ifeq ($(CONFIG_ARM),y) libsha1-y += arm/sha1-armv4-large.o libsha1-$(CONFIG_KERNEL_MODE_NEON) += arm/sha1-armv7-neon.o \ arm/sha1-ce-core.o endif +libsha1-$(CONFIG_ARM64) += arm64/sha1-ce-core.o endif # CONFIG_CRYPTO_LIB_SHA1_ARCH ################################################################################ obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o
lib/crypto/arm64/sha1-ce-core.S renamed from arch/arm64/crypto/sha1-ce-core.S +10 -30
@@ -60,12 +60,12 @@ movk \tmp, :abs_g1:\val dup \k, \tmp .endm /* - * int __sha1_ce_transform(struct sha1_ce_state *sst, u8 const *src, - * int blocks) + * size_t __sha1_ce_transform(struct sha1_block_state *state, + * const u8 *data, size_t nblocks); */ SYM_FUNC_START(__sha1_ce_transform) /* load round constants */ loadrc k0.4s, 0x5a827999, w6 loadrc k1.4s, 0x6ed9eba1, w6
@@ -74,24 +74,20 @@ SYM_FUNC_START(__sha1_ce_transform) /* load state */ ld1 {dgav.4s}, [x0] ldr dgb, [x0, #16] - /* load sha1_ce_state::finalize */ - ldr_l w4, sha1_ce_offsetof_finalize, x4 - ldr w4, [x0, x4] - /* load input */ 0: ld1 {v8.4s-v11.4s}, [x1], #64 - sub w2, w2, #1 + sub x2, x2, #1 CPU_LE( rev32 v8.16b, v8.16b ) CPU_LE( rev32 v9.16b, v9.16b ) CPU_LE( rev32 v10.16b, v10.16b ) CPU_LE( rev32 v11.16b, v11.16b ) -1: add t0.4s, v8.4s, k0.4s + add t0.4s, v8.4s, k0.4s mov dg0v.16b, dgav.16b add_update c, ev, k0, 8, 9, 10, 11, dgb add_update c, od, k0, 9, 10, 11, 8 add_update c, ev, k0, 10, 11, 8, 9
@@ -118,33 +114,17 @@ CPU_LE( rev32 v11.16b, v11.16b ) /* update state */ add dgbv.2s, dgbv.2s, dg1v.2s add dgav.4s, dgav.4s, dg0v.4s - cbz w2, 2f - cond_yield 3f, x5, x6 - b 0b + /* return early if voluntary preemption is needed */ + cond_yield 1f, x5, x6 - /* - * 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, sha1_ce_offsetof_count, x4 - ldr x4, [x0, x4] - movi v9.2d, #0 - mov x8, #0x80000000 - movi v10.2d, #0 - ror x7, x4, #29 // ror(lsl(x4, 3), 32) - fmov d8, x8 - mov x4, #0 - mov v11.d[0], xzr - mov v11.d[1], x7 - b 1b + /* handled all input blocks? */ + cbnz x2, 0b /* store new state */ -3: st1 {dgav.4s}, [x0] +1: st1 {dgav.4s}, [x0] str dgb, [x0, #16] - mov w0, w2 + mov x0, x2 ret SYM_FUNC_END(__sha1_ce_transform)
lib/crypto/arm64/sha1.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* SHA-1 optimized for ARM64 +* +* Copyright 2025 Google LLC +*/ +#include <asm/neon.h> +#include <asm/simd.h> +#include <linux/cpufeature.h> + +static __ro_after_init DEFINE_STATIC_KEY_FALSE (have_ce); + +asmlinkage size_t __sha1_ce_transform(struct sha1_block_state *state, +const u8 *data,size_t nblocks); + +static void sha1_blocks (struct sha1_block_state *state, +const u8 *data,size_t nblocks) +{ +if (static_branch_likely (&have_ce) &&may_use_simd ()) { +do { +size_t rem; + +kernel_neon_begin (); + rem =__sha1_ce_transform (state, data, nblocks); +kernel_neon_end (); + data += (nblocks - rem) *SHA1_BLOCK_SIZE ; + nblocks = rem; + }while (nblocks); + }else { +sha1_blocks_generic (state, data, nblocks); + } +} + +#define sha1_mod_init_arch sha1_mod_init_arch +static inline void sha1_mod_init_arch (void ) +{ +if (cpu_have_named_feature (SHA1 )) +static_branch_enable (&have_ce); +}
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 9/26 lib/crypto: mips/sha1: Migrate optimized code into library
In reply to Eric BiggersInstead of exposing the mips-optimized SHA-1 code via mips-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be mips-optimized, and it fixes the longstanding issue where the mips-optimized SHA-1 code was disabled by default. SHA-1 still remains available through crypto_shash, but individual architectures no longer need to handle it.
Note: to see the diff from arch/mips/cavium-octeon/crypto/octeon-sha1.c to lib/crypto/mips/sha1.h, view this commit with 'git show -M10'.
--- arch/mips/cavium-octeon/crypto/Makefile | 1 - arch/mips/cavium-octeon/crypto/octeon-sha1.c | 146 ------------------- arch/mips/configs/cavium_octeon_defconfig | 1 - arch/mips/crypto/Kconfig | 10 -- lib/crypto/Kconfig | 1 + lib/crypto/mips/sha1.h | 81 ++++++++++ 6 files changed, 82 insertions(+), 158 deletions(-) delete mode 100644 arch/mips/cavium-octeon/crypto/octeon-sha1.c create mode 100644 lib/crypto/mips/sha1.h
arch/mips/cavium-octeon/crypto/Makefile +0 -1
@@ -4,6 +4,5 @@ # obj-y += octeon-crypto.o obj-$(CONFIG_CRYPTO_MD5_OCTEON) += octeon-md5.o -obj-$(CONFIG_CRYPTO_SHA1_OCTEON) += octeon-sha1.o
arch/mips/cavium-octeon/crypto/octeon-sha1.c deleted +0 -146
146 lines not on this page · raw message
arch/mips/configs/cavium_octeon_defconfig +0 -1
@@ -154,11 +154,10 @@ CONFIG_NLS_UTF8=y CONFIG_SECURITY=y CONFIG_SECURITY_NETWORK=y CONFIG_CRYPTO_CBC=y CONFIG_CRYPTO_HMAC=y CONFIG_CRYPTO_MD5_OCTEON=y -CONFIG_CRYPTO_SHA1_OCTEON=m CONFIG_CRYPTO_DES=y CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y CONFIG_DEBUG_FS=y CONFIG_MAGIC_SYSRQ=y # CONFIG_SCHED_DEBUG is not set
arch/mips/crypto/Kconfig +0 -10
@@ -10,16 +10,6 @@ config CRYPTO_MD5_OCTEON help MD5 message digest algorithm (RFC1321) Architecture: mips OCTEON using crypto instructions, when available -config CRYPTO_SHA1_OCTEON - tristate "Hash functions: SHA-1 (OCTEON)" - depends on CPU_CAVIUM_OCTEON - select CRYPTO_SHA1 - select CRYPTO_HASH - help - SHA-1 secure hash algorithm (FIPS 180) - - Architecture: mips OCTEON - endmenu
lib/crypto/Kconfig +1 -0
@@ -146,10 +146,11 @@ config CRYPTO_LIB_SHA1 config CRYPTO_LIB_SHA1_ARCH bool depends on CRYPTO_LIB_SHA1 && !UML default y if ARM default y if ARM64 && KERNEL_MODE_NEON + default y if MIPS && CPU_CAVIUM_OCTEON config CRYPTO_LIB_SHA256 tristate help Enable the SHA-256 library interface. This interface may be fulfilled
lib/crypto/mips/sha1.h new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 10/26 lib/crypto: powerpc/sha1: Migrate optimized code into library
In reply to Eric BiggersInstead of exposing the powerpc-optimized SHA-1 code via powerpc-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be powerpc-optimized, and it fixes the longstanding issue where the powerpc-optimized SHA-1 code was disabled by default. SHA-1 still remains available through crypto_shash, but individual architectures no longer need to handle it.
Note: to see the diff from arch/powerpc/crypto/sha1-spe-glue.c to lib/crypto/powerpc/sha1.h, view this commit with 'git show -M10'.
---
arch/powerpc/configs/44x/akebono_defconfig | 1 -
arch/powerpc/configs/powernv_defconfig | 1 -
arch/powerpc/configs/ppc64_defconfig | 1 -
arch/powerpc/crypto/Kconfig | 16 ---
arch/powerpc/crypto/Makefile | 4 -
arch/powerpc/crypto/sha1-spe-glue.c | 107 ------------------
arch/powerpc/crypto/sha1.c | 78 -------------
lib/crypto/Kconfig | 1 +
lib/crypto/Makefile | 4 +
.../crypto/powerpc}/sha1-powerpc-asm.S | 0
.../crypto/powerpc}/sha1-spe-asm.S | 0
lib/crypto/powerpc/sha1.h | 67 +++++++++++
12 files changed, 72 insertions(+), 208 deletions(-)
delete mode 100644 arch/powerpc/crypto/sha1-spe-glue.c
delete mode 100644 arch/powerpc/crypto/sha1.c
rename {arch/powerpc/crypto => lib/crypto/powerpc}/sha1-powerpc-asm.S (100%)
rename {arch/powerpc/crypto => lib/crypto/powerpc}/sha1-spe-asm.S (100%)
create mode 100644 lib/crypto/powerpc/sha1.harch/powerpc/configs/44x/akebono_defconfig +0 -1
@@ -126,8 +126,7 @@ CONFIG_XMON_DEFAULT=y CONFIG_PPC_EARLY_DEBUG=y CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW=0x00010000 CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH=0x33f CONFIG_CRYPTO_PCBC=y CONFIG_CRYPTO_MD5=y -CONFIG_CRYPTO_SHA1_PPC=y CONFIG_CRYPTO_DES=y # CONFIG_CRYPTO_HW is not set
arch/powerpc/configs/powernv_defconfig +0 -1
@@ -320,11 +320,10 @@ CONFIG_XMON=y CONFIG_CRYPTO_BENCHMARK=m CONFIG_CRYPTO_PCBC=m CONFIG_CRYPTO_HMAC=y CONFIG_CRYPTO_MD5_PPC=m CONFIG_CRYPTO_MICHAEL_MIC=m -CONFIG_CRYPTO_SHA1_PPC=m CONFIG_CRYPTO_SHA256=y CONFIG_CRYPTO_WP512=m CONFIG_CRYPTO_ANUBIS=m CONFIG_CRYPTO_BLOWFISH=m CONFIG_CRYPTO_CAST6=m
arch/powerpc/configs/ppc64_defconfig +0 -1
@@ -386,11 +386,10 @@ CONFIG_CRYPTO_PCBC=m CONFIG_CRYPTO_MICHAEL_MIC=m CONFIG_CRYPTO_SHA256=y CONFIG_CRYPTO_WP512=m CONFIG_CRYPTO_LZO=m CONFIG_CRYPTO_MD5_PPC=m -CONFIG_CRYPTO_SHA1_PPC=m CONFIG_CRYPTO_AES_GCM_P10=m CONFIG_CRYPTO_DEV_NX=y CONFIG_CRYPTO_DEV_NX_ENCRYPT=m CONFIG_CRYPTO_DEV_VMX=y CONFIG_SYSTEM_TRUSTED_KEYRING=y
arch/powerpc/crypto/Kconfig +0 -16
@@ -21,26 +21,10 @@ config CRYPTO_MD5_PPC help MD5 message digest algorithm (RFC1321) Architecture: powerpc -config CRYPTO_SHA1_PPC - tristate "Hash functions: SHA-1" - help - SHA-1 secure hash algorithm (FIPS 180) - - Architecture: powerpc - -config CRYPTO_SHA1_PPC_SPE - tristate "Hash functions: SHA-1 (SPE)" - depends on SPE - help - SHA-1 secure hash algorithm (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 select CRYPTO_SKCIPHER help
arch/powerpc/crypto/Makefile +0 -4
@@ -5,20 +5,16 @@ # Arch-specific CryptoAPI modules. # 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_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 aes-ppc-spe-y := aes-spe-core.o aes-spe-keys.o aes-tab-4k.o aes-spe-modes.o aes-spe-glue.o 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 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 ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
arch/powerpc/crypto/sha1-spe-glue.c deleted +0 -107
107 lines not on this page · raw message
arch/powerpc/crypto/sha1.c deleted +0 -78
78 lines not on this page · raw message
lib/crypto/Kconfig +1 -0
@@ -147,10 +147,11 @@ config CRYPTO_LIB_SHA1_ARCH bool depends on CRYPTO_LIB_SHA1 && !UML default y if ARM default y if ARM64 && KERNEL_MODE_NEON default y if MIPS && CPU_CAVIUM_OCTEON + default y if PPC config CRYPTO_LIB_SHA256 tristate help Enable the SHA-256 library interface. This interface may be fulfilled
lib/crypto/Makefile +4 -0
@@ -77,10 +77,14 @@ ifeq ($(CONFIG_ARM),y) libsha1-y += arm/sha1-armv4-large.o libsha1-$(CONFIG_KERNEL_MODE_NEON) += arm/sha1-armv7-neon.o \ arm/sha1-ce-core.o endif libsha1-$(CONFIG_ARM64) += arm64/sha1-ce-core.o +ifeq ($(CONFIG_PPC),y) +libsha1-y += powerpc/sha1-powerpc-asm.o +libsha1-$(CONFIG_SPE) += powerpc/sha1-spe-asm.o +endif endif # CONFIG_CRYPTO_LIB_SHA1_ARCH ################################################################################ obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o
lib/crypto/powerpc/sha1-powerpc-asm.S renamed from arch/powerpc/crypto/sha1-powerpc-asm.S +0 -0
lib/crypto/powerpc/sha1-spe-asm.S renamed from arch/powerpc/crypto/sha1-spe-asm.S +0 -0
lib/crypto/powerpc/sha1.h new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 11/26 lib/crypto: s390/sha1: Migrate optimized code into library
In reply to Eric BiggersInstead of exposing the s390-optimized SHA-1 code via s390-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be s390-optimized, and it fixes the longstanding issue where the s390-optimized SHA-1 code was disabled by default. SHA-1 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/sha1_s390.c | 103 ------------------------------ lib/crypto/Kconfig | 1 + lib/crypto/s390/sha1.h | 28 ++++++++ 7 files changed, 29 insertions(+), 116 deletions(-) delete mode 100644 arch/s390/crypto/sha1_s390.c create mode 100644 lib/crypto/s390/sha1.h
arch/s390/configs/debug_defconfig +0 -1
@@ -802,11 +802,10 @@ CONFIG_CRYPTO_ZSTD=m CONFIG_CRYPTO_ANSI_CPRNG=m CONFIG_CRYPTO_USER_API_HASH=m CONFIG_CRYPTO_USER_API_SKCIPHER=m CONFIG_CRYPTO_USER_API_RNG=m CONFIG_CRYPTO_USER_API_AEAD=m -CONFIG_CRYPTO_SHA1_S390=m CONFIG_CRYPTO_SHA3_256_S390=m CONFIG_CRYPTO_SHA3_512_S390=m CONFIG_CRYPTO_GHASH_S390=m CONFIG_CRYPTO_AES_S390=m CONFIG_CRYPTO_DES_S390=m
arch/s390/configs/defconfig +0 -1
@@ -789,11 +789,10 @@ CONFIG_CRYPTO_ANSI_CPRNG=m CONFIG_CRYPTO_JITTERENTROPY_OSR=1 CONFIG_CRYPTO_USER_API_HASH=m CONFIG_CRYPTO_USER_API_SKCIPHER=m CONFIG_CRYPTO_USER_API_RNG=m CONFIG_CRYPTO_USER_API_AEAD=m -CONFIG_CRYPTO_SHA1_S390=m CONFIG_CRYPTO_SHA3_256_S390=m CONFIG_CRYPTO_SHA3_512_S390=m CONFIG_CRYPTO_GHASH_S390=m CONFIG_CRYPTO_AES_S390=m CONFIG_CRYPTO_DES_S390=m
arch/s390/crypto/Kconfig +0 -10
@@ -1,19 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 menu "Accelerated Cryptographic Algorithms for CPU (s390)" -config CRYPTO_SHA1_S390 - tristate "Hash functions: SHA-1" - select CRYPTO_HASH - help - SHA-1 secure hash algorithm (FIPS 180) - - Architecture: s390 - - It is available as of z990. - config CRYPTO_SHA3_256_S390 tristate "Hash functions: SHA3-224 and SHA3-256" select CRYPTO_HASH help SHA3-224 and SHA3-256 secure hash algorithms (FIPS 202)
arch/s390/crypto/Makefile +0 -1
@@ -1,11 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 # # Cryptographic API # -obj-$(CONFIG_CRYPTO_SHA1_S390) += sha1_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 obj-$(CONFIG_CRYPTO_DES_S390) += des_s390.o obj-$(CONFIG_CRYPTO_AES_S390) += aes_s390.o obj-$(CONFIG_CRYPTO_PAES_S390) += paes_s390.o
arch/s390/crypto/sha1_s390.c deleted +0 -103
103 lines not on this page · raw message
lib/crypto/Kconfig +1 -0
@@ -148,10 +148,11 @@ config CRYPTO_LIB_SHA1_ARCH depends on CRYPTO_LIB_SHA1 && !UML default y if ARM default y if ARM64 && KERNEL_MODE_NEON default y if MIPS && CPU_CAVIUM_OCTEON default y if PPC + default y if S390 config CRYPTO_LIB_SHA256 tristate help Enable the SHA-256 library interface. This interface may be fulfilled
lib/crypto/s390/sha1.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* SHA-1 optimized using the CP Assist for Cryptographic Functions (CPACF) +* +* Copyright 2025 Google LLC +*/ +#include <asm/cpacf.h> +#include <linux/cpufeature.h> + +static __ro_after_init DEFINE_STATIC_KEY_FALSE (have_cpacf_sha1); + +static void sha1_blocks (struct sha1_block_state *state, +const u8 *data,size_t nblocks) +{ +if (static_branch_likely (&have_cpacf_sha1)) +cpacf_kimd (CPACF_KIMD_SHA_1 , state, data, + nblocks *SHA1_BLOCK_SIZE ); +else +sha1_blocks_generic (state, data, nblocks); +} + +#define sha1_mod_init_arch sha1_mod_init_arch +static inline void sha1_mod_init_arch (void ) +{ +if (cpu_have_feature (S390_CPU_FEATURE_MSA ) && +cpacf_query_func (CPACF_KIMD ,CPACF_KIMD_SHA_1 )) +static_branch_enable (&have_cpacf_sha1); +}
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 12/26 lib/crypto: sparc/sha1: Migrate optimized code into library
In reply to Eric BiggersInstead of exposing the sparc-optimized SHA-1 code via sparc-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be sparc-optimized, and it fixes the longstanding issue where the sparc-optimized SHA-1 code was disabled by default. SHA-1 still remains available through crypto_shash, but individual architectures no longer need to handle it.
Note: to see the diff from arch/sparc/crypto/sha1_glue.c to lib/crypto/sparc/sha1.h, view this commit with 'git show -M10'.
---
arch/sparc/crypto/Kconfig | 10 --
arch/sparc/crypto/Makefile | 2 -
arch/sparc/crypto/sha1_glue.c | 94 -------------------
lib/crypto/Kconfig | 1 +
lib/crypto/Makefile | 1 +
lib/crypto/sparc/sha1.h | 43 +++++++++
.../crypto => lib/crypto/sparc}/sha1_asm.S | 0
7 files changed, 45 insertions(+), 106 deletions(-)
delete mode 100644 arch/sparc/crypto/sha1_glue.c
create mode 100644 lib/crypto/sparc/sha1.h
rename {arch/sparc/crypto => lib/crypto/sparc}/sha1_asm.S (100%)arch/sparc/crypto/Kconfig +0 -10
@@ -24,20 +24,10 @@ config CRYPTO_MD5_SPARC64 help MD5 message digest algorithm (RFC1321) Architecture: sparc64 using crypto instructions, when available -config CRYPTO_SHA1_SPARC64 - tristate "Hash functions: SHA-1" - depends on SPARC64 - select CRYPTO_SHA1 - select CRYPTO_HASH - help - SHA-1 secure hash algorithm (FIPS 180) - - Architecture: sparc64 - config CRYPTO_AES_SPARC64 tristate "Ciphers: AES, modes: ECB, CBC, CTR" depends on SPARC64 select CRYPTO_SKCIPHER help
arch/sparc/crypto/Makefile +0 -2
@@ -1,18 +1,16 @@ # SPDX-License-Identifier: GPL-2.0 # # Arch-specific CryptoAPI modules. # -obj-$(CONFIG_CRYPTO_SHA1_SPARC64) += sha1-sparc64.o obj-$(CONFIG_CRYPTO_MD5_SPARC64) += md5-sparc64.o obj-$(CONFIG_CRYPTO_AES_SPARC64) += aes-sparc64.o 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 md5-sparc64-y := md5_asm.o md5_glue.o aes-sparc64-y := aes_asm.o aes_glue.o des-sparc64-y := des_asm.o des_glue.o camellia-sparc64-y := camellia_asm.o camellia_glue.o
arch/sparc/crypto/sha1_glue.c deleted +0 -94
94 lines not on this page · raw message
lib/crypto/Kconfig +1 -0
@@ -149,10 +149,11 @@ config CRYPTO_LIB_SHA1_ARCH default y if ARM default y if ARM64 && KERNEL_MODE_NEON default y if MIPS && CPU_CAVIUM_OCTEON default y if PPC default y if S390 + default y if SPARC64 config CRYPTO_LIB_SHA256 tristate help Enable the SHA-256 library interface. This interface may be fulfilled
lib/crypto/Makefile +1 -0
@@ -81,10 +81,11 @@ endif libsha1-$(CONFIG_ARM64) += arm64/sha1-ce-core.o ifeq ($(CONFIG_PPC),y) libsha1-y += powerpc/sha1-powerpc-asm.o libsha1-$(CONFIG_SPE) += powerpc/sha1-spe-asm.o endif +libsha1-$(CONFIG_SPARC) += sparc/sha1_asm.o endif # CONFIG_CRYPTO_LIB_SHA1_ARCH ################################################################################ obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o
lib/crypto/sparc/sha1.h new file +43 -0
43 lines not on this page · raw message
lib/crypto/sparc/sha1_asm.S renamed from arch/sparc/crypto/sha1_asm.S +0 -0
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 13/26 lib/crypto: x86/sha1: Migrate optimized code into library
In reply to Eric BiggersInstead of exposing the x86-optimized SHA-1 code via x86-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be x86-optimized, and it fixes the longstanding issue where the x86-optimized SHA-1 code was disabled by default. SHA-1 still remains available through crypto_shash, but individual architectures no longer need to handle it.
--- arch/x86/crypto/Kconfig | 14 - arch/x86/crypto/Makefile | 3 - arch/x86/crypto/sha1_ssse3_glue.c | 324 ------------------ lib/crypto/Kconfig | 1 + lib/crypto/Makefile | 3 + .../crypto/x86/sha1-avx2-asm.S | 7 +- .../crypto/x86/sha1-ni-asm.S | 23 +- .../crypto/x86/sha1-ssse3-and-avx.S | 13 +- lib/crypto/x86/sha1.h | 75 ++++ 9 files changed, 95 insertions(+), 368 deletions(-) delete mode 100644 arch/x86/crypto/sha1_ssse3_glue.c rename arch/x86/crypto/sha1_avx2_x86_64_asm.S => lib/crypto/x86/sha1-avx2-asm.S (98%) rename arch/x86/crypto/sha1_ni_asm.S => lib/crypto/x86/sha1-ni-asm.S (90%) rename arch/x86/crypto/sha1_ssse3_asm.S => lib/crypto/x86/sha1-ssse3-and-avx.S (97%) create mode 100644 lib/crypto/x86/sha1.h
arch/x86/crypto/Kconfig +0 -14
@@ -374,24 +374,10 @@ config CRYPTO_POLYVAL_CLMUL_NI POLYVAL hash function for HCTR2 Architecture: x86_64 using: - CLMUL-NI (carry-less multiplication new instructions) -config CRYPTO_SHA1_SSSE3 - tristate "Hash functions: SHA-1 (SSSE3/AVX/AVX2/SHA-NI)" - depends on 64BIT - select CRYPTO_SHA1 - select CRYPTO_HASH - help - SHA-1 secure hash algorithm (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_SM3_AVX_X86_64 tristate "Hash functions: SM3 (AVX)" depends on 64BIT select CRYPTO_HASH select CRYPTO_LIB_SM3
arch/x86/crypto/Makefile +0 -3
@@ -49,13 +49,10 @@ aesni-intel-$(CONFIG_64BIT) += aes-ctr-avx-x86_64.o \ aes-xts-avx-x86_64.o ifeq ($(CONFIG_AS_VAES)$(CONFIG_AS_VPCLMULQDQ),yy) aesni-intel-$(CONFIG_64BIT) += aes-gcm-avx10-x86_64.o 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_GHASH_CLMUL_NI_INTEL) += ghash-clmulni-intel.o ghash-clmulni-intel-y := ghash-clmulni-intel_asm.o ghash-clmulni-intel_glue.o obj-$(CONFIG_CRYPTO_POLYVAL_CLMUL_NI) += polyval-clmulni.o polyval-clmulni-y := polyval-clmulni_asm.o polyval-clmulni_glue.o
arch/x86/crypto/sha1_ssse3_glue.c deleted +0 -324
324 lines not on this page · raw message
lib/crypto/Kconfig +1 -0
@@ -150,10 +150,11 @@ config CRYPTO_LIB_SHA1_ARCH default y if ARM64 && KERNEL_MODE_NEON default y if MIPS && CPU_CAVIUM_OCTEON default y if PPC default y if S390 default y if SPARC64 + default y if X86_64 config CRYPTO_LIB_SHA256 tristate help Enable the SHA-256 library interface. This interface may be fulfilled
lib/crypto/Makefile +3 -0
@@ -82,10 +82,13 @@ libsha1-$(CONFIG_ARM64) += arm64/sha1-ce-core.o ifeq ($(CONFIG_PPC),y) libsha1-y += powerpc/sha1-powerpc-asm.o libsha1-$(CONFIG_SPE) += powerpc/sha1-spe-asm.o endif libsha1-$(CONFIG_SPARC) += sparc/sha1_asm.o +libsha1-$(CONFIG_X86) += x86/sha1-ssse3-and-avx.o \ + x86/sha1-avx2-asm.o \ + x86/sha1-ni-asm.o endif # CONFIG_CRYPTO_LIB_SHA1_ARCH ################################################################################ obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o
lib/crypto/x86/sha1-avx2-asm.S renamed from arch/x86/crypto/sha1_avx2_x86_64_asm.S +2 -5
@@ -60,15 +60,12 @@ * *This implementation is based on the previous SSSE3 release: *Visit http://software.intel.com/en-us/articles/ *and refer to improving-the-performance-of-the-secure-hash-algorithm-1/ * - *Updates 20-byte SHA-1 record at start of 'state', from 'input', for - *even number of 'blocks' consecutive 64-byte blocks. - * - *extern "C" void sha1_transform_avx2( - * struct sha1_state *state, const u8* input, int blocks ); + * void sha1_transform_avx2(struct sha1_block_state *state, + * const u8 *data, size_t nblocks); */ #include <linux/linkage.h> #define CTX %rdi /* arg1 */
lib/crypto/x86/sha1-ni-asm.S renamed from arch/x86/crypto/sha1_ni_asm.S +9 -14
@@ -52,11 +52,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include <linux/linkage.h> -#include <linux/cfi_types.h> #define DIGEST_PTR %rdi /* 1st arg */ #define DATA_PTR %rsi /* 2nd arg */ #define NUM_BLKS %rdx /* 3rd arg */
@@ -72,30 +71,26 @@ #define MSG3 %xmm6 #define SHUF_MASK %xmm7 /* - * Intel SHA Extensions optimized implementation of a SHA-1 update function + * Intel SHA Extensions optimized implementation of a SHA-1 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-1 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 are expected to be handled elsewhere. * * The indented lines in the loop are instructions related to rounds processing. * The non-indented lines are instructions related to the message schedule. * - * void sha1_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 sha1_ni_transform(struct sha1_block_state *state, + * const u8 *data, size_t nblocks) */ .text -SYM_TYPED_FUNC_START(sha1_ni_transform) +SYM_FUNC_START(sha1_ni_transform) push %rbp mov %rsp, %rbp sub $FRAME_SIZE, %rsp and $~0xF, %rsp
lib/crypto/x86/sha1-ssse3-and-avx.S renamed from arch/x86/crypto/sha1_ssse3_asm.S +5 -8
@@ -23,11 +23,10 @@ * Converted to AT&T syntax and adapted for inclusion in the Linux kernel: * Author: Mathias Krause <[email protected]> */ #include <linux/linkage.h> -#include <linux/cfi_types.h> #define CTX %rdi // arg1 #define BUF %rsi // arg2 #define CNT %rdx // arg3
@@ -66,11 +65,11 @@ /* * This macro implements the SHA-1 function's body for single 64-byte block * param: function's name */ .macro SHA1_VECTOR_ASM name - SYM_TYPED_FUNC_START(\name) + SYM_FUNC_START(\name) push %rbx push %r12 push %rbp mov %rsp, %rbp
@@ -459,14 +458,12 @@ W_PRECALC_SSSE3 .endm /* * SSSE3 optimized implementation: * - * extern "C" void sha1_transform_ssse3(struct sha1_state *state, - * const u8 *data, int blocks); - * - * Note that struct sha1_state is assumed to begin with u32 state[5]. + * void sha1_transform_ssse3(struct sha1_block_state *state, + * const u8 *data, size_t nblocks); */ SHA1_VECTOR_ASM sha1_transform_ssse3 .macro W_PRECALC_AVX
@@ -546,9 +543,9 @@ W_PRECALC_AVX vmovdqu \a,\b .endm /* AVX optimized implementation: - * extern "C" void sha1_transform_avx(struct sha1_state *state, - * const u8 *data, int blocks); + * void sha1_transform_avx(struct sha1_block_state *state, + * const u8 *data, size_t nblocks); */ SHA1_VECTOR_ASM sha1_transform_avx
lib/crypto/x86/sha1.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 14/26 crypto: sha1 - Remove sha1_base.h
In reply to Eric Biggerssha1_base.h is no longer used, so remove it.
--- include/crypto/sha1_base.h | 82 -------------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 include/crypto/sha1_base.h
include/crypto/sha1_base.h deleted +0 -82
@@ -1,82 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* sha1_base.h - core logic for SHA-1 implementations -* -* Copyright (C) 2015 Linaro Ltd <[email protected]> -*/ - -#ifndef _CRYPTO_SHA1_BASE_H -#define _CRYPTO_SHA1_BASE_H - -#include <crypto/internal/hash.h> -#include <crypto/sha1.h> -#include <linux/math.h> -#include <linux/string.h> -#include <linux/types.h> -#include <linux/unaligned.h> - -typedef void (sha1_block_fn )(struct sha1_state *sst,u8 const *src,int blocks); - -static inline int sha1_base_init (struct shash_desc *desc) -{ -struct sha1_state *sctx =shash_desc_ctx (desc); - - sctx->state[0 ] =SHA1_H0 ; - sctx->state[1 ] =SHA1_H1 ; - sctx->state[2 ] =SHA1_H2 ; - sctx->state[3 ] =SHA1_H3 ; - sctx->state[4 ] =SHA1_H4 ; - sctx->count =0 ; - -return 0 ; -} - -static inline int sha1_base_do_update_blocks (struct shash_desc *desc, -const u8 *data, -unsigned int len, -sha1_block_fn *block_fn) -{ -unsigned int remain = len -round_down (len,SHA1_BLOCK_SIZE ); -struct sha1_state *sctx =shash_desc_ctx (desc); - - sctx->count += len - remain; -block_fn (sctx, data, len /SHA1_BLOCK_SIZE ); -return remain; -} - -static inline int sha1_base_do_finup (struct shash_desc *desc, -const u8 *src,unsigned int len, -sha1_block_fn *block_fn) -{ -unsigned int bit_offset =SHA1_BLOCK_SIZE /8 -1 ; -struct sha1_state *sctx =shash_desc_ctx (desc); -union { -__be64 b64[SHA1_BLOCK_SIZE /4 ]; -u8 u8[SHA1_BLOCK_SIZE *2 ]; - } block = {}; - -if (len >= bit_offset *8 ) - bit_offset +=SHA1_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 /SHA1_BLOCK_SIZE ); -memzero_explicit (&block,sizeof (block)); - -return 0 ; -} - -static inline int sha1_base_finish (struct shash_desc *desc,u8 *out) -{ -struct sha1_state *sctx =shash_desc_ctx (desc); -__be32 *digest = (__be32 *)out; -int i; - -for (i =0 ; i <SHA1_DIGEST_SIZE /sizeof (__be32); i++) -put_unaligned_be32 (sctx->state[i], digest++); - -return 0 ; -} - -#endif /* _CRYPTO_SHA1_BASE_H */
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 15/26 lib/crypto: tests: Add KUnit tests for SHA-1 and HMAC-SHA1
In reply to Eric BiggersAdd a KUnit test suite for the SHA-1 library functions, including the corresponding HMAC support. The core test logic is in the previously-added hash-test-template.h. This commit just adds the actual KUnit suite, and it adds the generated test vectors to the tree so that gen-hash-testvecs.py won't have to be run at build time.
--- lib/crypto/tests/Kconfig | 10 ++ lib/crypto/tests/Makefile | 1 + lib/crypto/tests/sha1-testvecs.h | 212 +++++++++++++++++++++++++++++++ lib/crypto/tests/sha1_kunit.c | 39 ++++++ 4 files changed, 262 insertions(+) create mode 100644 lib/crypto/tests/sha1-testvecs.h create mode 100644 lib/crypto/tests/sha1_kunit.c
lib/crypto/tests/Kconfig +10 -0
@@ -7,10 +7,20 @@ config CRYPTO_LIB_POLY1305_KUNIT_TEST select CRYPTO_LIB_BENCHMARK_VISIBLE select CRYPTO_LIB_POLY1305 help KUnit tests for the Poly1305 library functions. +config CRYPTO_LIB_SHA1_KUNIT_TEST + tristate "KUnit tests for SHA-1" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS + select CRYPTO_LIB_BENCHMARK_VISIBLE + select CRYPTO_LIB_SHA1 + help + KUnit tests for the SHA-1 cryptographic hash function and its + corresponding HMAC. + # Option is named *_SHA256_KUNIT_TEST, though both SHA-224 and SHA-256 tests are # included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA256). config CRYPTO_LIB_SHA256_KUNIT_TEST tristate "KUnit tests for SHA-224 and SHA-256" if !KUNIT_ALL_TESTS depends on KUNIT
lib/crypto/tests/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-or-later obj-$(CONFIG_CRYPTO_LIB_POLY1305_KUNIT_TEST) += poly1305_kunit.o +obj-$(CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST) += sha1_kunit.o obj-$(CONFIG_CRYPTO_LIB_SHA256_KUNIT_TEST) += sha224_kunit.o sha256_kunit.o obj-$(CONFIG_CRYPTO_LIB_SHA512_KUNIT_TEST) += sha384_kunit.o sha512_kunit.o
lib/crypto/tests/sha1-testvecs.h new file +212 -0
212 lines not on this page · raw message
lib/crypto/tests/sha1_kunit.c new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright 2025 Google LLC +*/ +#include <crypto/sha1.h> +#include "sha1-testvecs.h" + +#define HASH sha1 +#define HASH_CTX sha1_ctx +#define HASH_SIZE SHA1_DIGEST_SIZE +#define HASH_INIT sha1_init +#define HASH_UPDATE sha1_update +#define HASH_FINAL sha1_final +#define HMAC_KEY hmac_sha1_key +#define HMAC_CTX hmac_sha1_ctx +#define HMAC_PREPAREKEY hmac_sha1_preparekey +#define HMAC_INIT hmac_sha1_init +#define HMAC_UPDATE hmac_sha1_update +#define HMAC_FINAL hmac_sha1_final +#define HMAC hmac_sha1 +#define HMAC_USINGRAWKEY hmac_sha1_usingrawkey +#include "hash-test-template.h" + +static struct kunit_case hash_test_cases[] = { +HASH_KUNIT_CASES , +KUNIT_CASE (benchmark_hash), + {}, +}; + +static struct kunit_suite hash_test_suite = { + .name ="sha1" , + .test_cases = hash_test_cases, + .suite_init = hash_suite_init, + .suite_exit = hash_suite_exit, +}; +kunit_test_suite (hash_test_suite); + +MODULE_DESCRIPTION ("KUnit tests and benchmark for SHA-1 and HMAC-SHA1" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 16/26 bpf: Use sha1() instead of sha1_transform() in bpf_prog_calc_tag()
In reply to Eric BiggersNow that there's a proper SHA-1 library API, just use that instead of the low-level SHA-1 compression function. This eliminates the need for bpf_prog_calc_tag() to implement the SHA-1 padding itself. No functional change.
--- include/linux/filter.h | 6 ------ kernel/bpf/core.c | 49 +++++++----------------------------------- 2 files changed, 8 insertions(+), 47 deletions(-)
include/linux/filter.h +0 -6
@@ -995,16 +995,10 @@ void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog);static inline u32 bpf_prog_insn_size (const struct bpf_prog *prog) {return prog->len *sizeof (struct bpf_insn ); } -static inline u32 bpf_prog_tag_scratch_size (const struct bpf_prog *prog) -{ -return round_up (bpf_prog_insn_size (prog) + -sizeof (__be64) +1 ,SHA1_BLOCK_SIZE ); -} -static inline unsigned int bpf_prog_size (unsigned int proglen) {return max (sizeof (struct bpf_prog ), offsetof(struct bpf_prog, insns[proglen])); }
kernel/bpf/core.c +8 -41
77 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 17/26 sctp: Use HMAC-SHA1 and HMAC-SHA256 library functions
In reply to Eric BiggersFor SCTP authenticated chunks, use the HMAC-SHA1 and HMAC-SHA256 library functions instead of crypto_shash. This is simpler and faster.
--- include/net/sctp/auth.h | 12 +-- include/net/sctp/constants.h | 2 - include/net/sctp/structs.h | 5 -- net/sctp/Kconfig | 15 ++-- net/sctp/auth.c | 153 +++++------------------------------ net/sctp/socket.c | 10 --- 6 files changed, 32 insertions(+), 165 deletions(-)
include/net/sctp/auth.h +3 -9
@@ -20,20 +20,15 @@struct sctp_endpoint ;struct sctp_association ;struct sctp_authkey ;struct sctp_hmacalgo ; -struct crypto_shash ; -/* -* Define a generic struct that will hold all the info -* necessary for an HMAC transform -*/ +/* Defines an HMAC algorithm supported by SCTP-AUTH */ struct sctp_hmac { -__u16 hmac_id;/* one of the above ids */ -char *hmac_name;/* name for loading */ -__u16 hmac_len;/* length of the signature */ +__u16 hmac_id;/* one of SCTP_AUTH_HMAC_ID_* */ +__u16 hmac_len;/* length of the HMAC signature in bytes */ };/* This is generic structure that containst authentication bytes used * as keying material. It's a what is referred to as byte-vector all * over SCTP-AUTH
@@ -76,11 +71,10 @@ struct sctp_shared_key *sctp_auth_get_shkey( __u16 key_id);int sctp_auth_asoc_copy_shkeys (const struct sctp_endpoint *ep,struct sctp_association *asoc,gfp_t gfp);int sctp_auth_init_hmacs (struct sctp_endpoint *ep,gfp_t gfp); -void sctp_auth_destroy_hmacs (struct crypto_shash *auth_hmacs[]);struct sctp_hmac *sctp_auth_get_hmac (__u16 hmac_id);struct sctp_hmac *sctp_auth_asoc_get_hmac (const struct sctp_association *asoc);void sctp_auth_asoc_set_default_hmac (struct sctp_association *asoc,struct sctp_hmac_algo_param *hmacs); int sctp_auth_asoc_verify_hmac_id(const struct sctp_association *asoc,
include/net/sctp/constants.h +0 -2
@@ -415,13 +415,11 @@ enum sctp_lower_cwnd {*/ enum {SCTP_AUTH_HMAC_ID_RESERVED_0 ,SCTP_AUTH_HMAC_ID_SHA1 ,SCTP_AUTH_HMAC_ID_RESERVED_2 , -#if defined (CONFIG_CRYPTO_SHA256 ) || defined (CONFIG_CRYPTO_SHA256_MODULE )SCTP_AUTH_HMAC_ID_SHA256 , -#endif __SCTP_AUTH_HMAC_MAX };#define SCTP_AUTH_HMAC_ID_MAX __SCTP_AUTH_HMAC_MAX - 1#define SCTP_AUTH_NUM_HMACS __SCTP_AUTH_HMAC_MAX
include/net/sctp/structs.h +0 -5
@@ -1327,15 +1327,10 @@ struct sctp_endpoint {__u32 sndbuf_policy;/* rcvbuf acct. policy. */ __u32 rcvbuf_policy; -/* SCTP AUTH: array of the HMACs that will be allocated -* we need this per association so that we don't serialize -*/ -struct crypto_shash **auth_hmacs; -/* SCTP-AUTH: hmacs for the endpoint encoded into parameter */ struct sctp_hmac_algo_param *auth_hmacs_list;/* SCTP-AUTH: chunks to authenticate encoded into parameter */ struct sctp_chunks_param *auth_chunk_list;
net/sctp/Kconfig +8 -7
@@ -5,13 +5,12 @@ menuconfig IP_SCTP tristate "The SCTP Protocol" depends on INET depends on IPV6 || IPV6=n - select CRYPTO - select CRYPTO_HMAC - select CRYPTO_SHA1 + select CRYPTO_LIB_SHA1 + select CRYPTO_LIB_SHA256 select NET_CRC32C select NET_UDP_TUNNEL help Stream Control Transmission Protocol
@@ -77,19 +76,21 @@ endchoice config SCTP_COOKIE_HMAC_MD5 bool "Enable optional MD5 hmac cookie generation" help Enable optional MD5 hmac based SCTP cookie generation - select CRYPTO_HMAC if SCTP_COOKIE_HMAC_MD5 - select CRYPTO_MD5 if SCTP_COOKIE_HMAC_MD5 + select CRYPTO + select CRYPTO_HMAC + select CRYPTO_MD5 config SCTP_COOKIE_HMAC_SHA1 bool "Enable optional SHA1 hmac cookie generation" help Enable optional SHA1 hmac based SCTP cookie generation - select CRYPTO_HMAC if SCTP_COOKIE_HMAC_SHA1 - select CRYPTO_SHA1 if SCTP_COOKIE_HMAC_SHA1 + select CRYPTO + select CRYPTO_HMAC + select CRYPTO_SHA1 config INET_SCTP_DIAG depends on INET_DIAG def_tristate INET_DIAG
net/sctp/auth.c +21 -132
299 lines not on this page · raw message
net/sctp/socket.c +0 -10
@@ -9579,20 +9579,10 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, err =sctp_bind_addr_dup (&newsp->ep->base.bind_addr, &oldsp->ep->base.bind_addr,GFP_KERNEL );if (err)return err; -/* New ep's auth_hmacs should be set if old ep's is set, in case -* that net->sctp.auth_enable has been changed to 0 by users and -* new ep's auth_hmacs couldn't be set in sctp_endpoint_init(). -*/ -if (oldsp->ep->auth_hmacs) { - err =sctp_auth_init_hmacs (newsp->ep,GFP_KERNEL ); -if (err) -return err; - } -sctp_auto_asconf_init (newsp);/* Move any messages in the old socket's receive queue that are for the * peeled off association to the new socket's receive queue. */
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 18/26 ipv6: sr: Use HMAC-SHA1 and HMAC-SHA256 library functions
In reply to Eric BiggersUse the HMAC-SHA1 and HMAC-SHA256 library functions instead of crypto_shash. This is simpler and faster.
--- include/net/seg6_hmac.h | 12 --- net/ipv6/Kconfig | 6 +- net/ipv6/seg6.c | 7 -- net/ipv6/seg6_hmac.c | 199 ++++------------------------------------ 4 files changed, 22 insertions(+), 202 deletions(-)
include/net/seg6_hmac.h +0 -12
@@ -17,11 +17,10 @@#include <linux/route.h> #include <net/seg6.h> #include <linux/seg6_hmac.h> #include <linux/rhashtable-types.h> -#define SEG6_HMAC_MAX_DIGESTSIZE 160#define SEG6_HMAC_RING_SIZE 256struct seg6_hmac_info {struct rhash_head node;struct rcu_head rcu;
@@ -30,17 +29,10 @@ struct seg6_hmac_info {char secret[SEG6_HMAC_SECRET_LEN ];u8 slen;u8 alg_id; }; -struct seg6_hmac_algo { -u8 alg_id; -char name[64 ]; -struct crypto_shash *__percpu *tfms; -struct shash_desc *__percpu *shashs; -}; -extern int seg6_hmac_compute (struct seg6_hmac_info *hinfo,struct ipv6_sr_hdr *hdr,struct in6_addr *saddr,u8 *output);extern struct seg6_hmac_info *seg6_hmac_info_lookup (struct net *net,u32 key); extern int seg6_hmac_info_add(struct net *net, u32 key,
@@ -48,17 +40,13 @@ extern int seg6_hmac_info_add(struct net *net, u32 key,extern int seg6_hmac_info_del (struct net *net,u32 key);extern int seg6_push_hmac (struct net *net,struct in6_addr *saddr,struct ipv6_sr_hdr *srh);extern bool seg6_hmac_validate_skb (struct sk_buff *skb);#ifdef CONFIG_IPV6_SEG6_HMAC -extern int seg6_hmac_init (void ); -extern void seg6_hmac_exit (void );extern int seg6_hmac_net_init (struct net *net);extern void seg6_hmac_net_exit (struct net *net);#else -static inline int seg6_hmac_init (void ) {return 0 ; } -static inline void seg6_hmac_exit (void ) {}static inline int seg6_hmac_net_init (struct net *net) {return 0 ; }static inline void seg6_hmac_net_exit (struct net *net) {}#endif #endif
net/ipv6/Kconfig +2 -4
@@ -302,14 +302,12 @@ config IPV6_SEG6_LWTUNNEL If unsure, say N. config IPV6_SEG6_HMAC bool "IPv6: Segment Routing HMAC support" depends on IPV6 - select CRYPTO - select CRYPTO_HMAC - select CRYPTO_SHA1 - select CRYPTO_SHA256 + select CRYPTO_LIB_SHA1 + select CRYPTO_LIB_SHA256 help Support for HMAC signature generation and verification of SR-enabled packets. If unsure, say N.
net/ipv6/seg6.c +0 -7
@@ -520,20 +520,14 @@ int __init seg6_init(void) err =seg6_local_init ();if (err) goto out_unregister_iptun; - err =seg6_hmac_init (); -if (err) - goto out_unregister_seg6; -pr_info ("Segment Routing with IPv6\n" ); out:return err; -out_unregister_seg6: -seg6_local_exit (); out_unregister_iptun:seg6_iptunnel_exit (); out_unregister_genl:genl_unregister_family (&seg6_genl_family); out_unregister_pernet:
@@ -541,11 +535,10 @@ int __init seg6_init(void) goto out; }void seg6_exit (void ) { -seg6_hmac_exit ();seg6_local_exit ();seg6_iptunnel_exit ();genl_unregister_family (&seg6_genl_family);unregister_pernet_subsys (&ip6_segments_ops); }
net/ipv6/seg6_hmac.c +20 -179
274 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 19/26 tee: Use SHA-1 library instead of crypto_shash
In reply to Eric BiggersUse the SHA-1 library functions instead of crypto_shash. This is simpler and faster.
--- drivers/tee/Kconfig | 3 +-- drivers/tee/tee_core.c | 55 +++++++----------------------------------- 2 files changed, 10 insertions(+), 48 deletions(-)
drivers/tee/Kconfig +1 -2
@@ -1,12 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-only # Generic Trusted Execution Environment Configuration menuconfig TEE tristate "Trusted Execution Environment support" depends on HAVE_ARM_SMCCC || COMPILE_TEST || CPU_SUP_AMD - select CRYPTO - select CRYPTO_SHA1 + select CRYPTO_LIB_SHA1 select DMA_SHARED_BUFFER select GENERIC_ALLOCATOR help This implements a generic interface towards a Trusted Execution Environment (TEE).
drivers/tee/tee_core.c +9 -46
103 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 20/26 lib/digsig: Use SHA-1 library instead of crypto_shash
In reply to Eric BiggersUse the SHA-1 library functions instead of crypto_shash. This is simpler and faster.
--- lib/Kconfig | 3 +-- lib/digsig.c | 46 ++++++---------------------------------------- 2 files changed, 7 insertions(+), 42 deletions(-)
lib/Kconfig +1 -2
@@ -561,12 +561,11 @@ config MPILIB which is used by IMA/EVM digital signature extension. config SIGNATURE tristate depends on KEYS - select CRYPTO - select CRYPTO_SHA1 + select CRYPTO_LIB_SHA1 select MPILIB help Digital signature verification. Currently only RSA is supported. Implementation is done using GnuPG MPI library
lib/digsig.c +6 -40
92 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 21/26 drm/bridge: it6505: Use SHA-1 library instead of crypto_shash
In reply to Eric BiggersUse the SHA-1 library instead of crypto_shash. This is simpler and faster.
--- drivers/gpu/drm/bridge/Kconfig | 3 +-- drivers/gpu/drm/bridge/ite-it6505.c | 33 ++--------------------------- 2 files changed, 3 insertions(+), 33 deletions(-)
drivers/gpu/drm/bridge/Kconfig +1 -2
@@ -118,12 +118,11 @@ config DRM_ITE_IT6505 select DRM_DISPLAY_HDCP_HELPER select DRM_DISPLAY_HELPER select DRM_DISPLAY_DP_AUX_BUS select DRM_KMS_HELPER select EXTCON - select CRYPTO - select CRYPTO_HASH + select CRYPTO_LIB_SHA1 help ITE IT6505 DisplayPort bridge chip driver. config DRM_LONTIUM_LT8912B tristate "Lontium LT8912B DSI/HDMI bridge"
drivers/gpu/drm/bridge/ite-it6505.c +2 -31
@@ -19,11 +19,11 @@#include <linux/regulator/consumer.h> #include <linux/types.h> #include <linux/wait.h> #include <linux/bitfield.h> -#include <crypto/hash.h> +#include <crypto/sha1.h> #include <drm/display/drm_dp_helper.h> #include <drm/display/drm_hdcp_helper.h> #include <drm/drm_atomic_helper.h> #include <drm/drm_bridge.h>
@@ -2105,39 +2105,10 @@ static void it6505_hdcp_part1_auth(struct it6505 *it6505) HDCP_TRIGGER_START); it6505->hdcp_status =HDCP_AUTH_GOING ; } -static int it6505_sha1_digest (struct it6505 *it6505,u8 *sha1_input, -unsigned int size,u8 *output_av) -{ -struct shash_desc *desc; -struct crypto_shash *tfm; -int err; -struct device *dev = it6505->dev; - - tfm =crypto_alloc_shash ("sha1" ,0 ,0 ); -if (IS_ERR (tfm)) { -dev_err (dev,"crypto_alloc_shash sha1 failed" ); -return PTR_ERR (tfm); - } - desc =kzalloc (sizeof (*desc) +crypto_shash_descsize (tfm),GFP_KERNEL ); -if (!desc) { -crypto_free_shash (tfm); -return -ENOMEM ; - } - - desc->tfm = tfm; - err =crypto_shash_digest (desc, sha1_input, size, output_av); -if (err) -dev_err (dev,"crypto_shash_digest sha1 failed" ); - -crypto_free_shash (tfm); -kfree (desc); -return err; -} -static int it6505_setup_sha1_input (struct it6505 *it6505,u8 *sha1_input) {struct device *dev = it6505->dev;u8 binfo[2 ];int down_stream_count, err, msg_count =0 ;
@@ -2203,11 +2174,11 @@ static bool it6505_hdcp_part2_ksvlist_check(struct it6505 *it6505)if (i <=0 ) {dev_err (dev,"SHA-1 Input length error %d" , i);return false; } -it6505_sha1_digest (it6505, it6505->sha1_input, i, (u8 *)av); +sha1 (it6505->sha1_input, i, (u8 *)av);/*1B-05 V' must retry 3 times */ for (retry =0 ; retry <3 ; retry++) { err =it6505_get_dpcd (it6505,DP_AUX_HDCP_V_PRIME (0 ), (u8 *)bv,sizeof (bv));
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 22/26 nfc: s3fwrn5: Use SHA-1 library instead of crypto_shash
In reply to Eric BiggersUse the SHA-1 library instead of crypto_shash. This is simpler and faster.
--- drivers/nfc/s3fwrn5/Kconfig | 3 +-- drivers/nfc/s3fwrn5/firmware.c | 17 +---------------- 2 files changed, 2 insertions(+), 18 deletions(-)
drivers/nfc/s3fwrn5/Kconfig +1 -2
@@ -1,10 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only config NFC_S3FWRN5 tristate - select CRYPTO - select CRYPTO_HASH + select CRYPTO_LIB_SHA1 help Core driver for Samsung S3FWRN5 NFC chip. Contains core utilities of chip. It's intended to be used by PHYs to avoid duplicating lots of common code.
drivers/nfc/s3fwrn5/firmware.c +1 -16
@@ -6,11 +6,10 @@* Robert Baldyga <[email protected]> */ #include <linux/completion.h> #include <linux/firmware.h> -#include <crypto/hash.h> #include <crypto/sha1.h> #include "s3fwrn5.h" #include "firmware.h"
@@ -409,31 +408,17 @@ bool s3fwrn5_fw_check_version(const struct s3fwrn5_fw_info *fw_info, u32 versionint s3fwrn5_fw_download (struct s3fwrn5_fw_info *fw_info) {struct device *dev = &fw_info->ndev->nfc_dev->dev;struct s3fwrn5_fw_image *fw = &fw_info->fw;u8 hash_data[SHA1_DIGEST_SIZE ]; -struct crypto_shash *tfm;u32 image_size, off;int ret; image_size = fw_info->sector_size * fw->image_sectors;/* Compute SHA of firmware data */ - - tfm =crypto_alloc_shash ("sha1" ,0 ,0 ); -if (IS_ERR (tfm)) { -dev_err (dev,"Cannot allocate shash (code=%pe)\n" , tfm); -return PTR_ERR (tfm); - } - - ret =crypto_shash_tfm_digest (tfm, fw->image, image_size, hash_data); - -crypto_free_shash (tfm); -if (ret) { -dev_err (dev,"Cannot compute hash (code=%d)\n" , ret); -return ret; - } +sha1 (fw->image, image_size, hash_data);/* Firmware update process */ dev_info (dev,"Firmware update: %s\n" , fw_info->fw_name);
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 23/26 ppp: mppe: Use SHA-1 library instead of crypto_shash
In reply to Eric BiggersUse the SHA-1 library instead of crypto_shash. This is simpler and faster.
--- drivers/net/ppp/Kconfig | 3 +- drivers/net/ppp/ppp_mppe.c | 109 +++++++------------------------------ 2 files changed, 20 insertions(+), 92 deletions(-)
drivers/net/ppp/Kconfig +1 -2
@@ -83,13 +83,12 @@ config PPP_FILTER If unsure, say N. config PPP_MPPE tristate "PPP MPPE compression (encryption)" depends on PPP - select CRYPTO - select CRYPTO_SHA1 select CRYPTO_LIB_ARC4 + select CRYPTO_LIB_SHA1 help Support for the MPPE Encryption protocol, as employed by the Microsoft Point-to-Point Tunneling Protocol. See http://pptpclient.sourceforge.net/ for information on
drivers/net/ppp/ppp_mppe.c +19 -90
223 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 24/26 KEYS: trusted_tpm1: Use SHA-1 library instead of crypto_shash
In reply to Eric BiggersUse the SHA-1 library functions instead of crypto_shash. This is simpler and faster.
--- security/keys/trusted-keys/Kconfig | 4 +- security/keys/trusted-keys/trusted_tpm1.c | 221 ++++------------------ 2 files changed, 35 insertions(+), 190 deletions(-)
security/keys/trusted-keys/Kconfig +1 -3
@@ -3,13 +3,11 @@ config HAVE_TRUSTED_KEYS config TRUSTED_KEYS_TPM bool "TPM-based trusted keys" depends on TCG_TPM >= TRUSTED_KEYS default y - select CRYPTO - select CRYPTO_HMAC - select CRYPTO_SHA1 + select CRYPTO_LIB_SHA1 select CRYPTO_HASH_INFO select ASN1_ENCODER select OID_REGISTRY select ASN1 select HAVE_TRUSTED_KEYS
security/keys/trusted-keys/trusted_tpm1.c +34 -187
419 lines not on this page · raw message
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 25/26 ipv6: Switch to higher-level SHA-1 functions
In reply to Eric BiggersThere's now a proper SHA-1 API that follows the usual conventions for hash function APIs: sha1_init(), sha1_update(), sha1_final(), sha1(). The only remaining user of the older low-level SHA-1 API, sha1_init_raw() and sha1_transform(), is ipv6_generate_stable_address(). I'd like to remove this older API, which is too low-level.
Unfortunately, ipv6_generate_stable_address() does in fact skip the SHA-1 finalization for some reason. So the values it computes are not standard SHA-1 values, and it sort of does want the low-level API.
Still, it's still possible to use the higher-level functions sha1_init() and sha1_update() to get the same result, provided that the resulting state is used directly, skipping sha1_final().
So, let's do that instead. This will allow removing the low-level API.
--- net/ipv6/addrconf.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
net/ipv6/addrconf.c +13 -10
@@ -3336,12 +3336,11 @@ static bool ipv6_reserved_interfaceid(struct in6_addr address) static int ipv6_generate_stable_address(struct in6_addr *address, u8 dad_count, const struct inet6_dev *idev) { static DEFINE_SPINLOCK(lock); - static __u32 digest[SHA1_DIGEST_WORDS]; - static __u32 workspace[SHA1_WORKSPACE_WORDS]; + static struct sha1_ctx sha_ctx; static union { char __data[SHA1_BLOCK_SIZE]; struct { struct in6_addr secret;
@@ -3353,36 +3352,40 @@ static int ipv6_generate_stable_address(struct in6_addr *address,struct in6_addr secret;struct in6_addr temp;struct net *net =dev_net (idev->dev); -BUILD_BUG_ON (sizeof (data.__data) !=sizeof (data)); -if (idev->cnf.stable_secret.initialized) secret = idev->cnf.stable_secret.secret;else if (net->ipv6.devconf_dflt->stable_secret.initialized) secret = net->ipv6.devconf_dflt->stable_secret.secret;else return -1 ; retry:spin_lock_bh (&lock); -sha1_init_raw (digest); +sha1_init (&sha_ctx); +memset (&data,0 ,sizeof (data)); -memset (workspace,0 ,sizeof (workspace));memcpy (data.hwaddr, idev->dev->perm_addr, idev->dev->addr_len); data.prefix[0 ] = address->s6_addr32[0 ]; data.prefix[1 ] = address->s6_addr32[1 ]; data.secret = secret; data.dad_count = dad_count; +sha1_update (&sha_ctx, (const u8 *)&data,sizeof (data)); -sha1_transform (digest, data.__data, workspace); - +/* +* Note that the SHA-1 finalization is omitted here, and the digest is +* pulled directly from the internal SHA-1 state (making it incompatible +* with standard SHA-1). Unusual, but technically okay since the data +* length is fixed and is a multiple of the SHA-1 block size. +*/ +static_assert (sizeof (data) %SHA1_BLOCK_SIZE ==0 ); temp = *address; - temp.s6_addr32[2 ] = (__force __be32 )digest[0 ]; - temp.s6_addr32[3 ] = (__force __be32 )digest[1 ]; + temp.s6_addr32[2 ] = (__force __be32 )sha_ctx.state.h[0 ]; + temp.s6_addr32[3 ] = (__force __be32 )sha_ctx.state.h[1 ];spin_unlock_bh (&lock);if (ipv6_reserved_interfaceid (temp)) { dad_count++;
Signature · 1 line
2.50.1
Eric Biggers
maintainerPATCH 26/26 lib/crypto: sha1: Remove low-level functions from API
In reply to Eric BiggersNow that there are no users of the low-level SHA-1 interface, remove it.
Specifically:
- Remove SHA1_DIGEST_WORDS (no longer used)
- Remove sha1_init_raw() (no longer used)
- Rename sha1_transform() to sha1_block_generic() and make it static
- Move SHA1_WORKSPACE_WORDS into lib/crypto/sha1.c
--- include/crypto/sha1.h | 10 ------- lib/crypto/sha1.c | 63 ++++++++++++------------------------------- 2 files changed, 17 insertions(+), 56 deletions(-)
include/crypto/sha1.h +0 -10
@@ -24,20 +24,10 @@ struct sha1_state {u32 state[SHA1_DIGEST_SIZE /4 ];u64 count;u8 buffer[SHA1_BLOCK_SIZE ]; }; -/* -* An implementation of SHA-1's compression function. Don't use in new code! -* You shouldn't be using SHA-1, and even if you *have* to use SHA-1, this isn't -* the correct way to hash something with SHA-1 (use crypto_shash instead). -*/ -#define SHA1_DIGEST_WORDS (SHA1_DIGEST_SIZE / 4) -#define SHA1_WORKSPACE_WORDS 16 -void sha1_init_raw (__u32 *buf); -void sha1_transform (__u32 *digest,const char *data,__u32 *W ); -/* State for the SHA-1 compression function */ struct sha1_block_state {u32 h[SHA1_DIGEST_SIZE /4 ]; };
lib/crypto/sha1.c +17 -46
105 lines not on this page · raw message
Signature · 1 line
2.50.1
RE: [PATCH 03/26] lib/crypto: sha1: Add SHA-1 library functions
In reply to Eric BiggersQuoted 6 lines
-----Original Message-----
From: Eric Biggers <[email protected]>
Sent: Saturday, July 12, 2025 6:23 PM
Subject: [PATCH 03/26] lib/crypto: sha1: Add SHA-1 library functions
...
lib/crypto/sha1.c void sha1_init_raw(__u32 *buf) · line 155
Quoted 13 lines
+static void
__maybe_unusedsha1_blocks_generic(structsha1_block_state*state,lib/crypto/sha1.c +11
-0+ const u8 *data, size_t nblocks) +{ +u32 workspace[SHA1_WORKSPACE_WORDS ]; + +do { +sha1_transform (state->h, data, workspace); + data +=SHA1_BLOCK_SIZE ; + }while (--nblocks); + +memzero_explicit (workspace,sizeof (workspace)); +}
That assumes the caller will never pass nblocks of 0... should that be checked first?
Eric Biggers
maintainerRe: [PATCH 03/26] lib/crypto: sha1: Add SHA-1 library functions
Quoted 5 lines · Robert (Servers)
Quoted 4 lines
-----Original Message-----
From: Eric Biggers <[email protected]>
Sent: Saturday, July 12, 2025 6:23 PM
Subject: [PATCH 03/26] lib/crypto: sha1: Add SHA-1 library functions...
Quoted 16 lines
lib/crypto/sha1.c void sha1_init_raw(__u32 *buf) · line 155
Quoted 13 lines
+static void
__maybe_unusedsha1_blocks_generic(structsha1_block_state*state,lib/crypto/sha1.c +11
-0+ const u8 *data, size_t nblocks) +{ +u32 workspace[SHA1_WORKSPACE_WORDS ]; + +do { +sha1_transform (state->h, data, workspace); + data +=SHA1_BLOCK_SIZE ; + }while (--nblocks); + +memzero_explicit (workspace,sizeof (workspace)); +}That assumes the caller will never pass nblocks of 0... should that be checked first?
No. This is a static function, and it's easy to verify that all callers pass a positive nblocks. All these code paths are also well-covered by sha1_kunit. Also, lib/crypto/sha256.c and lib/crypto/sha512.c do the exact same thing. Also, most of the architecture-specfiic implementations of sha{1,256,512}_blocks() assume positive nblocks too.
- Eric
Quoted 70 lines · Eric Biggers
This series is also available at:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git sha1-lib-v1
Patches 1-14 reorganize the kernel's SHA-1 code to be consistent with the way the SHA-2 code is now organized:
- Add SHA-1 and HMAC-SHA1 library functions.
- Make the SHA-1 (and HMAC-SHA1) library functions use the existing architecture-optimized SHA-1 code, which is moved intolib/crypto/.
- Reimplement the old-school crypto API's "sha1" and "hmac(sha1)" algorithms on top of the SHA-1 and HMAC-SHA1 library functions.The diffstat for that part is:
65 files changed, 1052 insertions(+), 1582 deletions(-)This hopefully should look quite boring and familiar by now, as essentially the same cleanup was already applied to SHA-2.
Patch 15 adds
sha1_kunit.Note that while SHA-1 is a legacy algorithm, it still has many in-kernel users for legacy protocols. So it's not like we'll be able to remove the SHA-1 code from the kernel anytime soon. And some of these users are currently having to jump through some *major* hoops to work around the limitations of the old-school crypto API. The library API greatly simplifies things, and it makes the SHA-1 code consistent with the SHA-2 code. So, IMO it's well worth doing this reorganization of the SHA-1 code, even though SHA-1 is a legacy algorithm.
To show this even more clearly, patches 16-26 convert various users to use the SHA-1 library API (or both SHA-1 and SHA-2, in the case of some users that use both algorithms). The diffstat for that part is:
27 files changed, 169 insertions(+), 903 deletions(-)For 6.17, I'd like to take patches 1-15 at the most. Patches 16-26 would be for later, and I'll probably resend them individually later for subsystem maintainers to take.
Eric Biggers (26):
crypto: x86/sha1 - Rename conflicting symbol lib/crypto: sha1: Renamesha1_init()tosha1_init_raw()lib/crypto: sha1: Add SHA-1 library functions lib/crypto: sha1: Add HMAC support
crypto: sha1 - Wrap library and add HMAC support
crypto: sha1 - Use same state format as legacy drivers lib/crypto: arm/sha1: Migrate optimized code into library lib/crypto: arm64/sha1: Migrate optimized code into library lib/crypto: mips/sha1: Migrate optimized code into library lib/crypto: powerpc/sha1: Migrate optimized code into library lib/crypto: s390/sha1: Migrate optimized code into library lib/crypto: sparc/sha1: Migrate optimized code into library lib/crypto: x86/sha1: Migrate optimized code into library
crypto: sha1 - Removesha1_base.h
lib/crypto: tests: Add KUnit tests for SHA-1 and HMAC-SHA1
bpf: Usesha1()instead ofsha1_transform()inbpf_prog_calc_tag()
sctp: Use HMAC-SHA1 and HMAC-SHA256 library functions
ipv6: sr: Use HMAC-SHA1 and HMAC-SHA256 library functions
tee: Use SHA-1 library instead ofcrypto_shashlib/digsig: Use SHA-1 library instead ofcrypto_shashdrm/bridge: it6505: Use SHA-1 library instead ofcrypto_shash
nfc: s3fwrn5: Use SHA-1 library instead ofcrypto_shash
ppp: mppe: Use SHA-1 library instead ofcrypto_shash
KEYS:trusted_tpm1: Use SHA-1 library instead ofcrypto_shash
ipv6: Switch to higher-level SHA-1 functions lib/crypto: sha1: Remove low-level functions from API
...
Quoted 1 line
92 files changed, 1472 insertions(+), 2474 deletions(-)
Again, the diffstat speaks for itself.
For the series,
Eric Biggers
maintainerQuoted 3 lines · Eric Biggers
For 6.17, I'd like to take patches 1-15 at the most. Patches 16-26 would be for later, and I'll probably resend them individually later for subsystem maintainers to take.
FYI, patches 1-15 have been in linux-next (via libcrypto-next) since earlier this week, with no issues reported. So I will include those in 6.17. I'll resend patches 16-26 later for 6.18.
- Eric