19 #include <linux/kernel.h>
20 #include <linux/module.h>
22 #include <linux/slab.h>
36 struct priv *
ctx = crypto_tfm_ctx(parent);
55 crypto_cipher_set_flags(child, crypto_tfm_get_flags(parent) &
57 err = crypto_cipher_setkey(child, key + keylen/2, keylen/2);
61 crypto_tfm_set_flags(parent, crypto_cipher_get_flags(child) &
68 crypto_cipher_set_flags(child, crypto_tfm_get_flags(parent) &
70 err = crypto_cipher_setkey(child, key, keylen/2);
74 crypto_tfm_set_flags(parent, crypto_cipher_get_flags(child) &
86 static inline void xts_round(
struct sinfo *
s,
void *
dst,
const void *
src)
88 be128_xor(dst, s->
t, src);
89 s->
fn(s->
tfm, dst, dst);
90 be128_xor(dst, dst, s->
t);
102 .tfm = crypto_cipher_tfm(ctx->
child),
128 xts_round(&s, wdst, wsrc);
132 }
while ((avail -= bs) >= bs);
150 struct priv *ctx = crypto_blkcipher_ctx(desc->
tfm);
153 blkcipher_walk_init(&w, dst, src, nbytes);
154 return crypt(desc, &w, ctx, crypto_cipher_alg(ctx->
tweak)->cia_encrypt,
155 crypto_cipher_alg(ctx->
child)->cia_encrypt);
161 struct priv *ctx = crypto_blkcipher_ctx(desc->
tfm);
164 blkcipher_walk_init(&w, dst, src, nbytes);
165 return crypt(desc, &w, ctx, crypto_cipher_alg(ctx->
tweak)->cia_encrypt,
166 crypto_cipher_alg(ctx->
child)->cia_decrypt);
174 const unsigned int max_blks = req->
tbuflen / bsize;
176 unsigned int nblocks;
183 blkcipher_walk_init(&walk, sdst, ssrc, nbytes);
190 nblocks =
min(nbytes / bsize, max_blks);
202 for (i = 0; i < nblocks; i++) {
208 be128_xor(dst + i, t, src + i);
216 for (i = 0; i < nblocks; i++)
217 be128_xor(dst + i, dst + i, &t_buf[i]);
221 nbytes -= nblocks * bsize;
222 nblocks =
min(nbytes / bsize, max_blks);
223 }
while (nblocks > 0);
232 nblocks =
min(nbytes / bsize, max_blks);
246 struct priv *ctx = crypto_tfm_ctx(tfm);
249 cipher = crypto_spawn_cipher(spawn);
251 return PTR_ERR(cipher);
255 crypto_free_cipher(cipher);
261 cipher = crypto_spawn_cipher(spawn);
262 if (IS_ERR(cipher)) {
263 crypto_free_cipher(ctx->
child);
264 return PTR_ERR(cipher);
269 crypto_free_cipher(cipher);
270 crypto_free_cipher(ctx->
child);
282 struct priv *ctx = crypto_tfm_ctx(tfm);
283 crypto_free_cipher(ctx->
child);
284 crypto_free_cipher(ctx->
tweak);
300 return ERR_CAST(alg);
311 inst->
alg.cra_alignmask = 7;
318 inst->
alg.cra_blkcipher.min_keysize =
319 2 * alg->cra_cipher.cia_min_keysize;
320 inst->
alg.cra_blkcipher.max_keysize =
321 2 * alg->cra_cipher.cia_max_keysize;
323 inst->
alg.cra_ctxsize =
sizeof(
struct priv);
325 inst->
alg.cra_init = init_tfm;
326 inst->
alg.cra_exit = exit_tfm;
330 inst->
alg.cra_blkcipher.decrypt = decrypt;
350 static int __init crypto_module_init(
void)
355 static void __exit crypto_module_exit(
void)