David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 1 | /* |
| 2 | * PCBC: Propagating Cipher Block Chaining mode |
| 3 | * |
| 4 | * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
| 6 | * |
| 7 | * Derived from cbc.c |
| 8 | * - Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | */ |
| 16 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 17 | #include <crypto/internal/skcipher.h> |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 18 | #include <linux/err.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/module.h> |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 22 | #include <linux/slab.h> |
Gideon Israel Dsouza | d8c34b9 | 2016-12-31 21:26:23 +0530 | [diff] [blame] | 23 | #include <linux/compiler.h> |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 24 | |
| 25 | struct crypto_pcbc_ctx { |
| 26 | struct crypto_cipher *child; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 27 | }; |
| 28 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 29 | static int crypto_pcbc_setkey(struct crypto_skcipher *parent, const u8 *key, |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 30 | unsigned int keylen) |
| 31 | { |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 32 | struct crypto_pcbc_ctx *ctx = crypto_skcipher_ctx(parent); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 33 | struct crypto_cipher *child = ctx->child; |
| 34 | int err; |
| 35 | |
| 36 | crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK); |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 37 | crypto_cipher_set_flags(child, crypto_skcipher_get_flags(parent) & |
| 38 | CRYPTO_TFM_REQ_MASK); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 39 | err = crypto_cipher_setkey(child, key, keylen); |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 40 | crypto_skcipher_set_flags(parent, crypto_cipher_get_flags(child) & |
| 41 | CRYPTO_TFM_RES_MASK); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 42 | return err; |
| 43 | } |
| 44 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 45 | static int crypto_pcbc_encrypt_segment(struct skcipher_request *req, |
| 46 | struct skcipher_walk *walk, |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 47 | struct crypto_cipher *tfm) |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 48 | { |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 49 | int bsize = crypto_cipher_blocksize(tfm); |
| 50 | unsigned int nbytes = walk->nbytes; |
| 51 | u8 *src = walk->src.virt.addr; |
| 52 | u8 *dst = walk->dst.virt.addr; |
| 53 | u8 *iv = walk->iv; |
| 54 | |
| 55 | do { |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 56 | crypto_xor(iv, src, bsize); |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 57 | crypto_cipher_encrypt_one(tfm, dst, iv); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 58 | memcpy(iv, dst, bsize); |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 59 | crypto_xor(iv, src, bsize); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 60 | |
| 61 | src += bsize; |
| 62 | dst += bsize; |
| 63 | } while ((nbytes -= bsize) >= bsize); |
| 64 | |
| 65 | return nbytes; |
| 66 | } |
| 67 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 68 | static int crypto_pcbc_encrypt_inplace(struct skcipher_request *req, |
| 69 | struct skcipher_walk *walk, |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 70 | struct crypto_cipher *tfm) |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 71 | { |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 72 | int bsize = crypto_cipher_blocksize(tfm); |
| 73 | unsigned int nbytes = walk->nbytes; |
| 74 | u8 *src = walk->src.virt.addr; |
| 75 | u8 *iv = walk->iv; |
| 76 | u8 tmpbuf[bsize]; |
| 77 | |
| 78 | do { |
| 79 | memcpy(tmpbuf, src, bsize); |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 80 | crypto_xor(iv, src, bsize); |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 81 | crypto_cipher_encrypt_one(tfm, src, iv); |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 82 | memcpy(iv, tmpbuf, bsize); |
| 83 | crypto_xor(iv, src, bsize); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 84 | |
| 85 | src += bsize; |
| 86 | } while ((nbytes -= bsize) >= bsize); |
| 87 | |
| 88 | memcpy(walk->iv, iv, bsize); |
| 89 | |
| 90 | return nbytes; |
| 91 | } |
| 92 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 93 | static int crypto_pcbc_encrypt(struct skcipher_request *req) |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 94 | { |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 95 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
| 96 | struct crypto_pcbc_ctx *ctx = crypto_skcipher_ctx(tfm); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 97 | struct crypto_cipher *child = ctx->child; |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 98 | struct skcipher_walk walk; |
| 99 | unsigned int nbytes; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 100 | int err; |
| 101 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 102 | err = skcipher_walk_virt(&walk, req, false); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 103 | |
| 104 | while ((nbytes = walk.nbytes)) { |
| 105 | if (walk.src.virt.addr == walk.dst.virt.addr) |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 106 | nbytes = crypto_pcbc_encrypt_inplace(req, &walk, |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 107 | child); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 108 | else |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 109 | nbytes = crypto_pcbc_encrypt_segment(req, &walk, |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 110 | child); |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 111 | err = skcipher_walk_done(&walk, nbytes); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | return err; |
| 115 | } |
| 116 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 117 | static int crypto_pcbc_decrypt_segment(struct skcipher_request *req, |
| 118 | struct skcipher_walk *walk, |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 119 | struct crypto_cipher *tfm) |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 120 | { |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 121 | int bsize = crypto_cipher_blocksize(tfm); |
| 122 | unsigned int nbytes = walk->nbytes; |
| 123 | u8 *src = walk->src.virt.addr; |
| 124 | u8 *dst = walk->dst.virt.addr; |
| 125 | u8 *iv = walk->iv; |
| 126 | |
| 127 | do { |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 128 | crypto_cipher_decrypt_one(tfm, dst, src); |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 129 | crypto_xor(dst, iv, bsize); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 130 | memcpy(iv, src, bsize); |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 131 | crypto_xor(iv, dst, bsize); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 132 | |
| 133 | src += bsize; |
| 134 | dst += bsize; |
| 135 | } while ((nbytes -= bsize) >= bsize); |
| 136 | |
| 137 | memcpy(walk->iv, iv, bsize); |
| 138 | |
| 139 | return nbytes; |
| 140 | } |
| 141 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 142 | static int crypto_pcbc_decrypt_inplace(struct skcipher_request *req, |
| 143 | struct skcipher_walk *walk, |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 144 | struct crypto_cipher *tfm) |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 145 | { |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 146 | int bsize = crypto_cipher_blocksize(tfm); |
| 147 | unsigned int nbytes = walk->nbytes; |
| 148 | u8 *src = walk->src.virt.addr; |
| 149 | u8 *iv = walk->iv; |
Gideon Israel Dsouza | d8c34b9 | 2016-12-31 21:26:23 +0530 | [diff] [blame] | 150 | u8 tmpbuf[bsize] __aligned(__alignof__(u32)); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 151 | |
| 152 | do { |
| 153 | memcpy(tmpbuf, src, bsize); |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 154 | crypto_cipher_decrypt_one(tfm, src, src); |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 155 | crypto_xor(src, iv, bsize); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 156 | memcpy(iv, tmpbuf, bsize); |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 157 | crypto_xor(iv, src, bsize); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 158 | |
| 159 | src += bsize; |
| 160 | } while ((nbytes -= bsize) >= bsize); |
| 161 | |
| 162 | memcpy(walk->iv, iv, bsize); |
| 163 | |
| 164 | return nbytes; |
| 165 | } |
| 166 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 167 | static int crypto_pcbc_decrypt(struct skcipher_request *req) |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 168 | { |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 169 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
| 170 | struct crypto_pcbc_ctx *ctx = crypto_skcipher_ctx(tfm); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 171 | struct crypto_cipher *child = ctx->child; |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 172 | struct skcipher_walk walk; |
| 173 | unsigned int nbytes; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 174 | int err; |
| 175 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 176 | err = skcipher_walk_virt(&walk, req, false); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 177 | |
| 178 | while ((nbytes = walk.nbytes)) { |
| 179 | if (walk.src.virt.addr == walk.dst.virt.addr) |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 180 | nbytes = crypto_pcbc_decrypt_inplace(req, &walk, |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 181 | child); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 182 | else |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 183 | nbytes = crypto_pcbc_decrypt_segment(req, &walk, |
Herbert Xu | d0b9007 | 2007-11-20 17:49:49 +0800 | [diff] [blame] | 184 | child); |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 185 | err = skcipher_walk_done(&walk, nbytes); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | return err; |
| 189 | } |
| 190 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 191 | static int crypto_pcbc_init_tfm(struct crypto_skcipher *tfm) |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 192 | { |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 193 | struct skcipher_instance *inst = skcipher_alg_instance(tfm); |
| 194 | struct crypto_spawn *spawn = skcipher_instance_ctx(inst); |
| 195 | struct crypto_pcbc_ctx *ctx = crypto_skcipher_ctx(tfm); |
Herbert Xu | 2e306ee | 2006-12-17 10:05:58 +1100 | [diff] [blame] | 196 | struct crypto_cipher *cipher; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 197 | |
Herbert Xu | 2e306ee | 2006-12-17 10:05:58 +1100 | [diff] [blame] | 198 | cipher = crypto_spawn_cipher(spawn); |
| 199 | if (IS_ERR(cipher)) |
| 200 | return PTR_ERR(cipher); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 201 | |
Herbert Xu | 2e306ee | 2006-12-17 10:05:58 +1100 | [diff] [blame] | 202 | ctx->child = cipher; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 203 | return 0; |
| 204 | } |
| 205 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 206 | static void crypto_pcbc_exit_tfm(struct crypto_skcipher *tfm) |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 207 | { |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 208 | struct crypto_pcbc_ctx *ctx = crypto_skcipher_ctx(tfm); |
| 209 | |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 210 | crypto_free_cipher(ctx->child); |
| 211 | } |
| 212 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 213 | static void crypto_pcbc_free(struct skcipher_instance *inst) |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 214 | { |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 215 | crypto_drop_skcipher(skcipher_instance_ctx(inst)); |
| 216 | kfree(inst); |
| 217 | } |
| 218 | |
| 219 | static int crypto_pcbc_create(struct crypto_template *tmpl, struct rtattr **tb) |
| 220 | { |
| 221 | struct skcipher_instance *inst; |
| 222 | struct crypto_attr_type *algt; |
| 223 | struct crypto_spawn *spawn; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 224 | struct crypto_alg *alg; |
Herbert Xu | ebc610e | 2007-01-01 18:37:02 +1100 | [diff] [blame] | 225 | int err; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 226 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 227 | algt = crypto_get_attr_type(tb); |
| 228 | if (IS_ERR(algt)) |
| 229 | return PTR_ERR(algt); |
Herbert Xu | ebc610e | 2007-01-01 18:37:02 +1100 | [diff] [blame] | 230 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 231 | if (((algt->type ^ CRYPTO_ALG_TYPE_SKCIPHER) & algt->mask) & |
| 232 | ~CRYPTO_ALG_INTERNAL) |
| 233 | return -EINVAL; |
| 234 | |
| 235 | inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); |
| 236 | if (!inst) |
| 237 | return -ENOMEM; |
| 238 | |
| 239 | alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER | |
| 240 | (algt->type & CRYPTO_ALG_INTERNAL), |
| 241 | CRYPTO_ALG_TYPE_MASK | |
| 242 | (algt->mask & CRYPTO_ALG_INTERNAL)); |
| 243 | err = PTR_ERR(alg); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 244 | if (IS_ERR(alg)) |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 245 | goto err_free_inst; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 246 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 247 | spawn = skcipher_instance_ctx(inst); |
| 248 | err = crypto_init_spawn(spawn, alg, skcipher_crypto_instance(inst), |
| 249 | CRYPTO_ALG_TYPE_MASK); |
| 250 | crypto_mod_put(alg); |
| 251 | if (err) |
| 252 | goto err_free_inst; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 253 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 254 | err = crypto_inst_setname(skcipher_crypto_instance(inst), "pcbc", alg); |
| 255 | if (err) |
| 256 | goto err_drop_spawn; |
| 257 | |
| 258 | inst->alg.base.cra_flags = alg->cra_flags & CRYPTO_ALG_INTERNAL; |
| 259 | inst->alg.base.cra_priority = alg->cra_priority; |
| 260 | inst->alg.base.cra_blocksize = alg->cra_blocksize; |
| 261 | inst->alg.base.cra_alignmask = alg->cra_alignmask; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 262 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 263 | inst->alg.ivsize = alg->cra_blocksize; |
| 264 | inst->alg.min_keysize = alg->cra_cipher.cia_min_keysize; |
| 265 | inst->alg.max_keysize = alg->cra_cipher.cia_max_keysize; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 266 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 267 | inst->alg.base.cra_ctxsize = sizeof(struct crypto_pcbc_ctx); |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 268 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 269 | inst->alg.init = crypto_pcbc_init_tfm; |
| 270 | inst->alg.exit = crypto_pcbc_exit_tfm; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 271 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 272 | inst->alg.setkey = crypto_pcbc_setkey; |
| 273 | inst->alg.encrypt = crypto_pcbc_encrypt; |
| 274 | inst->alg.decrypt = crypto_pcbc_decrypt; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 275 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 276 | inst->free = crypto_pcbc_free; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 277 | |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 278 | err = skcipher_register_instance(tmpl, inst); |
| 279 | if (err) |
| 280 | goto err_drop_spawn; |
| 281 | |
| 282 | out: |
| 283 | return err; |
| 284 | |
| 285 | err_drop_spawn: |
| 286 | crypto_drop_spawn(spawn); |
| 287 | err_free_inst: |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 288 | kfree(inst); |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 289 | goto out; |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static struct crypto_template crypto_pcbc_tmpl = { |
| 293 | .name = "pcbc", |
Herbert Xu | 043a440 | 2016-11-22 20:08:27 +0800 | [diff] [blame] | 294 | .create = crypto_pcbc_create, |
David Howells | 91652be | 2006-12-16 12:09:02 +1100 | [diff] [blame] | 295 | .module = THIS_MODULE, |
| 296 | }; |
| 297 | |
| 298 | static int __init crypto_pcbc_module_init(void) |
| 299 | { |
| 300 | return crypto_register_template(&crypto_pcbc_tmpl); |
| 301 | } |
| 302 | |
| 303 | static void __exit crypto_pcbc_module_exit(void) |
| 304 | { |
| 305 | crypto_unregister_template(&crypto_pcbc_tmpl); |
| 306 | } |
| 307 | |
| 308 | module_init(crypto_pcbc_module_init); |
| 309 | module_exit(crypto_pcbc_module_exit); |
| 310 | |
| 311 | MODULE_LICENSE("GPL"); |
| 312 | MODULE_DESCRIPTION("PCBC block cipher algorithm"); |
Kees Cook | 4943ba1 | 2014-11-24 16:32:38 -0800 | [diff] [blame] | 313 | MODULE_ALIAS_CRYPTO("pcbc"); |