crypto: blake2s - remove shash module
Subsystems (6)
Jason A. Donenfeld
maintainerPATCH 1/1 crypto: blake2s - remove shash module
BLAKE2s has no use as an shash and no use is likely to ever come up. Just remove all of this unnecessary plumbing. Removing this shash was something we talked about back when we were making BLAKE2s a built-in, but I simply never got around to doing it. So this completes that project.
This also helps fix a bug in which the lib code depends on crypto_simd_disabled_for_test, which is now unnecessary.
--- arch/arm/crypto/Kconfig | 2 +- arch/arm/crypto/Makefile | 4 +- arch/arm/crypto/blake2s-shash.c | 75 ----------- arch/x86/crypto/Makefile | 4 +- arch/x86/crypto/blake2s-glue.c | 3 +- arch/x86/crypto/blake2s-shash.c | 77 ----------- crypto/Kconfig | 20 +-- crypto/Makefile | 1 - crypto/blake2s_generic.c | 75 ----------- crypto/tcrypt.c | 12 -- crypto/testmgr.c | 24 ---- crypto/testmgr.h | 217 ------------------------------ include/crypto/internal/blake2s.h | 108 --------------- lib/crypto/blake2s-selftest.c | 1 + lib/crypto/blake2s.c | 36 ++++- 15 files changed, 35 insertions(+), 624 deletions(-) delete mode 100644 arch/arm/crypto/blake2s-shash.c delete mode 100644 arch/x86/crypto/blake2s-shash.c delete mode 100644 crypto/blake2s_generic.c
arch/arm/crypto/Kconfig +1 -1
@@ -63,7 +63,7 @@ config CRYPTO_SHA512_ARM using optimized ARM assembler and NEON, when available. config CRYPTO_BLAKE2S_ARM - tristate "BLAKE2s digest algorithm (ARM)" + bool "BLAKE2s digest algorithm (ARM)" select CRYPTO_ARCH_HAVE_LIB_BLAKE2S help BLAKE2s digest algorithm optimized with ARM scalar instructions. This
arch/arm/crypto/Makefile +1 -3
@@ -9,8 +9,7 @@ obj-$(CONFIG_CRYPTO_SHA1_ARM) += sha1-arm.o obj-$(CONFIG_CRYPTO_SHA1_ARM_NEON) += sha1-arm-neon.o obj-$(CONFIG_CRYPTO_SHA256_ARM) += sha256-arm.o obj-$(CONFIG_CRYPTO_SHA512_ARM) += sha512-arm.o -obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += blake2s-arm.o -obj-$(if $(CONFIG_CRYPTO_BLAKE2S_ARM),y) += libblake2s-arm.o +obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += libblake2s-arm.o obj-$(CONFIG_CRYPTO_BLAKE2B_NEON) += blake2b-neon.o obj-$(CONFIG_CRYPTO_CHACHA20_NEON) += chacha-neon.o obj-$(CONFIG_CRYPTO_POLY1305_ARM) += poly1305-arm.o
@@ -32,7 +31,6 @@ sha256-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha256_neon_glue.o sha256-arm-y := sha256-core.o sha256_glue.o $(sha256-arm-neon-y) sha512-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha512-neon-glue.o sha512-arm-y := sha512-core.o sha512-glue.o $(sha512-arm-neon-y) -blake2s-arm-y := blake2s-shash.o libblake2s-arm-y:= blake2s-core.o blake2s-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
arch/arm/crypto/blake2s-shash.c deleted +0 -75
75 lines not on this page · raw message
arch/x86/crypto/Makefile +1 -3
@@ -61,9 +61,7 @@ sha256-ssse3-$(CONFIG_AS_SHA256_NI) += sha256_ni_asm.o obj-$(CONFIG_CRYPTO_SHA512_SSSE3) += sha512-ssse3.o sha512-ssse3-y := sha512-ssse3-asm.o sha512-avx-asm.o sha512-avx2-asm.o sha512_ssse3_glue.o -obj-$(CONFIG_CRYPTO_BLAKE2S_X86) += blake2s-x86_64.o -blake2s-x86_64-y := blake2s-shash.o -obj-$(if $(CONFIG_CRYPTO_BLAKE2S_X86),y) += libblake2s-x86_64.o +obj-$(CONFIG_CRYPTO_BLAKE2S_X86) += libblake2s-x86_64.o libblake2s-x86_64-y := blake2s-core.o blake2s-glue.o obj-$(CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL) += ghash-clmulni-intel.o
arch/x86/crypto/blake2s-glue.c +1 -2
@@ -4,7 +4,6 @@*/ #include <crypto/internal/blake2s.h> -#include <crypto/internal/simd.h> #include <linux/types.h> #include <linux/jump_label.h>
@@ -33,7 +32,7 @@ void blake2s_compress(struct blake2s_state *state, const u8 *block,/* SIMD disables preemption, so relax after processing each page. */ BUILD_BUG_ON (SZ_4K /BLAKE2S_BLOCK_SIZE <8 ); -if (!static_branch_likely (&blake2s_use_ssse3) || !crypto_simd_usable ()) { +if (!static_branch_likely (&blake2s_use_ssse3) || !may_use_simd ()) {blake2s_compress_generic (state, block, nblocks, inc);return ; }
arch/x86/crypto/blake2s-shash.c deleted +0 -77
77 lines not on this page · raw message
crypto/Kconfig +1 -19
@@ -691,26 +691,8 @@ config CRYPTO_BLAKE2B See https://blake2.net for further information. -config CRYPTO_BLAKE2S - tristate "BLAKE2s digest algorithm" - select CRYPTO_LIB_BLAKE2S_GENERIC - select CRYPTO_HASH - help - Implementation of cryptographic hash function BLAKE2s - optimized for 8-32bit platforms and can produce digests of any size - between 1 to 32. The keyed hash is also implemented. - - This module provides the following algorithms: - - - blake2s-128 - - blake2s-160 - - blake2s-224 - - blake2s-256 - - See https://blake2.net for further information. - config CRYPTO_BLAKE2S_X86 - tristate "BLAKE2s digest algorithm (x86 accelerated version)" + bool "BLAKE2s digest algorithm (x86 accelerated version)" depends on X86 && 64BIT select CRYPTO_LIB_BLAKE2S_GENERIC select CRYPTO_ARCH_HAVE_LIB_BLAKE2S
crypto/Makefile +0 -1
@@ -83,7 +83,6 @@ obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o obj-$(CONFIG_CRYPTO_WP512) += wp512.o CFLAGS_wp512.o := $(call cc-option,-fno-schedule-insns) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149 obj-$(CONFIG_CRYPTO_BLAKE2B) += blake2b_generic.o -obj-$(CONFIG_CRYPTO_BLAKE2S) += blake2s_generic.o obj-$(CONFIG_CRYPTO_GF128MUL) += gf128mul.o obj-$(CONFIG_CRYPTO_ECB) += ecb.o obj-$(CONFIG_CRYPTO_CBC) += cbc.o
crypto/blake2s_generic.c deleted +0 -75
75 lines not on this page · raw message
crypto/tcrypt.c +0 -12
@@ -1669,10 +1669,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) ret +=tcrypt_test ("rmd160" );break ; -case 41 : - ret +=tcrypt_test ("blake2s-256" ); -break ; -case 42 : ret +=tcrypt_test ("blake2b-512" );break ;
@@ -2240,10 +2236,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)test_hash_speed ("rmd160" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ; fallthrough; -case 316 : -test_hash_speed ("blake2s-256" , sec, generic_hash_speed_template); -if (mode >300 && mode <400 )break ; - fallthrough;case 317 :test_hash_speed ("blake2b-512" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ;
@@ -2352,10 +2344,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)test_ahash_speed ("rmd160" , sec, generic_hash_speed_template);if (mode >400 && mode <500 )break ; fallthrough; -case 416 : -test_ahash_speed ("blake2s-256" , sec, generic_hash_speed_template); -if (mode >400 && mode <500 )break ; - fallthrough;case 417 :test_ahash_speed ("blake2b-512" , sec, generic_hash_speed_template);if (mode >400 && mode <500 )break ;
crypto/testmgr.c +0 -24
@@ -4324,30 +4324,6 @@ static const struct alg_test_desc alg_test_descs[] = { .suite = { .hash = __VECS(blake2b_512_tv_template) } - }, { - .alg = "blake2s-128", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_128_tv_template) - } - }, { - .alg = "blake2s-160", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_160_tv_template) - } - }, { - .alg = "blake2s-224", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_224_tv_template) - } - }, { - .alg = "blake2s-256", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_256_tv_template) - } }, { .alg = "cbc(aes)", .test = alg_test_skcipher,
crypto/testmgr.h +0 -217
221 lines not on this page · raw message
include/crypto/internal/blake2s.h +0 -108
118 lines not on this page · raw message
lib/crypto/blake2s-selftest.c +1 -0
@@ -4,6 +4,7 @@*/ #include <crypto/internal/blake2s.h> +#include <linux/kernel.h> #include <linux/string.h> /*
lib/crypto/blake2s.c +29 -7
@@ -16,16 +16,43 @@#include <linux/init.h> #include <linux/bug.h> +static inline void blake2s_set_lastblock (struct blake2s_state *state) +{ + state->f[0 ] =-1 ; +} +void blake2s_update (struct blake2s_state *state,const u8 *in,size_t inlen) { -__blake2s_update (state, in, inlen, false); +const size_t fill =BLAKE2S_BLOCK_SIZE - state->buflen; + +if (unlikely (!inlen)) +return ; +if (inlen > fill) { +memcpy (state->buf + state->buflen, in, fill); +blake2s_compress (state, state->buf,1 ,BLAKE2S_BLOCK_SIZE ); + state->buflen =0 ; + in += fill; + inlen -= fill; + } +if (inlen >BLAKE2S_BLOCK_SIZE ) { +const size_t nblocks =DIV_ROUND_UP (inlen,BLAKE2S_BLOCK_SIZE ); +blake2s_compress (state, in, nblocks -1 ,BLAKE2S_BLOCK_SIZE ); + in +=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + inlen -=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + } +memcpy (state->buf + state->buflen, in, inlen); + state->buflen += inlen; }EXPORT_SYMBOL (blake2s_update);void blake2s_final (struct blake2s_state *state,u8 *out) {WARN_ON (IS_ENABLED (DEBUG ) && !out); -__blake2s_final (state, out, false); +blake2s_set_lastblock (state); +memset (state->buf + state->buflen,0 ,BLAKE2S_BLOCK_SIZE - state->buflen);/* Padding */ +blake2s_compress (state, state->buf,1 , state->buflen); +cpu_to_le32_array (state->h,ARRAY_SIZE (state->h)); +memcpy (out, state->h, state->outlen);memzero_explicit (state,sizeof (*state)); }EXPORT_SYMBOL (blake2s_final);
@@ -38,12 +65,7 @@ static int __init blake2s_mod_init(void)return 0 ; } -static void __exit blake2s_mod_exit(void) -{ -} -module_init (blake2s_mod_init); -module_exit (blake2s_mod_exit);MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("BLAKE2s hash function" );MODULE_AUTHOR ("Jason A. Donenfeld <[email protected]>" );
Signature · 1 line
2.35.1
Eric Biggers
maintainerQuoted 1 line · Jason A. Donenfeld
BLAKE2s has no use as an shash and no use is likely to ever come up.
I'm not sure about that. Anyone who is already using shash (for supporting multiple algorithms) and wants to add blake2s support would need it. dm-verity, dm-integrity, fs-verity, UBIFS authentication, IMA, btrfs checksums, etc. A couple of these are already using blake2b, even. I guess you might as well remove blake2s until someone explicitly says they want it, but I can easily see it coming back later.
Quoted 5 lines
Just remove all of this unnecessary plumbing. Removing this shash was something we talked about back when we were making BLAKE2s a built-in, but I simply never got around to doing it. So this completes that project.
Quoted 7 lines
This also helps fix a bug in which the lib code depends on
crypto_simd_disabled_for_test, which is now unnecessary.Cc gaochao <[email protected]>Cc Eric Biggers <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
More importantly, this is removing quite a bit of test coverage because the extra self-tests in crypto/testmgr.c are more comprehensive than what lib/crypto/blake2s-selftest.c does. For example they test the case where the input data is misaligned, as well as the case where the code is executed in a context where SIMD instructions are unavailable.
In order for this to be acceptable, I think you'd need to update blake2s-selftest.c to be more comprehensive.
- Eric
Jason A. Donenfeld
maintainerHey Eric,
Quoted 4 lines · Eric Biggers
Quoted 1 line · Jason A. Donenfeld
BLAKE2s has no use as an shash and no use is likely to ever come up.
I'm not sure about that. Anyone who is already using shash (for supporting
I'll tweak the language of the commit message.
Quoted 8 lines
More importantly, this is removing quite a bit of test coverage because the extra self-tests in
crypto/testmgr.care more comprehensive than whatlib/crypto/blake2s-selftest.cdoes. For example they test the case where the input data is misaligned, as well as the case where the code is executed in a context where SIMD instructions are unavailable.In order for this to be acceptable, I think you'd need to update
blake2s-selftest.cto be more comprehensive.
There actually already is some alignment tests. But I'll add some more and also compare implementations. v2 incoming.
Jason
Jason A. Donenfeld
maintainerPATCH v2 1/1 crypto: blake2s - remove shash module
BLAKE2s has no use as an shash, with no users of it. Just remove all of this unnecessary plumbing. Removing this shash was something we talked about back when we were making BLAKE2s a built-in, but I simply never got around to doing it. So this completes that project.
Importantly, this fixs a bug in which the lib code depends on crypto_simd_disabled_for_test, causing linker errors.
Also add more alignment tests to the selftests and compare SIMD and non-SIMD compression functions, to make up for what we lose from testmgr.c.
--- arch/arm/crypto/Kconfig | 2 +- arch/arm/crypto/Makefile | 4 +- arch/arm/crypto/blake2s-shash.c | 75 ----------- arch/x86/crypto/Makefile | 4 +- arch/x86/crypto/blake2s-glue.c | 3 +- arch/x86/crypto/blake2s-shash.c | 77 ----------- crypto/Kconfig | 20 +-- crypto/Makefile | 1 - crypto/blake2s_generic.c | 75 ----------- crypto/tcrypt.c | 12 -- crypto/testmgr.c | 24 ---- crypto/testmgr.h | 217 ------------------------------ include/crypto/internal/blake2s.h | 108 --------------- lib/crypto/blake2s-selftest.c | 32 ++++- lib/crypto/blake2s.c | 36 ++++- 15 files changed, 65 insertions(+), 625 deletions(-) delete mode 100644 arch/arm/crypto/blake2s-shash.c delete mode 100644 arch/x86/crypto/blake2s-shash.c delete mode 100644 crypto/blake2s_generic.c
arch/arm/crypto/Kconfig +1 -1
@@ -63,7 +63,7 @@ config CRYPTO_SHA512_ARM using optimized ARM assembler and NEON, when available. config CRYPTO_BLAKE2S_ARM - tristate "BLAKE2s digest algorithm (ARM)" + bool "BLAKE2s digest algorithm (ARM)" select CRYPTO_ARCH_HAVE_LIB_BLAKE2S help BLAKE2s digest algorithm optimized with ARM scalar instructions. This
arch/arm/crypto/Makefile +1 -3
@@ -9,8 +9,7 @@ obj-$(CONFIG_CRYPTO_SHA1_ARM) += sha1-arm.o obj-$(CONFIG_CRYPTO_SHA1_ARM_NEON) += sha1-arm-neon.o obj-$(CONFIG_CRYPTO_SHA256_ARM) += sha256-arm.o obj-$(CONFIG_CRYPTO_SHA512_ARM) += sha512-arm.o -obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += blake2s-arm.o -obj-$(if $(CONFIG_CRYPTO_BLAKE2S_ARM),y) += libblake2s-arm.o +obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += libblake2s-arm.o obj-$(CONFIG_CRYPTO_BLAKE2B_NEON) += blake2b-neon.o obj-$(CONFIG_CRYPTO_CHACHA20_NEON) += chacha-neon.o obj-$(CONFIG_CRYPTO_POLY1305_ARM) += poly1305-arm.o
@@ -32,7 +31,6 @@ sha256-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha256_neon_glue.o sha256-arm-y := sha256-core.o sha256_glue.o $(sha256-arm-neon-y) sha512-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha512-neon-glue.o sha512-arm-y := sha512-core.o sha512-glue.o $(sha512-arm-neon-y) -blake2s-arm-y := blake2s-shash.o libblake2s-arm-y:= blake2s-core.o blake2s-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
arch/arm/crypto/blake2s-shash.c deleted +0 -75
75 lines not on this page · raw message
arch/x86/crypto/Makefile +1 -3
@@ -61,9 +61,7 @@ sha256-ssse3-$(CONFIG_AS_SHA256_NI) += sha256_ni_asm.o obj-$(CONFIG_CRYPTO_SHA512_SSSE3) += sha512-ssse3.o sha512-ssse3-y := sha512-ssse3-asm.o sha512-avx-asm.o sha512-avx2-asm.o sha512_ssse3_glue.o -obj-$(CONFIG_CRYPTO_BLAKE2S_X86) += blake2s-x86_64.o -blake2s-x86_64-y := blake2s-shash.o -obj-$(if $(CONFIG_CRYPTO_BLAKE2S_X86),y) += libblake2s-x86_64.o +obj-$(CONFIG_CRYPTO_BLAKE2S_X86) += libblake2s-x86_64.o libblake2s-x86_64-y := blake2s-core.o blake2s-glue.o obj-$(CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL) += ghash-clmulni-intel.o
arch/x86/crypto/blake2s-glue.c +1 -2
@@ -4,7 +4,6 @@*/ #include <crypto/internal/blake2s.h> -#include <crypto/internal/simd.h> #include <linux/types.h> #include <linux/jump_label.h>
@@ -33,7 +32,7 @@ void blake2s_compress(struct blake2s_state *state, const u8 *block,/* SIMD disables preemption, so relax after processing each page. */ BUILD_BUG_ON (SZ_4K /BLAKE2S_BLOCK_SIZE <8 ); -if (!static_branch_likely (&blake2s_use_ssse3) || !crypto_simd_usable ()) { +if (!static_branch_likely (&blake2s_use_ssse3) || !may_use_simd ()) {blake2s_compress_generic (state, block, nblocks, inc);return ; }
arch/x86/crypto/blake2s-shash.c deleted +0 -77
77 lines not on this page · raw message
crypto/Kconfig +1 -19
@@ -691,26 +691,8 @@ config CRYPTO_BLAKE2B See https://blake2.net for further information. -config CRYPTO_BLAKE2S - tristate "BLAKE2s digest algorithm" - select CRYPTO_LIB_BLAKE2S_GENERIC - select CRYPTO_HASH - help - Implementation of cryptographic hash function BLAKE2s - optimized for 8-32bit platforms and can produce digests of any size - between 1 to 32. The keyed hash is also implemented. - - This module provides the following algorithms: - - - blake2s-128 - - blake2s-160 - - blake2s-224 - - blake2s-256 - - See https://blake2.net for further information. - config CRYPTO_BLAKE2S_X86 - tristate "BLAKE2s digest algorithm (x86 accelerated version)" + bool "BLAKE2s digest algorithm (x86 accelerated version)" depends on X86 && 64BIT select CRYPTO_LIB_BLAKE2S_GENERIC select CRYPTO_ARCH_HAVE_LIB_BLAKE2S
crypto/Makefile +0 -1
@@ -83,7 +83,6 @@ obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o obj-$(CONFIG_CRYPTO_WP512) += wp512.o CFLAGS_wp512.o := $(call cc-option,-fno-schedule-insns) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149 obj-$(CONFIG_CRYPTO_BLAKE2B) += blake2b_generic.o -obj-$(CONFIG_CRYPTO_BLAKE2S) += blake2s_generic.o obj-$(CONFIG_CRYPTO_GF128MUL) += gf128mul.o obj-$(CONFIG_CRYPTO_ECB) += ecb.o obj-$(CONFIG_CRYPTO_CBC) += cbc.o
crypto/blake2s_generic.c deleted +0 -75
75 lines not on this page · raw message
crypto/tcrypt.c +0 -12
@@ -1669,10 +1669,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) ret +=tcrypt_test ("rmd160" );break ; -case 41 : - ret +=tcrypt_test ("blake2s-256" ); -break ; -case 42 : ret +=tcrypt_test ("blake2b-512" );break ;
@@ -2240,10 +2236,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)test_hash_speed ("rmd160" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ; fallthrough; -case 316 : -test_hash_speed ("blake2s-256" , sec, generic_hash_speed_template); -if (mode >300 && mode <400 )break ; - fallthrough;case 317 :test_hash_speed ("blake2b-512" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ;
@@ -2352,10 +2344,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)test_ahash_speed ("rmd160" , sec, generic_hash_speed_template);if (mode >400 && mode <500 )break ; fallthrough; -case 416 : -test_ahash_speed ("blake2s-256" , sec, generic_hash_speed_template); -if (mode >400 && mode <500 )break ; - fallthrough;case 417 :test_ahash_speed ("blake2b-512" , sec, generic_hash_speed_template);if (mode >400 && mode <500 )break ;
crypto/testmgr.c +0 -24
@@ -4324,30 +4324,6 @@ static const struct alg_test_desc alg_test_descs[] = { .suite = { .hash = __VECS(blake2b_512_tv_template) } - }, { - .alg = "blake2s-128", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_128_tv_template) - } - }, { - .alg = "blake2s-160", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_160_tv_template) - } - }, { - .alg = "blake2s-224", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_224_tv_template) - } - }, { - .alg = "blake2s-256", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_256_tv_template) - } }, { .alg = "cbc(aes)", .test = alg_test_skcipher,
crypto/testmgr.h +0 -217
221 lines not on this page · raw message
include/crypto/internal/blake2s.h +0 -108
118 lines not on this page · raw message
lib/crypto/blake2s-selftest.c +31 -1
@@ -4,6 +4,8 @@*/ #include <crypto/internal/blake2s.h> +#include <linux/kernel.h> +#include <linux/random.h> #include <linux/string.h> /*
@@ -548,7 +550,8 @@ bool __init blake2s_selftest(void)u8 key[BLAKE2S_KEY_SIZE ];u8 buf[ARRAY_SIZE (blake2s_testvecs)];u8 hash[BLAKE2S_HASH_SIZE ]; -struct blake2s_state state; +u8 blocks[BLAKE2S_BLOCK_SIZE *4 ]; +struct blake2s_state state, state1, state2;bool success = true;int i, l;
@@ -587,5 +590,32 @@ bool __init blake2s_selftest(void) } } +for (i =0 ; i <2048 ; ++i) { +get_random_bytes (blocks,sizeof (blocks)); +get_random_bytes (&state,sizeof (state)); + +memcpy (&state1, &state,sizeof (state1)); +memcpy (&state2, &state,sizeof (state2)); +blake2s_compress (&state1, blocks,4 ,sizeof (blocks)); +blake2s_compress_generic (&state2, blocks,4 ,sizeof (blocks)); +if (memcmp (&state1, &state2,sizeof (state1))) { +pr_err ("blake2s random compress self-test %d: FAIL\n" , + i +1 ); + success = false; + } + +for (l =1 ; l <8 ; ++l) { +memcpy (&state1, &state,sizeof (state1)); +memcpy (&state2, &state,sizeof (state2)); +blake2s_compress (&state1, blocks + l,3 ,sizeof (blocks) -BLAKE2S_BLOCK_SIZE ); +blake2s_compress_generic (&state2, blocks + l,3 ,sizeof (blocks) -BLAKE2S_BLOCK_SIZE ); +if (memcmp (&state1, &state2,sizeof (state1))) { +pr_err ("blake2s random compress align %d self-test %d: FAIL\n" , + l, i +1 ); + success = false; + } + } + } +return success; }
lib/crypto/blake2s.c +29 -7
@@ -16,16 +16,43 @@#include <linux/init.h> #include <linux/bug.h> +static inline void blake2s_set_lastblock (struct blake2s_state *state) +{ + state->f[0 ] =-1 ; +} +void blake2s_update (struct blake2s_state *state,const u8 *in,size_t inlen) { -__blake2s_update (state, in, inlen, false); +const size_t fill =BLAKE2S_BLOCK_SIZE - state->buflen; + +if (unlikely (!inlen)) +return ; +if (inlen > fill) { +memcpy (state->buf + state->buflen, in, fill); +blake2s_compress (state, state->buf,1 ,BLAKE2S_BLOCK_SIZE ); + state->buflen =0 ; + in += fill; + inlen -= fill; + } +if (inlen >BLAKE2S_BLOCK_SIZE ) { +const size_t nblocks =DIV_ROUND_UP (inlen,BLAKE2S_BLOCK_SIZE ); +blake2s_compress (state, in, nblocks -1 ,BLAKE2S_BLOCK_SIZE ); + in +=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + inlen -=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + } +memcpy (state->buf + state->buflen, in, inlen); + state->buflen += inlen; }EXPORT_SYMBOL (blake2s_update);void blake2s_final (struct blake2s_state *state,u8 *out) {WARN_ON (IS_ENABLED (DEBUG ) && !out); -__blake2s_final (state, out, false); +blake2s_set_lastblock (state); +memset (state->buf + state->buflen,0 ,BLAKE2S_BLOCK_SIZE - state->buflen);/* Padding */ +blake2s_compress (state, state->buf,1 , state->buflen); +cpu_to_le32_array (state->h,ARRAY_SIZE (state->h)); +memcpy (out, state->h, state->outlen);memzero_explicit (state,sizeof (*state)); }EXPORT_SYMBOL (blake2s_final);
@@ -38,12 +65,7 @@ static int __init blake2s_mod_init(void)return 0 ; } -static void __exit blake2s_mod_exit(void) -{ -} -module_init (blake2s_mod_init); -module_exit (blake2s_mod_exit);MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("BLAKE2s hash function" );MODULE_AUTHOR ("Jason A. Donenfeld <[email protected]>" );
Signature · 1 line
2.35.1
From: Jason A. Donenfeld
Quoted 6 lines
Sent: 27 May 2022 09:11
BLAKE2s has no use as an shash, with no users of it. Just remove all of this unnecessary plumbing. Removing this shash was something we talked about back when we were making BLAKE2s a built-in, but I simply never got around to doing it. So this completes that project.
...
Quoted 10 lines
lib/crypto/blake2s.c +2
-0@@ -16,16 +16,43 @@#include <linux/init.h> #include <linux/bug.h> +static inline void blake2s_set_lastblock (struct blake2s_state *state) +{
lib/crypto/blake2s.c line 29
Quoted 10 lines
lib/crypto/blake2s.c +7
-1+ state->f[0 ] =-1 ; +} +void blake2s_update (struct blake2s_state *state,const u8 *in,size_t inlen) { -__blake2s_update (state, in, inlen, false); +const size_t fill =BLAKE2S_BLOCK_SIZE - state->buflen; + +if (unlikely (!inlen)) +return ;
Does this happen often enough to optimise for?
The zero length memcpy() should be fine.
(though pedants might worry about in == NULL)
lib/crypto/blake2s.c line 30
Quoted 1 line
lib/crypto/blake2s.c +1
-0+if (inlen > fill) {
Testing inlen >= fill will be better.
You also don't need the code below in the (probably) likely case that state->buflen == 0.
lib/crypto/blake2s.c line 35
Quoted 5 lines
lib/crypto/blake2s.c +5
-0+memcpy (state->buf + state->buflen, in, fill); +blake2s_compress (state, state->buf,1 ,BLAKE2S_BLOCK_SIZE ); + state->buflen =0 ; + in += fill; + inlen -= fill;
an 'if (!inlen) return' check here may be a cheap optimisation.
lib/crypto/blake2s.c line 37
Quoted 2 lines
lib/crypto/blake2s.c +2
-0+ } +if (inlen >BLAKE2S_BLOCK_SIZE ) {
This test only needs to be inside the earlier inlen > fill condition. The compiler may not be able to assume so.
lib/crypto/blake2s.c line 38
Quoted 1 line
lib/crypto/blake2s.c +1
-0+const size_t nblocks =DIV_ROUND_UP (inlen,BLAKE2S_BLOCK_SIZE );
Why not inlen/BLAKE2S_BLOCK_SIZE and remove all the '- 1'. Looping inside blakes2s_compress() has to be better than doing an extra call when processing the next data block.
Quoted 22 lines
lib/crypto/blake2s.c +11
-1+blake2s_compress (state, in, nblocks -1 ,BLAKE2S_BLOCK_SIZE ); + in +=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + inlen -=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + } +memcpy (state->buf + state->buflen, in, inlen); + state->buflen += inlen; }EXPORT_SYMBOL (blake2s_update);void blake2s_final (struct blake2s_state *state,u8 *out) {WARN_ON (IS_ENABLED (DEBUG ) && !out); -__blake2s_final (state, out, false); +blake2s_set_lastblock (state); +memset (state->buf + state->buflen,0 ,BLAKE2S_BLOCK_SIZE - state->buflen);/* Padding */ +blake2s_compress (state, state->buf,1 , state->buflen); +cpu_to_le32_array (state->h,ARRAY_SIZE (state->h)); +memcpy (out, state->h, state->outlen);memzero_explicit (state,sizeof (*state)); }EXPORT_SYMBOL (blake2s_final);
lib/crypto/blake2s.c static int __init blake2s_mod_init(void) · line 66
Quoted 2 lines
lib/crypto/blake2s.c +0
-0@@ -38,12 +65,7 @@ static int __init blake2s_mod_init(void)return 0 ; }
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Jason A. Donenfeld
maintainerHi David,
Quoted 25 lines · David Laight
From: Jason A. Donenfeld
Quoted 6 lines
Sent: 27 May 2022 09:11
BLAKE2s has no use as an shash, with no users of it. Just remove all of this unnecessary plumbing. Removing this shash was something we talked about back when we were making BLAKE2s a built-in, but I simply never got around to doing it. So this completes that project.
...
Quoted 17 lines
lib/crypto/blake2s.c +5
-1@@ -16,16 +16,43 @@#include <linux/init.h> #include <linux/bug.h> +static inline void blake2s_set_lastblock (struct blake2s_state *state) +{ + state->f[0 ] =-1 ; +} +void blake2s_update (struct blake2s_state *state,const u8 *in,size_t inlen) { -__blake2s_update (state, in, inlen, false);
Quoted 9 lines
lib/crypto/blake2s.c line 29
Quoted 4 lines
lib/crypto/blake2s.c +4
-0+const size_t fill =BLAKE2S_BLOCK_SIZE - state->buflen; + +if (unlikely (!inlen)) +return ;Does this happen often enough to optimise for?
The zero lengthmemcpy()should be fine.
(though pedants might worry about in == NULL)
I don't know and don't care here. This is a straight copy and paste for the removal. It is not the place for random performance optimizations.
I have now witnessed you have random performance optimization ideas in at least 7 threads, usually unrelated to whatever the topic is. As I keep telling you every time: SEND A PATCH. Those capital letters are
intentional: I care about the same things you do, so please send a patch so that all that stuff actually happens. Talk is cheap.
Jason
Eric Biggers
maintainerQuoted 1 line · Jason A. Donenfeld
BLAKE2s has no use as an shash, with no users of it.
"no use" => "no known current use".
Quoted 43 lines
lib/crypto/blake2s-selftest.c +20
-1@@ -4,6 +4,8 @@*/ #include <crypto/internal/blake2s.h> +#include <linux/kernel.h> +#include <linux/random.h> #include <linux/string.h> /* @@ -548,7 +550,8 @@ bool __init blake2s_selftest(void)u8 key[BLAKE2S_KEY_SIZE ];u8 buf[ARRAY_SIZE (blake2s_testvecs)];u8 hash[BLAKE2S_HASH_SIZE ]; -struct blake2s_state state; +u8 blocks[BLAKE2S_BLOCK_SIZE *4 ]; +struct blake2s_state state, state1, state2;bool success = true;int i, l;@@ -587,5 +590,32 @@ bool __init blake2s_selftest(void) } } +for (i =0 ; i <2048 ; ++i) { +get_random_bytes (blocks,sizeof (blocks)); +get_random_bytes (&state,sizeof (state)); + +memcpy (&state1, &state,sizeof (state1)); +memcpy (&state2, &state,sizeof (state2)); +blake2s_compress (&state1, blocks,4 ,sizeof (blocks)); +blake2s_compress_generic (&state2, blocks,4 ,sizeof (blocks)); +if (memcmp (&state1, &state2,sizeof (state1))) { +pr_err ("blake2s random compress self-test %d: FAIL\n" , + i +1 ); + success = false; + } + +for (l =1 ; l <8 ; ++l) { +memcpy (&state1, &state,sizeof (state1));
lib/crypto/blake2s-selftest.c bool __init blake2s_selftest(void) · line 618
Quoted 10 lines
lib/crypto/blake2s-selftest.c +10
-0+memcpy (&state2, &state,sizeof (state2)); +blake2s_compress (&state1, blocks + l,3 ,sizeof (blocks) -BLAKE2S_BLOCK_SIZE ); +blake2s_compress_generic (&state2, blocks + l,3 ,sizeof (blocks) -BLAKE2S_BLOCK_SIZE ); +if (memcmp (&state1, &state2,sizeof (state1))) { +pr_err ("blake2s random compress align %d self-test %d: FAIL\n" , + l, i +1 ); + success = false; + } + } + }
This doesn't compile on arm, since blake2s_compress_generic() isn't defined.
Also, the wrong value is being passed for the 'inc' argument.
2048 iterations is also a lot. Doing a lot of iterations here doesn't meaningfully increase the test coverage.
And please run checkpatch; those are some very long lines :-(
- Eric
Jason A. Donenfeld
maintainerHi Eric,
Quoted 4 lines · Eric Biggers
Quoted 1 line · Jason A. Donenfeld
BLAKE2s has no use as an shash, with no users of it.
"no use" => "no known current use".
Ack.
Quoted 1 line
This doesn't compile on arm, since
blake2s_compress_generic()isn't defined.
Grr, thanks. I'll fix that and verify before sending v3.
Quoted 1 line
Also, the wrong value is being passed for the 'inc' argument.
Are you sure? Not sure I'm seeing what you are on first glance.
Quoted 2 lines
2048 iterations is also a lot. Doing a lot of iterations here doesn't meaningfully increase the test coverage.
For symmetric things like this, yeah, you're right. I'll reduce that to a more modest 100 or something.
Quoted 1 line
And please run checkpatch; those are some very long lines :-(
Ack.
Jason
Jason A. Donenfeld
maintainerPATCH v3 1/1 crypto: blake2s - remove shash module
BLAKE2s has no currently known use as an shash. Just remove all of this unnecessary plumbing. Removing this shash was something we talked about back when we were making BLAKE2s a built-in, but I simply never got around to doing it. So this completes that project.
Importantly, this fixs a bug in which the lib code depends on crypto_simd_disabled_for_test, causing linker errors.
Also add more alignment tests to the selftests and compare SIMD and non-SIMD compression functions, to make up for what we lose from testmgr.c.
--- arch/arm/crypto/Kconfig | 2 +- arch/arm/crypto/Makefile | 4 +- arch/arm/crypto/blake2s-shash.c | 75 ----------- arch/x86/crypto/Makefile | 4 +- arch/x86/crypto/blake2s-glue.c | 3 +- arch/x86/crypto/blake2s-shash.c | 77 ----------- crypto/Kconfig | 20 +-- crypto/Makefile | 1 - crypto/blake2s_generic.c | 75 ----------- crypto/tcrypt.c | 12 -- crypto/testmgr.c | 24 ---- crypto/testmgr.h | 217 ------------------------------ include/crypto/internal/blake2s.h | 108 --------------- lib/crypto/blake2s-selftest.c | 39 ++++++ lib/crypto/blake2s.c | 37 ++++- 15 files changed, 74 insertions(+), 624 deletions(-) delete mode 100644 arch/arm/crypto/blake2s-shash.c delete mode 100644 arch/x86/crypto/blake2s-shash.c delete mode 100644 crypto/blake2s_generic.c
arch/arm/crypto/Kconfig +1 -1
@@ -63,7 +63,7 @@ config CRYPTO_SHA512_ARM using optimized ARM assembler and NEON, when available. config CRYPTO_BLAKE2S_ARM - tristate "BLAKE2s digest algorithm (ARM)" + bool "BLAKE2s digest algorithm (ARM)" select CRYPTO_ARCH_HAVE_LIB_BLAKE2S help BLAKE2s digest algorithm optimized with ARM scalar instructions. This
arch/arm/crypto/Makefile +1 -3
@@ -9,8 +9,7 @@ obj-$(CONFIG_CRYPTO_SHA1_ARM) += sha1-arm.o obj-$(CONFIG_CRYPTO_SHA1_ARM_NEON) += sha1-arm-neon.o obj-$(CONFIG_CRYPTO_SHA256_ARM) += sha256-arm.o obj-$(CONFIG_CRYPTO_SHA512_ARM) += sha512-arm.o -obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += blake2s-arm.o -obj-$(if $(CONFIG_CRYPTO_BLAKE2S_ARM),y) += libblake2s-arm.o +obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += libblake2s-arm.o obj-$(CONFIG_CRYPTO_BLAKE2B_NEON) += blake2b-neon.o obj-$(CONFIG_CRYPTO_CHACHA20_NEON) += chacha-neon.o obj-$(CONFIG_CRYPTO_POLY1305_ARM) += poly1305-arm.o
@@ -32,7 +31,6 @@ sha256-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha256_neon_glue.o sha256-arm-y := sha256-core.o sha256_glue.o $(sha256-arm-neon-y) sha512-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha512-neon-glue.o sha512-arm-y := sha512-core.o sha512-glue.o $(sha512-arm-neon-y) -blake2s-arm-y := blake2s-shash.o libblake2s-arm-y:= blake2s-core.o blake2s-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
arch/arm/crypto/blake2s-shash.c deleted +0 -75
75 lines not on this page · raw message
arch/x86/crypto/Makefile +1 -3
@@ -61,9 +61,7 @@ sha256-ssse3-$(CONFIG_AS_SHA256_NI) += sha256_ni_asm.o obj-$(CONFIG_CRYPTO_SHA512_SSSE3) += sha512-ssse3.o sha512-ssse3-y := sha512-ssse3-asm.o sha512-avx-asm.o sha512-avx2-asm.o sha512_ssse3_glue.o -obj-$(CONFIG_CRYPTO_BLAKE2S_X86) += blake2s-x86_64.o -blake2s-x86_64-y := blake2s-shash.o -obj-$(if $(CONFIG_CRYPTO_BLAKE2S_X86),y) += libblake2s-x86_64.o +obj-$(CONFIG_CRYPTO_BLAKE2S_X86) += libblake2s-x86_64.o libblake2s-x86_64-y := blake2s-core.o blake2s-glue.o obj-$(CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL) += ghash-clmulni-intel.o
arch/x86/crypto/blake2s-glue.c +1 -2
@@ -4,7 +4,6 @@*/ #include <crypto/internal/blake2s.h> -#include <crypto/internal/simd.h> #include <linux/types.h> #include <linux/jump_label.h>
@@ -33,7 +32,7 @@ void blake2s_compress(struct blake2s_state *state, const u8 *block,/* SIMD disables preemption, so relax after processing each page. */ BUILD_BUG_ON (SZ_4K /BLAKE2S_BLOCK_SIZE <8 ); -if (!static_branch_likely (&blake2s_use_ssse3) || !crypto_simd_usable ()) { +if (!static_branch_likely (&blake2s_use_ssse3) || !may_use_simd ()) {blake2s_compress_generic (state, block, nblocks, inc);return ; }
arch/x86/crypto/blake2s-shash.c deleted +0 -77
77 lines not on this page · raw message
crypto/Kconfig +1 -19
@@ -691,26 +691,8 @@ config CRYPTO_BLAKE2B See https://blake2.net for further information. -config CRYPTO_BLAKE2S - tristate "BLAKE2s digest algorithm" - select CRYPTO_LIB_BLAKE2S_GENERIC - select CRYPTO_HASH - help - Implementation of cryptographic hash function BLAKE2s - optimized for 8-32bit platforms and can produce digests of any size - between 1 to 32. The keyed hash is also implemented. - - This module provides the following algorithms: - - - blake2s-128 - - blake2s-160 - - blake2s-224 - - blake2s-256 - - See https://blake2.net for further information. - config CRYPTO_BLAKE2S_X86 - tristate "BLAKE2s digest algorithm (x86 accelerated version)" + bool "BLAKE2s digest algorithm (x86 accelerated version)" depends on X86 && 64BIT select CRYPTO_LIB_BLAKE2S_GENERIC select CRYPTO_ARCH_HAVE_LIB_BLAKE2S
crypto/Makefile +0 -1
@@ -83,7 +83,6 @@ obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o obj-$(CONFIG_CRYPTO_WP512) += wp512.o CFLAGS_wp512.o := $(call cc-option,-fno-schedule-insns) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149 obj-$(CONFIG_CRYPTO_BLAKE2B) += blake2b_generic.o -obj-$(CONFIG_CRYPTO_BLAKE2S) += blake2s_generic.o obj-$(CONFIG_CRYPTO_GF128MUL) += gf128mul.o obj-$(CONFIG_CRYPTO_ECB) += ecb.o obj-$(CONFIG_CRYPTO_CBC) += cbc.o
crypto/blake2s_generic.c deleted +0 -75
75 lines not on this page · raw message
crypto/tcrypt.c +0 -12
@@ -1669,10 +1669,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) ret +=tcrypt_test ("rmd160" );break ; -case 41 : - ret +=tcrypt_test ("blake2s-256" ); -break ; -case 42 : ret +=tcrypt_test ("blake2b-512" );break ;
@@ -2240,10 +2236,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)test_hash_speed ("rmd160" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ; fallthrough; -case 316 : -test_hash_speed ("blake2s-256" , sec, generic_hash_speed_template); -if (mode >300 && mode <400 )break ; - fallthrough;case 317 :test_hash_speed ("blake2b-512" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ;
@@ -2352,10 +2344,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)test_ahash_speed ("rmd160" , sec, generic_hash_speed_template);if (mode >400 && mode <500 )break ; fallthrough; -case 416 : -test_ahash_speed ("blake2s-256" , sec, generic_hash_speed_template); -if (mode >400 && mode <500 )break ; - fallthrough;case 417 :test_ahash_speed ("blake2b-512" , sec, generic_hash_speed_template);if (mode >400 && mode <500 )break ;
crypto/testmgr.c +0 -24
@@ -4324,30 +4324,6 @@ static const struct alg_test_desc alg_test_descs[] = { .suite = { .hash = __VECS(blake2b_512_tv_template) } - }, { - .alg = "blake2s-128", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_128_tv_template) - } - }, { - .alg = "blake2s-160", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_160_tv_template) - } - }, { - .alg = "blake2s-224", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_224_tv_template) - } - }, { - .alg = "blake2s-256", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_256_tv_template) - } }, { .alg = "cbc(aes)", .test = alg_test_skcipher,
crypto/testmgr.h +0 -217
221 lines not on this page · raw message
include/crypto/internal/blake2s.h +0 -108
118 lines not on this page · raw message
lib/crypto/blake2s-selftest.c +39 -0
@@ -4,6 +4,8 @@*/ #include <crypto/internal/blake2s.h> +#include <linux/kernel.h> +#include <linux/random.h> #include <linux/string.h> /*
@@ -587,5 +589,42 @@ bool __init blake2s_selftest(void) } } +for (i =0 ; i <100 ; ++i) { +u8 unaligned_block[BLAKE2S_BLOCK_SIZE +sizeof (long ) -1 ] +__aligned(sizeof(long)) ; +u8 blocks[BLAKE2S_BLOCK_SIZE *4 ]; +struct blake2s_state state1, state2; + +get_random_bytes (blocks,sizeof (blocks)); +get_random_bytes (&state,sizeof (state)); + +#ifdef CONFIG_CRYPTO_LIB_BLAKE2S_GENERIC +memcpy (&state1, &state,sizeof (state1)); +memcpy (&state2, &state,sizeof (state2)); +blake2s_compress (&state1, blocks,4 ,sizeof (blocks)); +blake2s_compress_generic (&state2, blocks,4 ,sizeof (blocks)); +if (memcmp (&state1, &state2,sizeof (state1))) { +pr_err ("blake2s random compress self-test %d: FAIL\n" , + i +1 ); + success = false; + } +#endif + +memcpy (&state1, &state,sizeof (state1)); +blake2s_compress (&state1, blocks,1 ,BLAKE2S_BLOCK_SIZE ); +for (l =1 ; l <sizeof (long ); ++l) { +memcpy (unaligned_block + l, blocks, +BLAKE2S_BLOCK_SIZE ); +memcpy (&state2, &state,sizeof (state2)); +blake2s_compress (&state2, unaligned_block + l,1 , +BLAKE2S_BLOCK_SIZE ); +if (memcmp (&state1, &state2,sizeof (state1))) { +pr_err ("blake2s random compress align %d self-test %d: FAIL\n" , + l, i +1 ); + success = false; + } + } + } +return success; }
lib/crypto/blake2s.c +30 -7
@@ -16,16 +16,44 @@#include <linux/init.h> #include <linux/bug.h> +static inline void blake2s_set_lastblock (struct blake2s_state *state) +{ + state->f[0 ] =-1 ; +} +void blake2s_update (struct blake2s_state *state,const u8 *in,size_t inlen) { -__blake2s_update (state, in, inlen, false); +const size_t fill =BLAKE2S_BLOCK_SIZE - state->buflen; + +if (unlikely (!inlen)) +return ; +if (inlen > fill) { +memcpy (state->buf + state->buflen, in, fill); +blake2s_compress (state, state->buf,1 ,BLAKE2S_BLOCK_SIZE ); + state->buflen =0 ; + in += fill; + inlen -= fill; + } +if (inlen >BLAKE2S_BLOCK_SIZE ) { +const size_t nblocks =DIV_ROUND_UP (inlen,BLAKE2S_BLOCK_SIZE ); +blake2s_compress (state, in, nblocks -1 ,BLAKE2S_BLOCK_SIZE ); + in +=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + inlen -=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + } +memcpy (state->buf + state->buflen, in, inlen); + state->buflen += inlen; }EXPORT_SYMBOL (blake2s_update);void blake2s_final (struct blake2s_state *state,u8 *out) {WARN_ON (IS_ENABLED (DEBUG ) && !out); -__blake2s_final (state, out, false); +blake2s_set_lastblock (state); +memset (state->buf + state->buflen,0 , +BLAKE2S_BLOCK_SIZE - state->buflen);/* Padding */ +blake2s_compress (state, state->buf,1 , state->buflen); +cpu_to_le32_array (state->h,ARRAY_SIZE (state->h)); +memcpy (out, state->h, state->outlen);memzero_explicit (state,sizeof (*state)); }EXPORT_SYMBOL (blake2s_final);
@@ -38,12 +66,7 @@ static int __init blake2s_mod_init(void)return 0 ; } -static void __exit blake2s_mod_exit(void) -{ -} -module_init (blake2s_mod_init); -module_exit (blake2s_mod_exit);MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("BLAKE2s hash function" );MODULE_AUTHOR ("Jason A. Donenfeld <[email protected]>" );
Signature · 1 line
2.35.1
Eric Biggers
maintainerQuoted 3 lines · Jason A. Donenfeld
Quoted 1 line
Also, the wrong value is being passed for the 'inc' argument.
Are you sure? Not sure I'm seeing what you are on first glance.
Yes, 'inc' is the increment amount per block. It needs to always be BLAKE2S_BLOCK_SIZE unless a partial block is being processed.
- Eric
Jason A. Donenfeld
maintainerQuoted 8 lines · Eric Biggers
Quoted 3 lines · Jason A. Donenfeld
Quoted 1 line
Also, the wrong value is being passed for the 'inc' argument.
Are you sure? Not sure I'm seeing what you are on first glance.
Yes, 'inc' is the increment amount per block. It needs to always be
BLAKE2S_BLOCK_SIZEunless a partial block is being processed.
Bingo, thanks. v+1 coming up.
Jason
Jason A. Donenfeld
maintainerPATCH v4 1/1 crypto: blake2s - remove shash module
BLAKE2s has no currently known use as an shash. Just remove all of this unnecessary plumbing. Removing this shash was something we talked about back when we were making BLAKE2s a built-in, but I simply never got around to doing it. So this completes that project.
Importantly, this fixs a bug in which the lib code depends on crypto_simd_disabled_for_test, causing linker errors.
Also add more alignment tests to the selftests and compare SIMD and non-SIMD compression functions, to make up for what we lose from testmgr.c.
--- arch/arm/crypto/Kconfig | 2 +- arch/arm/crypto/Makefile | 4 +- arch/arm/crypto/blake2s-shash.c | 75 ----------- arch/x86/crypto/Makefile | 4 +- arch/x86/crypto/blake2s-glue.c | 3 +- arch/x86/crypto/blake2s-shash.c | 77 ----------- crypto/Kconfig | 20 +-- crypto/Makefile | 1 - crypto/blake2s_generic.c | 75 ----------- crypto/tcrypt.c | 12 -- crypto/testmgr.c | 24 ---- crypto/testmgr.h | 217 ------------------------------ include/crypto/internal/blake2s.h | 108 --------------- lib/crypto/blake2s-selftest.c | 41 ++++++ lib/crypto/blake2s.c | 37 ++++- 15 files changed, 76 insertions(+), 624 deletions(-) delete mode 100644 arch/arm/crypto/blake2s-shash.c delete mode 100644 arch/x86/crypto/blake2s-shash.c delete mode 100644 crypto/blake2s_generic.c
arch/arm/crypto/Kconfig +1 -1
@@ -63,7 +63,7 @@ config CRYPTO_SHA512_ARM using optimized ARM assembler and NEON, when available. config CRYPTO_BLAKE2S_ARM - tristate "BLAKE2s digest algorithm (ARM)" + bool "BLAKE2s digest algorithm (ARM)" select CRYPTO_ARCH_HAVE_LIB_BLAKE2S help BLAKE2s digest algorithm optimized with ARM scalar instructions. This
arch/arm/crypto/Makefile +1 -3
@@ -9,8 +9,7 @@ obj-$(CONFIG_CRYPTO_SHA1_ARM) += sha1-arm.o obj-$(CONFIG_CRYPTO_SHA1_ARM_NEON) += sha1-arm-neon.o obj-$(CONFIG_CRYPTO_SHA256_ARM) += sha256-arm.o obj-$(CONFIG_CRYPTO_SHA512_ARM) += sha512-arm.o -obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += blake2s-arm.o -obj-$(if $(CONFIG_CRYPTO_BLAKE2S_ARM),y) += libblake2s-arm.o +obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += libblake2s-arm.o obj-$(CONFIG_CRYPTO_BLAKE2B_NEON) += blake2b-neon.o obj-$(CONFIG_CRYPTO_CHACHA20_NEON) += chacha-neon.o obj-$(CONFIG_CRYPTO_POLY1305_ARM) += poly1305-arm.o
@@ -32,7 +31,6 @@ sha256-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha256_neon_glue.o sha256-arm-y := sha256-core.o sha256_glue.o $(sha256-arm-neon-y) sha512-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha512-neon-glue.o sha512-arm-y := sha512-core.o sha512-glue.o $(sha512-arm-neon-y) -blake2s-arm-y := blake2s-shash.o libblake2s-arm-y:= blake2s-core.o blake2s-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
arch/arm/crypto/blake2s-shash.c deleted +0 -75
75 lines not on this page · raw message
arch/x86/crypto/Makefile +1 -3
@@ -61,9 +61,7 @@ sha256-ssse3-$(CONFIG_AS_SHA256_NI) += sha256_ni_asm.o obj-$(CONFIG_CRYPTO_SHA512_SSSE3) += sha512-ssse3.o sha512-ssse3-y := sha512-ssse3-asm.o sha512-avx-asm.o sha512-avx2-asm.o sha512_ssse3_glue.o -obj-$(CONFIG_CRYPTO_BLAKE2S_X86) += blake2s-x86_64.o -blake2s-x86_64-y := blake2s-shash.o -obj-$(if $(CONFIG_CRYPTO_BLAKE2S_X86),y) += libblake2s-x86_64.o +obj-$(CONFIG_CRYPTO_BLAKE2S_X86) += libblake2s-x86_64.o libblake2s-x86_64-y := blake2s-core.o blake2s-glue.o obj-$(CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL) += ghash-clmulni-intel.o
arch/x86/crypto/blake2s-glue.c +1 -2
@@ -4,7 +4,6 @@*/ #include <crypto/internal/blake2s.h> -#include <crypto/internal/simd.h> #include <linux/types.h> #include <linux/jump_label.h>
@@ -33,7 +32,7 @@ void blake2s_compress(struct blake2s_state *state, const u8 *block,/* SIMD disables preemption, so relax after processing each page. */ BUILD_BUG_ON (SZ_4K /BLAKE2S_BLOCK_SIZE <8 ); -if (!static_branch_likely (&blake2s_use_ssse3) || !crypto_simd_usable ()) { +if (!static_branch_likely (&blake2s_use_ssse3) || !may_use_simd ()) {blake2s_compress_generic (state, block, nblocks, inc);return ; }
arch/x86/crypto/blake2s-shash.c deleted +0 -77
77 lines not on this page · raw message
crypto/Kconfig +1 -19
@@ -692,26 +692,8 @@ config CRYPTO_BLAKE2B See https://blake2.net for further information. -config CRYPTO_BLAKE2S - tristate "BLAKE2s digest algorithm" - select CRYPTO_LIB_BLAKE2S_GENERIC - select CRYPTO_HASH - help - Implementation of cryptographic hash function BLAKE2s - optimized for 8-32bit platforms and can produce digests of any size - between 1 to 32. The keyed hash is also implemented. - - This module provides the following algorithms: - - - blake2s-128 - - blake2s-160 - - blake2s-224 - - blake2s-256 - - See https://blake2.net for further information. - config CRYPTO_BLAKE2S_X86 - tristate "BLAKE2s digest algorithm (x86 accelerated version)" + bool "BLAKE2s digest algorithm (x86 accelerated version)" depends on X86 && 64BIT select CRYPTO_LIB_BLAKE2S_GENERIC select CRYPTO_ARCH_HAVE_LIB_BLAKE2S
crypto/Makefile +0 -1
@@ -83,7 +83,6 @@ obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o obj-$(CONFIG_CRYPTO_WP512) += wp512.o CFLAGS_wp512.o := $(call cc-option,-fno-schedule-insns) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149 obj-$(CONFIG_CRYPTO_BLAKE2B) += blake2b_generic.o -obj-$(CONFIG_CRYPTO_BLAKE2S) += blake2s_generic.o obj-$(CONFIG_CRYPTO_GF128MUL) += gf128mul.o obj-$(CONFIG_CRYPTO_ECB) += ecb.o obj-$(CONFIG_CRYPTO_CBC) += cbc.o
crypto/blake2s_generic.c deleted +0 -75
75 lines not on this page · raw message
crypto/tcrypt.c +0 -12
@@ -1669,10 +1669,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) ret +=tcrypt_test ("rmd160" );break ; -case 41 : - ret +=tcrypt_test ("blake2s-256" ); -break ; -case 42 : ret +=tcrypt_test ("blake2b-512" );break ;
@@ -2240,10 +2236,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)test_hash_speed ("rmd160" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ; fallthrough; -case 316 : -test_hash_speed ("blake2s-256" , sec, generic_hash_speed_template); -if (mode >300 && mode <400 )break ; - fallthrough;case 317 :test_hash_speed ("blake2b-512" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ;
@@ -2352,10 +2344,6 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)test_ahash_speed ("rmd160" , sec, generic_hash_speed_template);if (mode >400 && mode <500 )break ; fallthrough; -case 416 : -test_ahash_speed ("blake2s-256" , sec, generic_hash_speed_template); -if (mode >400 && mode <500 )break ; - fallthrough;case 417 :test_ahash_speed ("blake2b-512" , sec, generic_hash_speed_template);if (mode >400 && mode <500 )break ;
crypto/testmgr.c +0 -24
@@ -4324,30 +4324,6 @@ static const struct alg_test_desc alg_test_descs[] = { .suite = { .hash = __VECS(blake2b_512_tv_template) } - }, { - .alg = "blake2s-128", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_128_tv_template) - } - }, { - .alg = "blake2s-160", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_160_tv_template) - } - }, { - .alg = "blake2s-224", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_224_tv_template) - } - }, { - .alg = "blake2s-256", - .test = alg_test_hash, - .suite = { - .hash = __VECS(blakes2s_256_tv_template) - } }, { .alg = "cbc(aes)", .test = alg_test_skcipher,
crypto/testmgr.h +0 -217
221 lines not on this page · raw message
include/crypto/internal/blake2s.h +0 -108
118 lines not on this page · raw message
lib/crypto/blake2s-selftest.c +41 -0
52 lines not on this page · raw message
lib/crypto/blake2s.c +30 -7
@@ -16,16 +16,44 @@#include <linux/init.h> #include <linux/bug.h> +static inline void blake2s_set_lastblock (struct blake2s_state *state) +{ + state->f[0 ] =-1 ; +} +void blake2s_update (struct blake2s_state *state,const u8 *in,size_t inlen) { -__blake2s_update (state, in, inlen, false); +const size_t fill =BLAKE2S_BLOCK_SIZE - state->buflen; + +if (unlikely (!inlen)) +return ; +if (inlen > fill) { +memcpy (state->buf + state->buflen, in, fill); +blake2s_compress (state, state->buf,1 ,BLAKE2S_BLOCK_SIZE ); + state->buflen =0 ; + in += fill; + inlen -= fill; + } +if (inlen >BLAKE2S_BLOCK_SIZE ) { +const size_t nblocks =DIV_ROUND_UP (inlen,BLAKE2S_BLOCK_SIZE ); +blake2s_compress (state, in, nblocks -1 ,BLAKE2S_BLOCK_SIZE ); + in +=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + inlen -=BLAKE2S_BLOCK_SIZE * (nblocks -1 ); + } +memcpy (state->buf + state->buflen, in, inlen); + state->buflen += inlen; }EXPORT_SYMBOL (blake2s_update);void blake2s_final (struct blake2s_state *state,u8 *out) {WARN_ON (IS_ENABLED (DEBUG ) && !out); -__blake2s_final (state, out, false); +blake2s_set_lastblock (state); +memset (state->buf + state->buflen,0 , +BLAKE2S_BLOCK_SIZE - state->buflen);/* Padding */ +blake2s_compress (state, state->buf,1 , state->buflen); +cpu_to_le32_array (state->h,ARRAY_SIZE (state->h)); +memcpy (out, state->h, state->outlen);memzero_explicit (state,sizeof (*state)); }EXPORT_SYMBOL (blake2s_final);
@@ -38,12 +66,7 @@ static int __init blake2s_mod_init(void)return 0 ; } -static void __exit blake2s_mod_exit(void) -{ -} -module_init (blake2s_mod_init); -module_exit (blake2s_mod_exit);MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("BLAKE2s hash function" );MODULE_AUTHOR ("Jason A. Donenfeld <[email protected]>" );
Signature · 1 line
2.35.1
Herbert Xu
maintainerQuoted 30 lines · Jason A. Donenfeld
BLAKE2s has no currently known use as an shash. Just remove all of this unnecessary plumbing. Removing this shash was something we talked about back when we were making BLAKE2s a built-in, but I simply never got around to doing it. So this completes that project.
Importantly, this fixs a bug in which the lib code depends on
crypto_simd_disabled_for_test, causing linker errors.Also add more alignment tests to the selftests and compare SIMD and non-SIMD compression functions, to make up for what we lose from
testmgr.c.Reported-by gaochao <[email protected]>Cc Eric Biggers <[email protected]>Cc Ard Biesheuvel <[email protected]>Fixes 6048fdcc5f26 ("lib/crypto: blake2s: include as built-in")Signed-off-by Jason A. Donenfeld <[email protected]>--- arch/arm/crypto/Kconfig | 2 +- arch/arm/crypto/Makefile | 4 +- arch/arm/crypto/blake2s-shash.c | 75 ----------- arch/x86/crypto/Makefile | 4 +- arch/x86/crypto/blake2s-glue.c | 3 +- arch/x86/crypto/blake2s-shash.c | 77 ----------- crypto/Kconfig | 20 +-- crypto/Makefile | 1 - crypto/blake2s_generic.c | 75 ----------- crypto/tcrypt.c | 12 -- crypto/testmgr.c | 24 ----
Quoted 8 lines
crypto/testmgr.h | 217 ------------------------------ include/crypto/internal/blake2s.h | 108 --------------- lib/crypto/blake2s-selftest.c | 41 ++++++ lib/crypto/blake2s.c | 37 ++++- 15 files changed, 76 insertions(+), 624 deletions(-) delete mode 100644 arch/arm/crypto/blake2s-shash.c delete mode 100644 arch/x86/crypto/blake2s-shash.c delete mode 100644 crypto/blake2s_generic.c
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
From: Eric Biggers
Quoted 9 lines
Sent: 28 May 2022 18:20
Quoted 3 lines · Jason A. Donenfeld
Quoted 1 line
Also, the wrong value is being passed for the 'inc' argument.
Are you sure? Not sure I'm seeing what you are on first glance.
Yes, 'inc' is the increment amount per block. It needs to always be
BLAKE2S_BLOCK_SIZEunless a partial block is being processed.
IIRC it isn't used for partial blocks.
Which rather begs the question as to why it is a parameter at all.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Jason A. Donenfeld
maintainerQuoted 6 lines · David Laight
From: Eric Biggers
Quoted 5 lines
Sent: 28 May 2022 18:20
Quoted 2 lines · Jason A. Donenfeld
Quoted 1 line
Also, the wrong value is being passed for the 'inc' argument.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Are you sure? Not sure I'm seeing what you are on first glance.
Yes, 'inc' is the increment amount per block. It needs to always be
BLAKE2S_BLOCK_SIZEunless a partial block is being processed.IIRC it isn't used for partial blocks.
Which rather begs the question as to why it is a parameter at all.
Again, with blake2s, please send a patch if you think there's an improvement to be made.
In this case, I don't think you're right. See blake2s_final.
Jason