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>
This commit is contained in:
Herbert Xu 2023-05-19 17:04:04 +08:00
parent ed51bba18f
commit b7be31b0d5
1 changed files with 7 additions and 5 deletions

View File

@ -597,7 +597,7 @@ struct crypto_shash *crypto_clone_shash(struct crypto_shash *hash)
return hash; return hash;
} }
if (!alg->clone_tfm) if (!alg->clone_tfm && (alg->init_tfm || alg->base.cra_init))
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
nhash = crypto_clone_tfm(&crypto_shash_type, tfm); 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; nhash->descsize = hash->descsize;
err = alg->clone_tfm(nhash, hash); if (alg->clone_tfm) {
if (err) { err = alg->clone_tfm(nhash, hash);
crypto_free_shash(nhash); if (err) {
return ERR_PTR(err); crypto_free_shash(nhash);
return ERR_PTR(err);
}
} }
return nhash; return nhash;