^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) * Copyright (C)2006 USAGI/WIDE Project
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Kazunori Miyazawa <miyazawa@linux-ipv6.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <crypto/internal/cipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <crypto/internal/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 0x02020202, 0x02020202, 0x02020202, 0x02020202,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 0x03030303, 0x03030303, 0x03030303, 0x03030303};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * +------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * | <parent tfm>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * +------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * | xcbc_tfm_ctx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * +------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * | consts (block size * 2)
^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) struct xcbc_tfm_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct crypto_cipher *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u8 ctx[];
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * +------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * | <shash desc>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * +------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * | xcbc_desc_ctx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * +------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * | odds (block size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * +------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * | prev (block size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * +------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct xcbc_desc_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u8 ctx[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define XCBC_BLOCKSIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int crypto_xcbc_digest_setkey(struct crypto_shash *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) const u8 *inkey, unsigned int keylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned long alignmask = crypto_shash_alignmask(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct xcbc_tfm_ctx *ctx = crypto_shash_ctx(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u8 *consts = PTR_ALIGN(&ctx->ctx[0], alignmask + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u8 key1[XCBC_BLOCKSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int bs = sizeof(key1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if ((err = crypto_cipher_setkey(ctx->child, inkey, keylen)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) crypto_cipher_encrypt_one(ctx->child, consts, (u8 *)ks + bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) crypto_cipher_encrypt_one(ctx->child, consts + bs, (u8 *)ks + bs * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) crypto_cipher_encrypt_one(ctx->child, key1, (u8 *)ks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return crypto_cipher_setkey(ctx->child, key1, bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static int crypto_xcbc_digest_init(struct shash_desc *pdesc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) unsigned long alignmask = crypto_shash_alignmask(pdesc->tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct xcbc_desc_ctx *ctx = shash_desc_ctx(pdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int bs = crypto_shash_blocksize(pdesc->tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u8 *prev = PTR_ALIGN(&ctx->ctx[0], alignmask + 1) + bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ctx->len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) memset(prev, 0, bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static int crypto_xcbc_digest_update(struct shash_desc *pdesc, const u8 *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct crypto_shash *parent = pdesc->tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) unsigned long alignmask = crypto_shash_alignmask(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct xcbc_tfm_ctx *tctx = crypto_shash_ctx(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct xcbc_desc_ctx *ctx = shash_desc_ctx(pdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct crypto_cipher *tfm = tctx->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int bs = crypto_shash_blocksize(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u8 *odds = PTR_ALIGN(&ctx->ctx[0], alignmask + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u8 *prev = odds + bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* checking the data can fill the block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if ((ctx->len + len) <= bs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) memcpy(odds + ctx->len, p, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ctx->len += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* filling odds with new data and encrypting it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) memcpy(odds + ctx->len, p, bs - ctx->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) len -= bs - ctx->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) p += bs - ctx->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) crypto_xor(prev, odds, bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) crypto_cipher_encrypt_one(tfm, prev, prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* clearing the length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ctx->len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* encrypting the rest of data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) while (len > bs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) crypto_xor(prev, p, bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) crypto_cipher_encrypt_one(tfm, prev, prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) p += bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) len -= bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* keeping the surplus of blocksize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) memcpy(odds, p, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ctx->len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int crypto_xcbc_digest_final(struct shash_desc *pdesc, u8 *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct crypto_shash *parent = pdesc->tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned long alignmask = crypto_shash_alignmask(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct xcbc_tfm_ctx *tctx = crypto_shash_ctx(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct xcbc_desc_ctx *ctx = shash_desc_ctx(pdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct crypto_cipher *tfm = tctx->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int bs = crypto_shash_blocksize(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) u8 *consts = PTR_ALIGN(&tctx->ctx[0], alignmask + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u8 *odds = PTR_ALIGN(&ctx->ctx[0], alignmask + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) u8 *prev = odds + bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsigned int offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (ctx->len != bs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) unsigned int rlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u8 *p = odds + ctx->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) *p = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) rlen = bs - ctx->len -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (rlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) memset(p, 0, rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) offset += bs;
^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) crypto_xor(prev, odds, bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) crypto_xor(prev, consts + offset, bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) crypto_cipher_encrypt_one(tfm, out, prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int xcbc_init_tfm(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct crypto_cipher *cipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct crypto_instance *inst = (void *)tfm->__crt_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct crypto_cipher_spawn *spawn = crypto_instance_ctx(inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct xcbc_tfm_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) cipher = crypto_spawn_cipher(spawn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (IS_ERR(cipher))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return PTR_ERR(cipher);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ctx->child = cipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void xcbc_exit_tfm(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct xcbc_tfm_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) crypto_free_cipher(ctx->child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct shash_instance *inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct crypto_cipher_spawn *spawn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct crypto_alg *alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) unsigned long alignmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) u32 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (!inst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) spawn = shash_instance_ctx(inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) err = crypto_grab_cipher(spawn, shash_crypto_instance(inst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) crypto_attr_alg_name(tb[1]), 0, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) goto err_free_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) alg = crypto_spawn_cipher_alg(spawn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (alg->cra_blocksize != XCBC_BLOCKSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) goto err_free_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) err = crypto_inst_setname(shash_crypto_instance(inst), tmpl->name, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) goto err_free_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) alignmask = alg->cra_alignmask | 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) inst->alg.base.cra_alignmask = alignmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) inst->alg.base.cra_priority = alg->cra_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) inst->alg.base.cra_blocksize = alg->cra_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) inst->alg.digestsize = alg->cra_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) inst->alg.descsize = ALIGN(sizeof(struct xcbc_desc_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) crypto_tfm_ctx_alignment()) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) (alignmask &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ~(crypto_tfm_ctx_alignment() - 1)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) alg->cra_blocksize * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) inst->alg.base.cra_ctxsize = ALIGN(sizeof(struct xcbc_tfm_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) alignmask + 1) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) alg->cra_blocksize * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) inst->alg.base.cra_init = xcbc_init_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) inst->alg.base.cra_exit = xcbc_exit_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) inst->alg.init = crypto_xcbc_digest_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) inst->alg.update = crypto_xcbc_digest_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) inst->alg.final = crypto_xcbc_digest_final;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) inst->alg.setkey = crypto_xcbc_digest_setkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) inst->free = shash_free_singlespawn_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) err = shash_register_instance(tmpl, inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) err_free_inst:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) shash_free_singlespawn_instance(inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return err;
^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) static struct crypto_template crypto_xcbc_tmpl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .name = "xcbc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .create = xcbc_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static int __init crypto_xcbc_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return crypto_register_template(&crypto_xcbc_tmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static void __exit crypto_xcbc_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) crypto_unregister_template(&crypto_xcbc_tmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) subsys_initcall(crypto_xcbc_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) module_exit(crypto_xcbc_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) MODULE_DESCRIPTION("XCBC keyed hash algorithm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) MODULE_ALIAS_CRYPTO("xcbc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) MODULE_IMPORT_NS(CRYPTO_INTERNAL);