aboutsummaryrefslogtreecommitdiffstats
path: root/include/crypto/internal
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2020-12-23 00:09:55 -0800
committerHerbert Xu <herbert@gondor.apana.org.au>2021-01-03 08:41:38 +1100
commit42ad8cf821f0d8564c393e9ad7d00a1a271d18ae (patch)
tree248a9d2169654a353a93d718c048f817a7129430 /include/crypto/internal
parentcrypto: blake2s - share the "shash" API boilerplate code (diff)
downloadlinux-dev-42ad8cf821f0d8564c393e9ad7d00a1a271d18ae.tar.xz
linux-dev-42ad8cf821f0d8564c393e9ad7d00a1a271d18ae.zip
crypto: blake2s - optimize blake2s initialization
If no key was provided, then don't waste time initializing the block buffer, as its initial contents won't be used. Also, make crypto_blake2s_init() and blake2s() call a single internal function __blake2s_init() which treats the key as optional, rather than conditionally calling blake2s_init() or blake2s_init_key(). This reduces the compiled code size, as previously both blake2s_init() and blake2s_init_key() were being inlined into these two callers, except when the key size passed to blake2s() was a compile-time constant. These optimizations aren't that significant for BLAKE2s. However, the equivalent optimizations will be more significant for BLAKE2b, as everything is twice as big in BLAKE2b. And it's good to keep things consistent rather than making optimizations for BLAKE2b but not BLAKE2s. Signed-off-by: Eric Biggers <ebiggers@google.com> Acked-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/crypto/internal')
-rw-r--r--include/crypto/internal/blake2s.h5
1 files changed, 1 insertions, 4 deletions
diff --git a/include/crypto/internal/blake2s.h b/include/crypto/internal/blake2s.h
index 2ea0a8f5e7f4..867ef3753f5c 100644
--- a/include/crypto/internal/blake2s.h
+++ b/include/crypto/internal/blake2s.h
@@ -93,10 +93,7 @@ static inline int crypto_blake2s_init(struct shash_desc *desc)
struct blake2s_state *state = shash_desc_ctx(desc);
unsigned int outlen = crypto_shash_digestsize(desc->tfm);
- if (tctx->keylen)
- blake2s_init_key(state, outlen, tctx->key, tctx->keylen);
- else
- blake2s_init(state, outlen);
+ __blake2s_init(state, outlen, tctx->key, tctx->keylen);
return 0;
}