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