diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2023-05-19 17:04:04 +0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2023-05-24 18:12:33 +0800 |
commit | b7be31b0d5088507b745bfa014798e52fad6dc7a (patch) | |
tree | df257538a796e23a06638e8bed8b57ef8d5534f4 | |
parent | ed51bba18f563594b5ddf7aaa5fd61abe5e474ae (diff) | |
download | linux-stable-b7be31b0d5088507b745bfa014798e52fad6dc7a.tar.gz linux-stable-b7be31b0d5088507b745bfa014798e52fad6dc7a.tar.bz2 linux-stable-b7be31b0d5088507b745bfa014798e52fad6dc7a.zip |
crypto: shash - Allow cloning on algorithms with no init_tfm
Some shash algorithms are so simple that they don't have an init_tfm
function. These can be cloned trivially. Check this before failing
in crypto_clone_shash.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/shash.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/crypto/shash.c b/crypto/shash.c index 717b42df3495..1fadb6b59bdc 100644 --- a/crypto/shash.c +++ b/crypto/shash.c @@ -597,7 +597,7 @@ struct crypto_shash *crypto_clone_shash(struct crypto_shash *hash) return hash; } - if (!alg->clone_tfm) + if (!alg->clone_tfm && (alg->init_tfm || alg->base.cra_init)) return ERR_PTR(-ENOSYS); nhash = crypto_clone_tfm(&crypto_shash_type, tfm); @@ -606,10 +606,12 @@ struct crypto_shash *crypto_clone_shash(struct crypto_shash *hash) nhash->descsize = hash->descsize; - err = alg->clone_tfm(nhash, hash); - if (err) { - crypto_free_shash(nhash); - return ERR_PTR(err); + if (alg->clone_tfm) { + err = alg->clone_tfm(nhash, hash); + if (err) { + crypto_free_shash(nhash); + return ERR_PTR(err); + } } return nhash; |