Skip to content

Commit

Permalink
crypto: shash - Allow cloning on algorithms with no init_tfm
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
herbertx committed May 24, 2023
1 parent ed51bba commit b7be31b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions crypto/shash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit b7be31b

Please sign in to comment.