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