Skip to content

Commit 8cf4c34

Browse files
committed
crypto: hmac - Add export_core and import_core
Add export_import and import_core so that hmac can be used as a fallback by block-only drivers. Signed-off-by: Herbert Xu <[email protected]>
1 parent a05a8bc commit 8cf4c34

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crypto/hmac.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ static int hmac_import(struct shash_desc *pdesc, const void *in)
9090
return crypto_shash_import(desc, in);
9191
}
9292

93+
static int hmac_export_core(struct shash_desc *pdesc, void *out)
94+
{
95+
struct shash_desc *desc = shash_desc_ctx(pdesc);
96+
97+
return crypto_shash_export_core(desc, out);
98+
}
99+
100+
static int hmac_import_core(struct shash_desc *pdesc, const void *in)
101+
{
102+
const struct hmac_ctx *tctx = crypto_shash_ctx(pdesc->tfm);
103+
struct shash_desc *desc = shash_desc_ctx(pdesc);
104+
105+
desc->tfm = tctx->hash;
106+
return crypto_shash_import_core(desc, in);
107+
}
108+
93109
static int hmac_init(struct shash_desc *pdesc)
94110
{
95111
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)
177193
return -ENOMEM;
178194
spawn = shash_instance_ctx(inst);
179195

196+
mask |= CRYPTO_AHASH_ALG_NO_EXPORT_CORE;
180197
err = crypto_grab_shash(spawn, shash_crypto_instance(inst),
181198
crypto_attr_alg_name(tb[1]), 0, mask);
182199
if (err)
@@ -211,6 +228,8 @@ static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
211228
inst->alg.finup = hmac_finup;
212229
inst->alg.export = hmac_export;
213230
inst->alg.import = hmac_import;
231+
inst->alg.export_core = hmac_export_core;
232+
inst->alg.import_core = hmac_import_core;
214233
inst->alg.setkey = hmac_setkey;
215234
inst->alg.init_tfm = hmac_init_tfm;
216235
inst->alg.clone_tfm = hmac_clone_tfm;

0 commit comments

Comments
 (0)