Skip to content

Commit 8538e60

Browse files
committed
crypto: hmac - Add support for cloning
Allow hmac to be cloned. The underlying hash can be used directly with a reference count. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent ed3630b commit 8538e60

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crypto/hmac.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ static int hmac_init_tfm(struct crypto_shash *parent)
160160
return 0;
161161
}
162162

163+
static int hmac_clone_tfm(struct crypto_shash *dst, struct crypto_shash *src)
164+
{
165+
struct hmac_ctx *sctx = hmac_ctx(src);
166+
struct hmac_ctx *dctx = hmac_ctx(dst);
167+
struct crypto_shash *hash;
168+
169+
hash = crypto_clone_shash(sctx->hash);
170+
if (IS_ERR(hash))
171+
return PTR_ERR(hash);
172+
173+
dctx->hash = hash;
174+
return 0;
175+
}
176+
163177
static void hmac_exit_tfm(struct crypto_shash *parent)
164178
{
165179
struct hmac_ctx *ctx = hmac_ctx(parent);
@@ -227,6 +241,7 @@ static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
227241
inst->alg.import = hmac_import;
228242
inst->alg.setkey = hmac_setkey;
229243
inst->alg.init_tfm = hmac_init_tfm;
244+
inst->alg.clone_tfm = hmac_clone_tfm;
230245
inst->alg.exit_tfm = hmac_exit_tfm;
231246

232247
inst->free = shash_free_singlespawn_instance;

0 commit comments

Comments
 (0)