21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
25 #include <linux/string.h>
43 geniv = skcipher_givcrypt_reqtfm(req);
44 memcpy(req->
creq.info, subreq->
info, crypto_ablkcipher_ivsize(geniv));
54 seqiv_complete2(req, err);
55 skcipher_givcrypt_complete(req, err);
69 geniv = aead_givcrypt_reqtfm(req);
70 memcpy(req->
areq.iv, subreq->
iv, crypto_aead_ivsize(geniv));
80 seqiv_aead_complete2(req, err);
81 aead_givcrypt_complete(req, err);
87 unsigned int len = ivsize;
89 if (ivsize >
sizeof(
u64)) {
94 memcpy(info + ivsize - len, &seq, len);
101 struct seqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
109 ablkcipher_request_set_tfm(subreq, skcipher_geniv_cipher(geniv));
111 complete = req->
creq.base.complete;
112 data = req->
creq.base.data;
113 info = req->
creq.info;
115 ivsize = crypto_ablkcipher_ivsize(geniv);
118 crypto_ablkcipher_alignmask(geniv) + 1))) {
125 complete = seqiv_complete;
129 ablkcipher_request_set_callback(subreq, req->
creq.base.flags, complete,
131 ablkcipher_request_set_crypt(subreq, req->
creq.src, req->
creq.dst,
132 req->
creq.nbytes, info);
134 seqiv_geniv(ctx, info, req->
seq, ivsize);
137 err = crypto_ablkcipher_encrypt(subreq);
139 seqiv_complete2(req, err);
145 struct crypto_aead *geniv = aead_givcrypt_reqtfm(req);
146 struct seqiv_ctx *ctx = crypto_aead_ctx(geniv);
148 struct aead_request *subreq = aead_givcrypt_reqctx(req);
155 aead_request_set_tfm(subreq, aead_geniv_base(geniv));
157 complete = areq->
base.complete;
158 data = areq->
base.data;
161 ivsize = crypto_aead_ivsize(geniv);
164 crypto_aead_alignmask(geniv) + 1))) {
171 complete = seqiv_aead_complete;
175 aead_request_set_callback(subreq, areq->
base.flags, complete, data);
176 aead_request_set_crypt(subreq, areq->
src, areq->
dst, areq->
cryptlen,
180 seqiv_geniv(ctx, info, req->
seq, ivsize);
183 err = crypto_aead_encrypt(subreq);
185 seqiv_aead_complete2(req, err);
192 struct seqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
195 spin_lock_bh(&ctx->
lock);
196 if (crypto_ablkcipher_crt(geniv)->givencrypt != seqiv_givencrypt_first)
199 crypto_ablkcipher_crt(geniv)->givencrypt = seqiv_givencrypt;
201 crypto_ablkcipher_ivsize(geniv));
204 spin_unlock_bh(&ctx->
lock);
209 return seqiv_givencrypt(req);
214 struct crypto_aead *geniv = aead_givcrypt_reqtfm(req);
215 struct seqiv_ctx *ctx = crypto_aead_ctx(geniv);
218 spin_lock_bh(&ctx->
lock);
219 if (crypto_aead_crt(geniv)->givencrypt != seqiv_aead_givencrypt_first)
222 crypto_aead_crt(geniv)->givencrypt = seqiv_aead_givencrypt;
224 crypto_aead_ivsize(geniv));
227 spin_unlock_bh(&ctx->
lock);
232 return seqiv_aead_givencrypt(req);
238 struct seqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
247 static int seqiv_aead_init(
struct crypto_tfm *tfm)
249 struct crypto_aead *geniv = __crypto_aead_cast(tfm);
250 struct seqiv_ctx *ctx = crypto_aead_ctx(geniv);
270 inst->
alg.cra_ablkcipher.givencrypt = seqiv_givencrypt_first;
272 inst->
alg.cra_init = seqiv_init;
275 inst->
alg.cra_ctxsize += inst->
alg.cra_ablkcipher.ivsize;
290 inst->
alg.cra_aead.givencrypt = seqiv_aead_givencrypt_first;
292 inst->
alg.cra_init = seqiv_aead_init;
295 inst->
alg.cra_ctxsize = inst->
alg.cra_aead.ivsize;
317 inst = seqiv_ablkcipher_alloc(tb);
319 inst = seqiv_aead_alloc(tb);
324 inst->
alg.cra_alignmask |= __alignof__(
u32) - 1;
346 .alloc = seqiv_alloc,
351 static int __init seqiv_module_init(
void)
356 static void __exit seqiv_module_exit(
void)