]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: hmac - Add export_core and import_core
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 15 May 2025 05:54:42 +0000 (13:54 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 19 May 2025 05:48:19 +0000 (13:48 +0800)
Add export_import and import_core so that hmac can be used as a
fallback by block-only drivers.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/hmac.c

index 4517e04bfbaa41dd839d5fe2993a8b819df17a3d..e4749a1f93ddda3b44d3e3ded1b562ebe14a957f 100644 (file)
@@ -90,6 +90,22 @@ static int hmac_import(struct shash_desc *pdesc, const void *in)
        return crypto_shash_import(desc, in);
 }
 
+static int hmac_export_core(struct shash_desc *pdesc, void *out)
+{
+       struct shash_desc *desc = shash_desc_ctx(pdesc);
+
+       return crypto_shash_export_core(desc, out);
+}
+
+static int hmac_import_core(struct shash_desc *pdesc, const void *in)
+{
+       const struct hmac_ctx *tctx = crypto_shash_ctx(pdesc->tfm);
+       struct shash_desc *desc = shash_desc_ctx(pdesc);
+
+       desc->tfm = tctx->hash;
+       return crypto_shash_import_core(desc, in);
+}
+
 static int hmac_init(struct shash_desc *pdesc)
 {
        const struct hmac_ctx *tctx = crypto_shash_ctx(pdesc->tfm);
@@ -177,6 +193,7 @@ static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
                return -ENOMEM;
        spawn = shash_instance_ctx(inst);
 
+       mask |= CRYPTO_AHASH_ALG_NO_EXPORT_CORE;
        err = crypto_grab_shash(spawn, shash_crypto_instance(inst),
                                crypto_attr_alg_name(tb[1]), 0, mask);
        if (err)
@@ -211,6 +228,8 @@ static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
        inst->alg.finup = hmac_finup;
        inst->alg.export = hmac_export;
        inst->alg.import = hmac_import;
+       inst->alg.export_core = hmac_export_core;
+       inst->alg.import_core = hmac_import_core;
        inst->alg.setkey = hmac_setkey;
        inst->alg.init_tfm = hmac_init_tfm;
        inst->alg.clone_tfm = hmac_clone_tfm;