16 #include <linux/kernel.h>
18 #include <linux/module.h>
20 #include <linux/slab.h>
34 crypto_cipher_set_flags(child, crypto_tfm_get_flags(parent) &
36 err = crypto_cipher_setkey(child, key, keylen);
37 crypto_tfm_set_flags(parent, crypto_cipher_get_flags(child) &
47 crypto_cipher_alg(tfm)->cia_encrypt;
48 int bsize = crypto_cipher_blocksize(tfm);
56 fn(crypto_cipher_tfm(tfm), dst, iv);
61 }
while ((nbytes -= bsize) >= bsize);
71 crypto_cipher_alg(tfm)->cia_encrypt;
72 int bsize = crypto_cipher_blocksize(tfm);
73 unsigned int nbytes = walk->
nbytes;
79 fn(crypto_cipher_tfm(tfm), src, src);
83 }
while ((nbytes -= bsize) >= bsize);
100 blkcipher_walk_init(&walk, dst, src, nbytes);
103 while ((nbytes = walk.
nbytes)) {
105 nbytes = crypto_cbc_encrypt_inplace(desc, &walk, child);
107 nbytes = crypto_cbc_encrypt_segment(desc, &walk, child);
114 static int crypto_cbc_decrypt_segment(
struct blkcipher_desc *desc,
119 crypto_cipher_alg(tfm)->cia_decrypt;
120 int bsize = crypto_cipher_blocksize(tfm);
121 unsigned int nbytes = walk->
nbytes;
127 fn(crypto_cipher_tfm(tfm), dst, src);
133 }
while ((nbytes -= bsize) >= bsize);
140 static int crypto_cbc_decrypt_inplace(
struct blkcipher_desc *desc,
145 crypto_cipher_alg(tfm)->cia_decrypt;
146 int bsize = crypto_cipher_blocksize(tfm);
147 unsigned int nbytes = walk->
nbytes;
152 src += nbytes - (nbytes & (bsize - 1)) - bsize;
153 memcpy(last_iv, src, bsize);
156 fn(crypto_cipher_tfm(tfm), src, src);
157 if ((nbytes -= bsize) < bsize)
179 blkcipher_walk_init(&walk, dst, src, nbytes);
182 while ((nbytes = walk.
nbytes)) {
184 nbytes = crypto_cbc_decrypt_inplace(desc, &walk, child);
186 nbytes = crypto_cbc_decrypt_segment(desc, &walk, child);
193 static int crypto_cbc_init_tfm(
struct crypto_tfm *tfm)
200 cipher = crypto_spawn_cipher(spawn);
202 return PTR_ERR(cipher);
208 static void crypto_cbc_exit_tfm(
struct crypto_tfm *tfm)
211 crypto_free_cipher(ctx->
child);
227 return ERR_CAST(alg);
244 inst->
alg.cra_alignmask |= __alignof__(
u32) - 1;
247 inst->
alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
248 inst->
alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
252 inst->
alg.cra_init = crypto_cbc_init_tfm;
253 inst->
alg.cra_exit = crypto_cbc_exit_tfm;
255 inst->
alg.cra_blkcipher.setkey = crypto_cbc_setkey;
256 inst->
alg.cra_blkcipher.encrypt = crypto_cbc_encrypt;
257 inst->
alg.cra_blkcipher.decrypt = crypto_cbc_decrypt;
272 .alloc = crypto_cbc_alloc,
273 .free = crypto_cbc_free,
277 static int __init crypto_cbc_module_init(
void)
282 static void __exit crypto_cbc_module_exit(
void)