crypto: cmac - Add support for cloning

JIRA: https://redhat.atlassian.net/browse/RHEL-142637
Upstream Status: net.git commit ed51bba18f563594b5ddf7aaa5fd61abe5e474ae

commit ed51bba18f563594b5ddf7aaa5fd61abe5e474ae
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Fri May 19 16:28:37 2023 +0800

    crypto: cmac - Add support for cloning

    Allow cmac to be cloned.  The underlying cipher needs to support
    cloning by not having a cra_init function (all implementations of
    aes that do not require a fallback can be cloned).

    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>

Signed-off-by: Davide Caratti <dcaratti@redhat.com>
This commit is contained in:
Davide Caratti
2026-07-06 23:21:04 +02:00
parent fbc09a8a74
commit 70248523f2
+17 -1
View File
@@ -213,7 +213,22 @@ static int cmac_init_tfm(struct crypto_shash *tfm)
ctx->child = cipher;
return 0;
};
}
static int cmac_clone_tfm(struct crypto_shash *tfm, struct crypto_shash *otfm)
{
struct cmac_tfm_ctx *octx = crypto_shash_ctx(otfm);
struct cmac_tfm_ctx *ctx = crypto_shash_ctx(tfm);
struct crypto_cipher *cipher;
cipher = crypto_clone_cipher(octx->child);
if (IS_ERR(cipher))
return PTR_ERR(cipher);
ctx->child = cipher;
return 0;
}
static void cmac_exit_tfm(struct crypto_shash *tfm)
{
@@ -280,6 +295,7 @@ static int cmac_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.final = crypto_cmac_digest_final;
inst->alg.setkey = crypto_cmac_digest_setkey;
inst->alg.init_tfm = cmac_init_tfm;
inst->alg.clone_tfm = cmac_clone_tfm;
inst->alg.exit_tfm = cmac_exit_tfm;
inst->free = shash_free_singlespawn_instance;