Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Cryptographic API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * HMAC: Keyed-Hashing for Message Authentication (RFC2104).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * The HMAC implementation is derived from USAGI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright (c) 2002 Kazunori Miyazawa <miyazawa@linux-ipv6.org> / USAGI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <crypto/hmac.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <crypto/internal/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <crypto/scatterwalk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct hmac_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct crypto_shash *hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static inline void *align_ptr(void *p, unsigned int align)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	return (void *)ALIGN((unsigned long)p, align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static inline struct hmac_ctx *hmac_ctx(struct crypto_shash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return align_ptr(crypto_shash_ctx_aligned(tfm) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			 crypto_shash_statesize(tfm) * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			 crypto_tfm_ctx_alignment());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static int hmac_setkey(struct crypto_shash *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		       const u8 *inkey, unsigned int keylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	int bs = crypto_shash_blocksize(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int ds = crypto_shash_digestsize(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	int ss = crypto_shash_statesize(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	char *ipad = crypto_shash_ctx_aligned(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	char *opad = ipad + ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct hmac_ctx *ctx = align_ptr(opad + ss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 					 crypto_tfm_ctx_alignment());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct crypto_shash *hash = ctx->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	SHASH_DESC_ON_STACK(shash, hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	shash->tfm = hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (keylen > bs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		err = crypto_shash_digest(shash, inkey, keylen, ipad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		keylen = ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		memcpy(ipad, inkey, keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	memset(ipad + keylen, 0, bs - keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	memcpy(opad, ipad, bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	for (i = 0; i < bs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		ipad[i] ^= HMAC_IPAD_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		opad[i] ^= HMAC_OPAD_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	return crypto_shash_init(shash) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	       crypto_shash_update(shash, ipad, bs) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	       crypto_shash_export(shash, ipad) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	       crypto_shash_init(shash) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	       crypto_shash_update(shash, opad, bs) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	       crypto_shash_export(shash, opad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int hmac_export(struct shash_desc *pdesc, void *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct shash_desc *desc = shash_desc_ctx(pdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return crypto_shash_export(desc, out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int hmac_import(struct shash_desc *pdesc, const void *in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct shash_desc *desc = shash_desc_ctx(pdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct hmac_ctx *ctx = hmac_ctx(pdesc->tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	desc->tfm = ctx->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return crypto_shash_import(desc, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int hmac_init(struct shash_desc *pdesc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return hmac_import(pdesc, crypto_shash_ctx_aligned(pdesc->tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int hmac_update(struct shash_desc *pdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		       const u8 *data, unsigned int nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct shash_desc *desc = shash_desc_ctx(pdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return crypto_shash_update(desc, data, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int hmac_final(struct shash_desc *pdesc, u8 *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct crypto_shash *parent = pdesc->tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	int ds = crypto_shash_digestsize(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	int ss = crypto_shash_statesize(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	char *opad = crypto_shash_ctx_aligned(parent) + ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct shash_desc *desc = shash_desc_ctx(pdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return crypto_shash_final(desc, out) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	       crypto_shash_import(desc, opad) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	       crypto_shash_finup(desc, out, ds, out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int hmac_finup(struct shash_desc *pdesc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		      unsigned int nbytes, u8 *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct crypto_shash *parent = pdesc->tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int ds = crypto_shash_digestsize(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	int ss = crypto_shash_statesize(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	char *opad = crypto_shash_ctx_aligned(parent) + ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct shash_desc *desc = shash_desc_ctx(pdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	return crypto_shash_finup(desc, data, nbytes, out) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	       crypto_shash_import(desc, opad) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	       crypto_shash_finup(desc, out, ds, out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int hmac_init_tfm(struct crypto_shash *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct crypto_shash *hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct shash_instance *inst = shash_alg_instance(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct crypto_shash_spawn *spawn = shash_instance_ctx(inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct hmac_ctx *ctx = hmac_ctx(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	hash = crypto_spawn_shash(spawn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (IS_ERR(hash))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return PTR_ERR(hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	parent->descsize = sizeof(struct shash_desc) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			   crypto_shash_descsize(hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	ctx->hash = hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static void hmac_exit_tfm(struct crypto_shash *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct hmac_ctx *ctx = hmac_ctx(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	crypto_free_shash(ctx->hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct shash_instance *inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct crypto_shash_spawn *spawn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct crypto_alg *alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct shash_alg *salg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	u32 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (!inst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	spawn = shash_instance_ctx(inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	err = crypto_grab_shash(spawn, shash_crypto_instance(inst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				crypto_attr_alg_name(tb[1]), 0, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		goto err_free_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	salg = crypto_spawn_shash_alg(spawn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	alg = &salg->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	/* The underlying hash algorithm must not require a key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (crypto_shash_alg_needs_key(salg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		goto err_free_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	ds = salg->digestsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	ss = salg->statesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (ds > alg->cra_blocksize ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	    ss < alg->cra_blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		goto err_free_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	err = crypto_inst_setname(shash_crypto_instance(inst), tmpl->name, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		goto err_free_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	inst->alg.base.cra_priority = alg->cra_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	inst->alg.base.cra_blocksize = alg->cra_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	inst->alg.base.cra_alignmask = alg->cra_alignmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	ss = ALIGN(ss, alg->cra_alignmask + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	inst->alg.digestsize = ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	inst->alg.statesize = ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	inst->alg.base.cra_ctxsize = sizeof(struct hmac_ctx) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				     ALIGN(ss * 2, crypto_tfm_ctx_alignment());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	inst->alg.init = hmac_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	inst->alg.update = hmac_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	inst->alg.final = hmac_final;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	inst->alg.finup = hmac_finup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	inst->alg.export = hmac_export;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	inst->alg.import = hmac_import;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	inst->alg.setkey = hmac_setkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	inst->alg.init_tfm = hmac_init_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	inst->alg.exit_tfm = hmac_exit_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	inst->free = shash_free_singlespawn_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	err = shash_register_instance(tmpl, inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) err_free_inst:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		shash_free_singlespawn_instance(inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static struct crypto_template hmac_tmpl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	.name = "hmac",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.create = hmac_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	.module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int __init hmac_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return crypto_register_template(&hmac_tmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static void __exit hmac_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	crypto_unregister_template(&hmac_tmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) subsys_initcall(hmac_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) module_exit(hmac_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) MODULE_DESCRIPTION("HMAC hash algorithm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) MODULE_ALIAS_CRYPTO("hmac");