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 | c57b1230d225c7a063cd9e7ba0086ec029b234e4 (patch) | |
tree | ea24df1052ac7b62fea0c3e1174dbc2adec528f5 | |
parent | 6f531739f0baa322e64e1bf67f9a8e6a45192ea3 (diff) | |
download | linux-crypto-c57b1230d225c7a063cd9e7ba0086ec029b234e4.tar.gz linux-crypto-c57b1230d225c7a063cd9e7ba0086ec029b234e4.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 717b42df..1fadb6b5 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; |