20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include <linux/slab.h>
37 crypto_cipher_set_flags(child, crypto_tfm_get_flags(parent) &
39 err = crypto_cipher_setkey(child, key, keylen);
40 crypto_tfm_set_flags(parent, crypto_cipher_get_flags(child) &
50 crypto_cipher_alg(tfm)->cia_encrypt;
51 int bsize = crypto_cipher_blocksize(tfm);
59 fn(crypto_cipher_tfm(tfm), dst, iv);
65 }
while ((nbytes -= bsize) >= bsize);
70 static int crypto_pcbc_encrypt_inplace(
struct blkcipher_desc *desc,
75 crypto_cipher_alg(tfm)->cia_encrypt;
76 int bsize = crypto_cipher_blocksize(tfm);
77 unsigned int nbytes = walk->
nbytes;
83 memcpy(tmpbuf, src, bsize);
85 fn(crypto_cipher_tfm(tfm), src, iv);
90 }
while ((nbytes -= bsize) >= bsize);
107 blkcipher_walk_init(&walk, dst, src, nbytes);
110 while ((nbytes = walk.
nbytes)) {
112 nbytes = crypto_pcbc_encrypt_inplace(desc, &walk,
115 nbytes = crypto_pcbc_encrypt_segment(desc, &walk,
123 static int crypto_pcbc_decrypt_segment(
struct blkcipher_desc *desc,
128 crypto_cipher_alg(tfm)->cia_decrypt;
129 int bsize = crypto_cipher_blocksize(tfm);
130 unsigned int nbytes = walk->
nbytes;
136 fn(crypto_cipher_tfm(tfm), dst, src);
143 }
while ((nbytes -= bsize) >= bsize);
150 static int crypto_pcbc_decrypt_inplace(
struct blkcipher_desc *desc,
155 crypto_cipher_alg(tfm)->cia_decrypt;
156 int bsize = crypto_cipher_blocksize(tfm);
157 unsigned int nbytes = walk->
nbytes;
163 memcpy(tmpbuf, src, bsize);
164 fn(crypto_cipher_tfm(tfm), src, src);
166 memcpy(iv, tmpbuf, bsize);
170 }
while ((nbytes -= bsize) >= bsize);
187 blkcipher_walk_init(&walk, dst, src, nbytes);
190 while ((nbytes = walk.
nbytes)) {
192 nbytes = crypto_pcbc_decrypt_inplace(desc, &walk,
195 nbytes = crypto_pcbc_decrypt_segment(desc, &walk,
203 static int crypto_pcbc_init_tfm(
struct crypto_tfm *tfm)
210 cipher = crypto_spawn_cipher(spawn);
212 return PTR_ERR(cipher);
218 static void crypto_pcbc_exit_tfm(
struct crypto_tfm *tfm)
221 crypto_free_cipher(ctx->
child);
237 return ERR_CAST(alg);
250 inst->
alg.cra_alignmask |= __alignof__(
u32) - 1;
253 inst->
alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
254 inst->
alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
258 inst->
alg.cra_init = crypto_pcbc_init_tfm;
259 inst->
alg.cra_exit = crypto_pcbc_exit_tfm;
261 inst->
alg.cra_blkcipher.setkey = crypto_pcbc_setkey;
262 inst->
alg.cra_blkcipher.encrypt = crypto_pcbc_encrypt;
263 inst->
alg.cra_blkcipher.decrypt = crypto_pcbc_decrypt;
278 .alloc = crypto_pcbc_alloc,
279 .free = crypto_pcbc_free,
283 static int __init crypto_pcbc_module_init(
void)
288 static void __exit crypto_pcbc_module_exit(
void)