2 * Authenc: Simple AEAD wrapper for IPsec
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
13 #include <crypto/aead.h>
14 #include <crypto/internal/hash.h>
15 #include <crypto/internal/skcipher.h>
16 #include <crypto/authenc.h>
17 #include <crypto/scatterwalk.h>
18 #include <linux/err.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/slab.h>
24 #include <linux/spinlock.h>
26 typedef u8
*(*authenc_ahash_t
)(struct aead_request
*req
, unsigned int flags
);
28 struct authenc_instance_ctx
{
29 struct crypto_ahash_spawn auth
;
30 struct crypto_skcipher_spawn enc
;
33 struct crypto_authenc_ctx
{
35 struct crypto_ahash
*auth
;
36 struct crypto_ablkcipher
*enc
;
39 struct authenc_request_ctx
{
40 unsigned int cryptlen
;
41 struct scatterlist
*sg
;
42 struct scatterlist asg
[2];
43 struct scatterlist cipher
[2];
44 crypto_completion_t complete
;
45 crypto_completion_t update_complete
;
49 static void authenc_request_complete(struct aead_request
*req
, int err
)
51 if (err
!= -EINPROGRESS
)
52 aead_request_complete(req
, err
);
55 int crypto_authenc_extractkeys(struct crypto_authenc_keys
*keys
, const u8
*key
,
58 struct rtattr
*rta
= (struct rtattr
*)key
;
59 struct crypto_authenc_key_param
*param
;
61 if (!RTA_OK(rta
, keylen
))
63 if (rta
->rta_type
!= CRYPTO_AUTHENC_KEYA_PARAM
)
67 * RTA_OK() didn't align the rtattr's payload when validating that it
68 * fits in the buffer. Yet, the keys should start on the next 4-byte
69 * aligned boundary. To avoid confusion, require that the rtattr
70 * payload be exactly the param struct, which has a 4-byte aligned size.
72 if (RTA_PAYLOAD(rta
) != sizeof(*param
))
74 BUILD_BUG_ON(sizeof(*param
) % RTA_ALIGNTO
);
76 param
= RTA_DATA(rta
);
77 keys
->enckeylen
= be32_to_cpu(param
->enckeylen
);
80 keylen
-= rta
->rta_len
;
82 if (keylen
< keys
->enckeylen
)
85 keys
->authkeylen
= keylen
- keys
->enckeylen
;
87 keys
->enckey
= key
+ keys
->authkeylen
;
91 EXPORT_SYMBOL_GPL(crypto_authenc_extractkeys
);
93 static int crypto_authenc_setkey(struct crypto_aead
*authenc
, const u8
*key
,
96 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
97 struct crypto_ahash
*auth
= ctx
->auth
;
98 struct crypto_ablkcipher
*enc
= ctx
->enc
;
99 struct crypto_authenc_keys keys
;
102 if (crypto_authenc_extractkeys(&keys
, key
, keylen
) != 0)
105 crypto_ahash_clear_flags(auth
, CRYPTO_TFM_REQ_MASK
);
106 crypto_ahash_set_flags(auth
, crypto_aead_get_flags(authenc
) &
107 CRYPTO_TFM_REQ_MASK
);
108 err
= crypto_ahash_setkey(auth
, keys
.authkey
, keys
.authkeylen
);
109 crypto_aead_set_flags(authenc
, crypto_ahash_get_flags(auth
) &
110 CRYPTO_TFM_RES_MASK
);
115 crypto_ablkcipher_clear_flags(enc
, CRYPTO_TFM_REQ_MASK
);
116 crypto_ablkcipher_set_flags(enc
, crypto_aead_get_flags(authenc
) &
117 CRYPTO_TFM_REQ_MASK
);
118 err
= crypto_ablkcipher_setkey(enc
, keys
.enckey
, keys
.enckeylen
);
119 crypto_aead_set_flags(authenc
, crypto_ablkcipher_get_flags(enc
) &
120 CRYPTO_TFM_RES_MASK
);
126 crypto_aead_set_flags(authenc
, CRYPTO_TFM_RES_BAD_KEY_LEN
);
130 static void authenc_geniv_ahash_update_done(struct crypto_async_request
*areq
,
133 struct aead_request
*req
= areq
->data
;
134 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
135 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
136 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
137 struct ahash_request
*ahreq
= (void *)(areq_ctx
->tail
+ ctx
->reqoff
);
142 ahash_request_set_crypt(ahreq
, areq_ctx
->sg
, ahreq
->result
,
144 ahash_request_set_callback(ahreq
, aead_request_flags(req
) &
145 CRYPTO_TFM_REQ_MAY_SLEEP
,
146 areq_ctx
->complete
, req
);
148 err
= crypto_ahash_finup(ahreq
);
152 scatterwalk_map_and_copy(ahreq
->result
, areq_ctx
->sg
,
154 crypto_aead_authsize(authenc
), 1);
157 authenc_request_complete(req
, err
);
160 static void authenc_geniv_ahash_done(struct crypto_async_request
*areq
, int err
)
162 struct aead_request
*req
= areq
->data
;
163 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
164 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
165 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
166 struct ahash_request
*ahreq
= (void *)(areq_ctx
->tail
+ ctx
->reqoff
);
171 scatterwalk_map_and_copy(ahreq
->result
, areq_ctx
->sg
,
173 crypto_aead_authsize(authenc
), 1);
176 aead_request_complete(req
, err
);
179 static void authenc_verify_ahash_update_done(struct crypto_async_request
*areq
,
183 unsigned int authsize
;
184 struct ablkcipher_request
*abreq
;
185 struct aead_request
*req
= areq
->data
;
186 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
187 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
188 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
189 struct ahash_request
*ahreq
= (void *)(areq_ctx
->tail
+ ctx
->reqoff
);
190 unsigned int cryptlen
= req
->cryptlen
;
195 ahash_request_set_crypt(ahreq
, areq_ctx
->sg
, ahreq
->result
,
197 ahash_request_set_callback(ahreq
, aead_request_flags(req
) &
198 CRYPTO_TFM_REQ_MAY_SLEEP
,
199 areq_ctx
->complete
, req
);
201 err
= crypto_ahash_finup(ahreq
);
205 authsize
= crypto_aead_authsize(authenc
);
206 cryptlen
-= authsize
;
207 ihash
= ahreq
->result
+ authsize
;
208 scatterwalk_map_and_copy(ihash
, areq_ctx
->sg
, areq_ctx
->cryptlen
,
211 err
= crypto_memneq(ihash
, ahreq
->result
, authsize
) ? -EBADMSG
: 0;
215 abreq
= aead_request_ctx(req
);
216 ablkcipher_request_set_tfm(abreq
, ctx
->enc
);
217 ablkcipher_request_set_callback(abreq
, aead_request_flags(req
),
218 req
->base
.complete
, req
->base
.data
);
219 ablkcipher_request_set_crypt(abreq
, req
->src
, req
->dst
,
222 err
= crypto_ablkcipher_decrypt(abreq
);
225 authenc_request_complete(req
, err
);
228 static void authenc_verify_ahash_done(struct crypto_async_request
*areq
,
232 unsigned int authsize
;
233 struct ablkcipher_request
*abreq
;
234 struct aead_request
*req
= areq
->data
;
235 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
236 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
237 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
238 struct ahash_request
*ahreq
= (void *)(areq_ctx
->tail
+ ctx
->reqoff
);
239 unsigned int cryptlen
= req
->cryptlen
;
244 authsize
= crypto_aead_authsize(authenc
);
245 cryptlen
-= authsize
;
246 ihash
= ahreq
->result
+ authsize
;
247 scatterwalk_map_and_copy(ihash
, areq_ctx
->sg
, areq_ctx
->cryptlen
,
250 err
= crypto_memneq(ihash
, ahreq
->result
, authsize
) ? -EBADMSG
: 0;
254 abreq
= aead_request_ctx(req
);
255 ablkcipher_request_set_tfm(abreq
, ctx
->enc
);
256 ablkcipher_request_set_callback(abreq
, aead_request_flags(req
),
257 req
->base
.complete
, req
->base
.data
);
258 ablkcipher_request_set_crypt(abreq
, req
->src
, req
->dst
,
261 err
= crypto_ablkcipher_decrypt(abreq
);
264 authenc_request_complete(req
, err
);
267 static u8
*crypto_authenc_ahash_fb(struct aead_request
*req
, unsigned int flags
)
269 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
270 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
271 struct crypto_ahash
*auth
= ctx
->auth
;
272 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
273 struct ahash_request
*ahreq
= (void *)(areq_ctx
->tail
+ ctx
->reqoff
);
274 u8
*hash
= areq_ctx
->tail
;
277 hash
= (u8
*)ALIGN((unsigned long)hash
+ crypto_ahash_alignmask(auth
),
278 crypto_ahash_alignmask(auth
) + 1);
280 ahash_request_set_tfm(ahreq
, auth
);
282 err
= crypto_ahash_init(ahreq
);
286 ahash_request_set_crypt(ahreq
, req
->assoc
, hash
, req
->assoclen
);
287 ahash_request_set_callback(ahreq
, aead_request_flags(req
) & flags
,
288 areq_ctx
->update_complete
, req
);
290 err
= crypto_ahash_update(ahreq
);
294 ahash_request_set_crypt(ahreq
, areq_ctx
->sg
, hash
,
296 ahash_request_set_callback(ahreq
, aead_request_flags(req
) & flags
,
297 areq_ctx
->complete
, req
);
299 err
= crypto_ahash_finup(ahreq
);
306 static u8
*crypto_authenc_ahash(struct aead_request
*req
, unsigned int flags
)
308 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
309 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
310 struct crypto_ahash
*auth
= ctx
->auth
;
311 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
312 struct ahash_request
*ahreq
= (void *)(areq_ctx
->tail
+ ctx
->reqoff
);
313 u8
*hash
= areq_ctx
->tail
;
316 hash
= (u8
*)ALIGN((unsigned long)hash
+ crypto_ahash_alignmask(auth
),
317 crypto_ahash_alignmask(auth
) + 1);
319 ahash_request_set_tfm(ahreq
, auth
);
320 ahash_request_set_crypt(ahreq
, areq_ctx
->sg
, hash
,
322 ahash_request_set_callback(ahreq
, aead_request_flags(req
) & flags
,
323 areq_ctx
->complete
, req
);
325 err
= crypto_ahash_digest(ahreq
);
332 static int crypto_authenc_genicv(struct aead_request
*req
, u8
*iv
,
335 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
336 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
337 struct scatterlist
*dst
= req
->dst
;
338 struct scatterlist
*assoc
= req
->assoc
;
339 struct scatterlist
*cipher
= areq_ctx
->cipher
;
340 struct scatterlist
*asg
= areq_ctx
->asg
;
341 unsigned int ivsize
= crypto_aead_ivsize(authenc
);
342 unsigned int cryptlen
= req
->cryptlen
;
343 authenc_ahash_t authenc_ahash_fn
= crypto_authenc_ahash_fb
;
349 vdst
= PageHighMem(dstp
) ? NULL
: page_address(dstp
) + dst
->offset
;
352 sg_init_table(cipher
, 2);
353 sg_set_buf(cipher
, iv
, ivsize
);
354 scatterwalk_crypto_chain(cipher
, dst
, vdst
== iv
+ ivsize
, 2);
359 if (req
->assoclen
&& sg_is_last(assoc
)) {
360 authenc_ahash_fn
= crypto_authenc_ahash
;
361 sg_init_table(asg
, 2);
362 sg_set_page(asg
, sg_page(assoc
), assoc
->length
, assoc
->offset
);
363 scatterwalk_crypto_chain(asg
, dst
, 0, 2);
365 cryptlen
+= req
->assoclen
;
368 areq_ctx
->cryptlen
= cryptlen
;
371 areq_ctx
->complete
= authenc_geniv_ahash_done
;
372 areq_ctx
->update_complete
= authenc_geniv_ahash_update_done
;
374 hash
= authenc_ahash_fn(req
, flags
);
376 return PTR_ERR(hash
);
378 scatterwalk_map_and_copy(hash
, dst
, cryptlen
,
379 crypto_aead_authsize(authenc
), 1);
383 static void crypto_authenc_encrypt_done(struct crypto_async_request
*req
,
386 struct aead_request
*areq
= req
->data
;
389 struct crypto_aead
*authenc
= crypto_aead_reqtfm(areq
);
390 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
391 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(areq
);
392 struct ablkcipher_request
*abreq
= (void *)(areq_ctx
->tail
394 u8
*iv
= (u8
*)abreq
- crypto_ablkcipher_ivsize(ctx
->enc
);
396 err
= crypto_authenc_genicv(areq
, iv
, 0);
399 authenc_request_complete(areq
, err
);
402 static int crypto_authenc_encrypt(struct aead_request
*req
)
404 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
405 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
406 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
407 struct crypto_ablkcipher
*enc
= ctx
->enc
;
408 struct scatterlist
*dst
= req
->dst
;
409 unsigned int cryptlen
= req
->cryptlen
;
410 struct ablkcipher_request
*abreq
= (void *)(areq_ctx
->tail
412 u8
*iv
= (u8
*)abreq
- crypto_ablkcipher_ivsize(enc
);
415 ablkcipher_request_set_tfm(abreq
, enc
);
416 ablkcipher_request_set_callback(abreq
, aead_request_flags(req
),
417 crypto_authenc_encrypt_done
, req
);
418 ablkcipher_request_set_crypt(abreq
, req
->src
, dst
, cryptlen
, req
->iv
);
420 memcpy(iv
, req
->iv
, crypto_aead_ivsize(authenc
));
422 err
= crypto_ablkcipher_encrypt(abreq
);
426 return crypto_authenc_genicv(req
, iv
, CRYPTO_TFM_REQ_MAY_SLEEP
);
429 static void crypto_authenc_givencrypt_done(struct crypto_async_request
*req
,
432 struct aead_request
*areq
= req
->data
;
435 struct skcipher_givcrypt_request
*greq
= aead_request_ctx(areq
);
437 err
= crypto_authenc_genicv(areq
, greq
->giv
, 0);
440 authenc_request_complete(areq
, err
);
443 static int crypto_authenc_givencrypt(struct aead_givcrypt_request
*req
)
445 struct crypto_aead
*authenc
= aead_givcrypt_reqtfm(req
);
446 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
447 struct aead_request
*areq
= &req
->areq
;
448 struct skcipher_givcrypt_request
*greq
= aead_request_ctx(areq
);
452 skcipher_givcrypt_set_tfm(greq
, ctx
->enc
);
453 skcipher_givcrypt_set_callback(greq
, aead_request_flags(areq
),
454 crypto_authenc_givencrypt_done
, areq
);
455 skcipher_givcrypt_set_crypt(greq
, areq
->src
, areq
->dst
, areq
->cryptlen
,
457 skcipher_givcrypt_set_giv(greq
, iv
, req
->seq
);
459 err
= crypto_skcipher_givencrypt(greq
);
463 return crypto_authenc_genicv(areq
, iv
, CRYPTO_TFM_REQ_MAY_SLEEP
);
466 static int crypto_authenc_verify(struct aead_request
*req
,
467 authenc_ahash_t authenc_ahash_fn
)
469 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
470 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
473 unsigned int authsize
;
475 areq_ctx
->complete
= authenc_verify_ahash_done
;
476 areq_ctx
->update_complete
= authenc_verify_ahash_update_done
;
478 ohash
= authenc_ahash_fn(req
, CRYPTO_TFM_REQ_MAY_SLEEP
);
480 return PTR_ERR(ohash
);
482 authsize
= crypto_aead_authsize(authenc
);
483 ihash
= ohash
+ authsize
;
484 scatterwalk_map_and_copy(ihash
, areq_ctx
->sg
, areq_ctx
->cryptlen
,
486 return crypto_memneq(ihash
, ohash
, authsize
) ? -EBADMSG
: 0;
489 static int crypto_authenc_iverify(struct aead_request
*req
, u8
*iv
,
490 unsigned int cryptlen
)
492 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
493 struct authenc_request_ctx
*areq_ctx
= aead_request_ctx(req
);
494 struct scatterlist
*src
= req
->src
;
495 struct scatterlist
*assoc
= req
->assoc
;
496 struct scatterlist
*cipher
= areq_ctx
->cipher
;
497 struct scatterlist
*asg
= areq_ctx
->asg
;
498 unsigned int ivsize
= crypto_aead_ivsize(authenc
);
499 authenc_ahash_t authenc_ahash_fn
= crypto_authenc_ahash_fb
;
504 vsrc
= PageHighMem(srcp
) ? NULL
: page_address(srcp
) + src
->offset
;
507 sg_init_table(cipher
, 2);
508 sg_set_buf(cipher
, iv
, ivsize
);
509 scatterwalk_crypto_chain(cipher
, src
, vsrc
== iv
+ ivsize
, 2);
514 if (req
->assoclen
&& sg_is_last(assoc
)) {
515 authenc_ahash_fn
= crypto_authenc_ahash
;
516 sg_init_table(asg
, 2);
517 sg_set_page(asg
, sg_page(assoc
), assoc
->length
, assoc
->offset
);
518 scatterwalk_crypto_chain(asg
, src
, 0, 2);
520 cryptlen
+= req
->assoclen
;
523 areq_ctx
->cryptlen
= cryptlen
;
526 return crypto_authenc_verify(req
, authenc_ahash_fn
);
529 static int crypto_authenc_decrypt(struct aead_request
*req
)
531 struct crypto_aead
*authenc
= crypto_aead_reqtfm(req
);
532 struct crypto_authenc_ctx
*ctx
= crypto_aead_ctx(authenc
);
533 struct ablkcipher_request
*abreq
= aead_request_ctx(req
);
534 unsigned int cryptlen
= req
->cryptlen
;
535 unsigned int authsize
= crypto_aead_authsize(authenc
);
539 if (cryptlen
< authsize
)
541 cryptlen
-= authsize
;
543 err
= crypto_authenc_iverify(req
, iv
, cryptlen
);
547 ablkcipher_request_set_tfm(abreq
, ctx
->enc
);
548 ablkcipher_request_set_callback(abreq
, aead_request_flags(req
),
549 req
->base
.complete
, req
->base
.data
);
550 ablkcipher_request_set_crypt(abreq
, req
->src
, req
->dst
, cryptlen
, iv
);
552 return crypto_ablkcipher_decrypt(abreq
);
555 static int crypto_authenc_init_tfm(struct crypto_tfm
*tfm
)
557 struct crypto_instance
*inst
= crypto_tfm_alg_instance(tfm
);
558 struct authenc_instance_ctx
*ictx
= crypto_instance_ctx(inst
);
559 struct crypto_authenc_ctx
*ctx
= crypto_tfm_ctx(tfm
);
560 struct crypto_ahash
*auth
;
561 struct crypto_ablkcipher
*enc
;
564 auth
= crypto_spawn_ahash(&ictx
->auth
);
566 return PTR_ERR(auth
);
568 enc
= crypto_spawn_skcipher(&ictx
->enc
);
576 ctx
->reqoff
= ALIGN(2 * crypto_ahash_digestsize(auth
) +
577 crypto_ahash_alignmask(auth
),
578 crypto_ahash_alignmask(auth
) + 1) +
579 crypto_ablkcipher_ivsize(enc
);
581 tfm
->crt_aead
.reqsize
= sizeof(struct authenc_request_ctx
) +
584 crypto_ahash_reqsize(auth
) +
585 sizeof(struct ahash_request
),
586 sizeof(struct skcipher_givcrypt_request
) +
587 crypto_ablkcipher_reqsize(enc
));
592 crypto_free_ahash(auth
);
596 static void crypto_authenc_exit_tfm(struct crypto_tfm
*tfm
)
598 struct crypto_authenc_ctx
*ctx
= crypto_tfm_ctx(tfm
);
600 crypto_free_ahash(ctx
->auth
);
601 crypto_free_ablkcipher(ctx
->enc
);
604 static struct crypto_instance
*crypto_authenc_alloc(struct rtattr
**tb
)
606 struct crypto_attr_type
*algt
;
607 struct crypto_instance
*inst
;
608 struct hash_alg_common
*auth
;
609 struct crypto_alg
*auth_base
;
610 struct crypto_alg
*enc
;
611 struct authenc_instance_ctx
*ctx
;
612 const char *enc_name
;
615 algt
= crypto_get_attr_type(tb
);
617 return ERR_CAST(algt
);
619 if ((algt
->type
^ CRYPTO_ALG_TYPE_AEAD
) & algt
->mask
)
620 return ERR_PTR(-EINVAL
);
622 auth
= ahash_attr_alg(tb
[1], CRYPTO_ALG_TYPE_HASH
,
623 CRYPTO_ALG_TYPE_AHASH_MASK
);
625 return ERR_CAST(auth
);
627 auth_base
= &auth
->base
;
629 enc_name
= crypto_attr_alg_name(tb
[2]);
630 err
= PTR_ERR(enc_name
);
631 if (IS_ERR(enc_name
))
634 inst
= kzalloc(sizeof(*inst
) + sizeof(*ctx
), GFP_KERNEL
);
639 ctx
= crypto_instance_ctx(inst
);
641 err
= crypto_init_ahash_spawn(&ctx
->auth
, auth
, inst
);
645 crypto_set_skcipher_spawn(&ctx
->enc
, inst
);
646 err
= crypto_grab_skcipher(&ctx
->enc
, enc_name
, 0,
647 crypto_requires_sync(algt
->type
,
652 enc
= crypto_skcipher_spawn_alg(&ctx
->enc
);
655 if (snprintf(inst
->alg
.cra_name
, CRYPTO_MAX_ALG_NAME
,
656 "authenc(%s,%s)", auth_base
->cra_name
, enc
->cra_name
) >=
660 if (snprintf(inst
->alg
.cra_driver_name
, CRYPTO_MAX_ALG_NAME
,
661 "authenc(%s,%s)", auth_base
->cra_driver_name
,
662 enc
->cra_driver_name
) >= CRYPTO_MAX_ALG_NAME
)
665 inst
->alg
.cra_flags
= CRYPTO_ALG_TYPE_AEAD
;
666 inst
->alg
.cra_flags
|= enc
->cra_flags
& CRYPTO_ALG_ASYNC
;
667 inst
->alg
.cra_priority
= enc
->cra_priority
*
668 10 + auth_base
->cra_priority
;
669 inst
->alg
.cra_blocksize
= enc
->cra_blocksize
;
670 inst
->alg
.cra_alignmask
= auth_base
->cra_alignmask
| enc
->cra_alignmask
;
671 inst
->alg
.cra_type
= &crypto_aead_type
;
673 inst
->alg
.cra_aead
.ivsize
= enc
->cra_ablkcipher
.ivsize
;
674 inst
->alg
.cra_aead
.maxauthsize
= auth
->digestsize
;
676 inst
->alg
.cra_ctxsize
= sizeof(struct crypto_authenc_ctx
);
678 inst
->alg
.cra_init
= crypto_authenc_init_tfm
;
679 inst
->alg
.cra_exit
= crypto_authenc_exit_tfm
;
681 inst
->alg
.cra_aead
.setkey
= crypto_authenc_setkey
;
682 inst
->alg
.cra_aead
.encrypt
= crypto_authenc_encrypt
;
683 inst
->alg
.cra_aead
.decrypt
= crypto_authenc_decrypt
;
684 inst
->alg
.cra_aead
.givencrypt
= crypto_authenc_givencrypt
;
687 crypto_mod_put(auth_base
);
691 crypto_drop_skcipher(&ctx
->enc
);
693 crypto_drop_ahash(&ctx
->auth
);
701 static void crypto_authenc_free(struct crypto_instance
*inst
)
703 struct authenc_instance_ctx
*ctx
= crypto_instance_ctx(inst
);
705 crypto_drop_skcipher(&ctx
->enc
);
706 crypto_drop_ahash(&ctx
->auth
);
710 static struct crypto_template crypto_authenc_tmpl
= {
712 .alloc
= crypto_authenc_alloc
,
713 .free
= crypto_authenc_free
,
714 .module
= THIS_MODULE
,
717 static int __init
crypto_authenc_module_init(void)
719 return crypto_register_template(&crypto_authenc_tmpl
);
722 static void __exit
crypto_authenc_module_exit(void)
724 crypto_unregister_template(&crypto_authenc_tmpl
);
727 module_init(crypto_authenc_module_init
);
728 module_exit(crypto_authenc_module_exit
);
730 MODULE_LICENSE("GPL");
731 MODULE_DESCRIPTION("Simple AEAD wrapper for IPsec");
732 MODULE_ALIAS_CRYPTO("authenc");