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