17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/random.h>
21 #include <linux/slab.h>
40 crypto_cipher_set_flags(child, crypto_tfm_get_flags(parent) &
42 err = crypto_cipher_setkey(child, key, keylen);
43 crypto_tfm_set_flags(parent, crypto_cipher_get_flags(child) &
52 unsigned int bsize = crypto_cipher_blocksize(tfm);
53 unsigned long alignmask = crypto_cipher_alignmask(tfm);
54 u8 *ctrblk = walk->
iv;
55 u8 tmp[bsize + alignmask];
61 crypto_cipher_encrypt_one(tfm, keystream, ctrblk);
63 memcpy(dst, keystream, nbytes);
72 crypto_cipher_alg(tfm)->cia_encrypt;
73 unsigned int bsize = crypto_cipher_blocksize(tfm);
74 u8 *ctrblk = walk->
iv;
81 fn(crypto_cipher_tfm(tfm), dst, ctrblk);
89 }
while ((nbytes -= bsize) >= bsize);
98 crypto_cipher_alg(tfm)->cia_encrypt;
99 unsigned int bsize = crypto_cipher_blocksize(tfm);
100 unsigned long alignmask = crypto_cipher_alignmask(tfm);
101 unsigned int nbytes = walk->
nbytes;
102 u8 *ctrblk = walk->
iv;
104 u8
tmp[bsize + alignmask];
105 u8 *keystream =
PTR_ALIGN(tmp + 0, alignmask + 1);
109 fn(crypto_cipher_tfm(tfm), keystream, ctrblk);
116 }
while ((nbytes -= bsize) >= bsize);
129 unsigned int bsize = crypto_cipher_blocksize(child);
132 blkcipher_walk_init(&walk, dst, src, nbytes);
135 while (walk.
nbytes >= bsize) {
137 nbytes = crypto_ctr_crypt_inplace(&walk, child);
139 nbytes = crypto_ctr_crypt_segment(&walk, child);
145 crypto_ctr_crypt_final(&walk, child);
152 static int crypto_ctr_init_tfm(
struct crypto_tfm *tfm)
159 cipher = crypto_spawn_cipher(spawn);
161 return PTR_ERR(cipher);
168 static void crypto_ctr_exit_tfm(
struct crypto_tfm *tfm)
172 crypto_free_cipher(ctx->
child);
188 return ERR_CAST(alg);
205 inst->
alg.cra_blocksize = 1;
210 inst->
alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
211 inst->
alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
215 inst->
alg.cra_init = crypto_ctr_init_tfm;
216 inst->
alg.cra_exit = crypto_ctr_exit_tfm;
218 inst->
alg.cra_blkcipher.setkey = crypto_ctr_setkey;
219 inst->
alg.cra_blkcipher.encrypt = crypto_ctr_crypt;
220 inst->
alg.cra_blkcipher.decrypt = crypto_ctr_crypt;
222 inst->
alg.cra_blkcipher.geniv =
"chainiv";
241 .alloc = crypto_ctr_alloc,
242 .free = crypto_ctr_free,
246 static int crypto_rfc3686_setkey(
struct crypto_tfm *parent,
const u8 *
key,
263 crypto_blkcipher_set_flags(child, crypto_tfm_get_flags(parent) &
265 err = crypto_blkcipher_setkey(child, key, keylen);
266 crypto_tfm_set_flags(parent, crypto_blkcipher_get_flags(child) &
279 unsigned long alignmask = crypto_blkcipher_alignmask(tfm);
295 err = crypto_blkcipher_encrypt_iv(desc, dst, src, nbytes);
302 static int crypto_rfc3686_init_tfm(
struct crypto_tfm *tfm)
309 cipher = crypto_spawn_blkcipher(spawn);
311 return PTR_ERR(cipher);
318 static void crypto_rfc3686_exit_tfm(
struct crypto_tfm *tfm)
322 crypto_free_blkcipher(ctx->
child);
356 inst->
alg.cra_blocksize = 1;
361 inst->
alg.cra_blkcipher.min_keysize = alg->cra_blkcipher.min_keysize
363 inst->
alg.cra_blkcipher.max_keysize = alg->cra_blkcipher.max_keysize
366 inst->
alg.cra_blkcipher.geniv =
"seqiv";
370 inst->
alg.cra_init = crypto_rfc3686_init_tfm;
371 inst->
alg.cra_exit = crypto_rfc3686_exit_tfm;
373 inst->
alg.cra_blkcipher.setkey = crypto_rfc3686_setkey;
374 inst->
alg.cra_blkcipher.encrypt = crypto_rfc3686_crypt;
375 inst->
alg.cra_blkcipher.decrypt = crypto_rfc3686_crypt;
388 .alloc = crypto_rfc3686_alloc,
389 .free = crypto_ctr_free,
393 static int __init crypto_ctr_module_init(
void)
413 static void __exit crypto_ctr_module_exit(
void)