2 * GCM: Galois/Counter Mode.
4 * Copyright (c) 2007 Nokia Siemens Networks - Mikko Herranen <mh1@iki.fi>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <crypto/gf128mul.h>
12 #include <crypto/internal/aead.h>
13 #include <crypto/internal/skcipher.h>
14 #include <crypto/scatterwalk.h>
15 #include <linux/completion.h>
16 #include <linux/err.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
22 struct gcm_instance_ctx
{
23 struct crypto_skcipher_spawn ctr
;
26 struct crypto_gcm_ctx
{
27 struct crypto_ablkcipher
*ctr
;
28 struct gf128mul_4k
*gf128
;
31 struct crypto_rfc4106_ctx
{
32 struct crypto_aead
*child
;
36 struct crypto_gcm_ghash_ctx
{
39 struct gf128mul_4k
*gf128
;
43 struct crypto_gcm_req_priv_ctx
{
46 struct scatterlist src
[2];
47 struct scatterlist dst
[2];
48 struct crypto_gcm_ghash_ctx ghash
;
49 struct ablkcipher_request abreq
;
52 struct crypto_gcm_setkey_result
{
54 struct completion completion
;
57 static inline struct crypto_gcm_req_priv_ctx
*crypto_gcm_reqctx(
58 struct aead_request
*req
)
60 unsigned long align
= crypto_aead_alignmask(crypto_aead_reqtfm(req
));
62 return (void *)PTR_ALIGN((u8
*)aead_request_ctx(req
), align
+ 1);
65 static void crypto_gcm_ghash_init(struct crypto_gcm_ghash_ctx
*ctx
, u32 flags
,
66 struct gf128mul_4k
*gf128
)
71 memset(ctx
->buffer
, 0, 16);
74 static void crypto_gcm_ghash_update(struct crypto_gcm_ghash_ctx
*ctx
,
75 const u8
*src
, unsigned int srclen
)
77 u8
*dst
= ctx
->buffer
;
80 int n
= min(srclen
, ctx
->bytes
);
81 u8
*pos
= dst
+ (16 - ctx
->bytes
);
90 gf128mul_4k_lle((be128
*)dst
, ctx
->gf128
);
93 while (srclen
>= 16) {
94 crypto_xor(dst
, src
, 16);
95 gf128mul_4k_lle((be128
*)dst
, ctx
->gf128
);
101 ctx
->bytes
= 16 - srclen
;
107 static void crypto_gcm_ghash_update_sg(struct crypto_gcm_ghash_ctx
*ctx
,
108 struct scatterlist
*sg
, int len
)
110 struct scatter_walk walk
;
117 scatterwalk_start(&walk
, sg
);
120 n
= scatterwalk_clamp(&walk
, len
);
123 scatterwalk_start(&walk
, scatterwalk_sg_next(walk
.sg
));
124 n
= scatterwalk_clamp(&walk
, len
);
127 src
= scatterwalk_map(&walk
, 0);
129 crypto_gcm_ghash_update(ctx
, src
, n
);
132 scatterwalk_unmap(src
, 0);
133 scatterwalk_advance(&walk
, n
);
134 scatterwalk_done(&walk
, 0, len
);
136 crypto_yield(ctx
->flags
);
140 static void crypto_gcm_ghash_flush(struct crypto_gcm_ghash_ctx
*ctx
)
142 u8
*dst
= ctx
->buffer
;
145 u8
*tmp
= dst
+ (16 - ctx
->bytes
);
150 gf128mul_4k_lle((be128
*)dst
, ctx
->gf128
);
156 static void crypto_gcm_ghash_final_xor(struct crypto_gcm_ghash_ctx
*ctx
,
157 unsigned int authlen
,
158 unsigned int cryptlen
, u8
*dst
)
160 u8
*buf
= ctx
->buffer
;
163 lengths
.a
= cpu_to_be64(authlen
* 8);
164 lengths
.b
= cpu_to_be64(cryptlen
* 8);
166 crypto_gcm_ghash_flush(ctx
);
167 crypto_xor(buf
, (u8
*)&lengths
, 16);
168 gf128mul_4k_lle((be128
*)buf
, ctx
->gf128
);
169 crypto_xor(dst
, buf
, 16);
172 static void crypto_gcm_setkey_done(struct crypto_async_request
*req
, int err
)
174 struct crypto_gcm_setkey_result
*result
= req
->data
;
176 if (err
== -EINPROGRESS
)
180 complete(&result
->completion
);
183 static int crypto_gcm_setkey(struct crypto_aead
*aead
, const u8
*key
,
186 struct crypto_gcm_ctx
*ctx
= crypto_aead_ctx(aead
);
187 struct crypto_ablkcipher
*ctr
= ctx
->ctr
;
192 struct crypto_gcm_setkey_result result
;
194 struct scatterlist sg
[1];
195 struct ablkcipher_request req
;
199 crypto_ablkcipher_clear_flags(ctr
, CRYPTO_TFM_REQ_MASK
);
200 crypto_ablkcipher_set_flags(ctr
, crypto_aead_get_flags(aead
) &
201 CRYPTO_TFM_REQ_MASK
);
203 err
= crypto_ablkcipher_setkey(ctr
, key
, keylen
);
207 crypto_aead_set_flags(aead
, crypto_ablkcipher_get_flags(ctr
) &
208 CRYPTO_TFM_RES_MASK
);
210 data
= kzalloc(sizeof(*data
) + crypto_ablkcipher_reqsize(ctr
),
215 init_completion(&data
->result
.completion
);
216 sg_init_one(data
->sg
, &data
->hash
, sizeof(data
->hash
));
217 ablkcipher_request_set_tfm(&data
->req
, ctr
);
218 ablkcipher_request_set_callback(&data
->req
, CRYPTO_TFM_REQ_MAY_SLEEP
|
219 CRYPTO_TFM_REQ_MAY_BACKLOG
,
220 crypto_gcm_setkey_done
,
222 ablkcipher_request_set_crypt(&data
->req
, data
->sg
, data
->sg
,
223 sizeof(data
->hash
), data
->iv
);
225 err
= crypto_ablkcipher_encrypt(&data
->req
);
226 if (err
== -EINPROGRESS
|| err
== -EBUSY
) {
227 err
= wait_for_completion_interruptible(
228 &data
->result
.completion
);
230 err
= data
->result
.err
;
236 if (ctx
->gf128
!= NULL
)
237 gf128mul_free_4k(ctx
->gf128
);
239 ctx
->gf128
= gf128mul_init_4k_lle(&data
->hash
);
241 if (ctx
->gf128
== NULL
)
249 static int crypto_gcm_setauthsize(struct crypto_aead
*tfm
,
250 unsigned int authsize
)
268 static void crypto_gcm_init_crypt(struct ablkcipher_request
*ablk_req
,
269 struct aead_request
*req
,
270 unsigned int cryptlen
)
272 struct crypto_aead
*aead
= crypto_aead_reqtfm(req
);
273 struct crypto_gcm_ctx
*ctx
= crypto_aead_ctx(aead
);
274 struct crypto_gcm_req_priv_ctx
*pctx
= crypto_gcm_reqctx(req
);
275 u32 flags
= req
->base
.tfm
->crt_flags
;
276 struct crypto_gcm_ghash_ctx
*ghash
= &pctx
->ghash
;
277 struct scatterlist
*dst
;
278 __be32 counter
= cpu_to_be32(1);
280 memset(pctx
->auth_tag
, 0, sizeof(pctx
->auth_tag
));
281 memcpy(req
->iv
+ 12, &counter
, 4);
283 sg_init_table(pctx
->src
, 2);
284 sg_set_buf(pctx
->src
, pctx
->auth_tag
, sizeof(pctx
->auth_tag
));
285 scatterwalk_sg_chain(pctx
->src
, 2, req
->src
);
288 if (req
->src
!= req
->dst
) {
289 sg_init_table(pctx
->dst
, 2);
290 sg_set_buf(pctx
->dst
, pctx
->auth_tag
, sizeof(pctx
->auth_tag
));
291 scatterwalk_sg_chain(pctx
->dst
, 2, req
->dst
);
295 ablkcipher_request_set_tfm(ablk_req
, ctx
->ctr
);
296 ablkcipher_request_set_crypt(ablk_req
, pctx
->src
, dst
,
297 cryptlen
+ sizeof(pctx
->auth_tag
),
300 crypto_gcm_ghash_init(ghash
, flags
, ctx
->gf128
);
302 crypto_gcm_ghash_update_sg(ghash
, req
->assoc
, req
->assoclen
);
303 crypto_gcm_ghash_flush(ghash
);
306 static int crypto_gcm_hash(struct aead_request
*req
)
308 struct crypto_aead
*aead
= crypto_aead_reqtfm(req
);
309 struct crypto_gcm_req_priv_ctx
*pctx
= crypto_gcm_reqctx(req
);
310 u8
*auth_tag
= pctx
->auth_tag
;
311 struct crypto_gcm_ghash_ctx
*ghash
= &pctx
->ghash
;
313 crypto_gcm_ghash_update_sg(ghash
, req
->dst
, req
->cryptlen
);
314 crypto_gcm_ghash_final_xor(ghash
, req
->assoclen
, req
->cryptlen
,
317 scatterwalk_map_and_copy(auth_tag
, req
->dst
, req
->cryptlen
,
318 crypto_aead_authsize(aead
), 1);
322 static void crypto_gcm_encrypt_done(struct crypto_async_request
*areq
, int err
)
324 struct aead_request
*req
= areq
->data
;
327 err
= crypto_gcm_hash(req
);
329 aead_request_complete(req
, err
);
332 static int crypto_gcm_encrypt(struct aead_request
*req
)
334 struct crypto_gcm_req_priv_ctx
*pctx
= crypto_gcm_reqctx(req
);
335 struct ablkcipher_request
*abreq
= &pctx
->abreq
;
338 crypto_gcm_init_crypt(abreq
, req
, req
->cryptlen
);
339 ablkcipher_request_set_callback(abreq
, aead_request_flags(req
),
340 crypto_gcm_encrypt_done
, req
);
342 err
= crypto_ablkcipher_encrypt(abreq
);
346 return crypto_gcm_hash(req
);
349 static int crypto_gcm_verify(struct aead_request
*req
)
351 struct crypto_aead
*aead
= crypto_aead_reqtfm(req
);
352 struct crypto_gcm_req_priv_ctx
*pctx
= crypto_gcm_reqctx(req
);
353 struct crypto_gcm_ghash_ctx
*ghash
= &pctx
->ghash
;
354 u8
*auth_tag
= pctx
->auth_tag
;
355 u8
*iauth_tag
= pctx
->iauth_tag
;
356 unsigned int authsize
= crypto_aead_authsize(aead
);
357 unsigned int cryptlen
= req
->cryptlen
- authsize
;
359 crypto_gcm_ghash_final_xor(ghash
, req
->assoclen
, cryptlen
, auth_tag
);
361 authsize
= crypto_aead_authsize(aead
);
362 scatterwalk_map_and_copy(iauth_tag
, req
->src
, cryptlen
, authsize
, 0);
363 return memcmp(iauth_tag
, auth_tag
, authsize
) ? -EBADMSG
: 0;
366 static void crypto_gcm_decrypt_done(struct crypto_async_request
*areq
, int err
)
368 struct aead_request
*req
= areq
->data
;
371 err
= crypto_gcm_verify(req
);
373 aead_request_complete(req
, err
);
376 static int crypto_gcm_decrypt(struct aead_request
*req
)
378 struct crypto_aead
*aead
= crypto_aead_reqtfm(req
);
379 struct crypto_gcm_req_priv_ctx
*pctx
= crypto_gcm_reqctx(req
);
380 struct ablkcipher_request
*abreq
= &pctx
->abreq
;
381 struct crypto_gcm_ghash_ctx
*ghash
= &pctx
->ghash
;
382 unsigned int cryptlen
= req
->cryptlen
;
383 unsigned int authsize
= crypto_aead_authsize(aead
);
386 if (cryptlen
< authsize
)
388 cryptlen
-= authsize
;
390 crypto_gcm_init_crypt(abreq
, req
, cryptlen
);
391 ablkcipher_request_set_callback(abreq
, aead_request_flags(req
),
392 crypto_gcm_decrypt_done
, req
);
394 crypto_gcm_ghash_update_sg(ghash
, req
->src
, cryptlen
);
396 err
= crypto_ablkcipher_decrypt(abreq
);
400 return crypto_gcm_verify(req
);
403 static int crypto_gcm_init_tfm(struct crypto_tfm
*tfm
)
405 struct crypto_instance
*inst
= (void *)tfm
->__crt_alg
;
406 struct gcm_instance_ctx
*ictx
= crypto_instance_ctx(inst
);
407 struct crypto_gcm_ctx
*ctx
= crypto_tfm_ctx(tfm
);
408 struct crypto_ablkcipher
*ctr
;
412 ctr
= crypto_spawn_skcipher(&ictx
->ctr
);
420 align
= crypto_tfm_alg_alignmask(tfm
);
421 align
&= ~(crypto_tfm_ctx_alignment() - 1);
422 tfm
->crt_aead
.reqsize
= align
+
423 sizeof(struct crypto_gcm_req_priv_ctx
) +
424 crypto_ablkcipher_reqsize(ctr
);
429 static void crypto_gcm_exit_tfm(struct crypto_tfm
*tfm
)
431 struct crypto_gcm_ctx
*ctx
= crypto_tfm_ctx(tfm
);
433 if (ctx
->gf128
!= NULL
)
434 gf128mul_free_4k(ctx
->gf128
);
436 crypto_free_ablkcipher(ctx
->ctr
);
439 static struct crypto_instance
*crypto_gcm_alloc_common(struct rtattr
**tb
,
440 const char *full_name
,
441 const char *ctr_name
)
443 struct crypto_attr_type
*algt
;
444 struct crypto_instance
*inst
;
445 struct crypto_alg
*ctr
;
446 struct gcm_instance_ctx
*ctx
;
449 algt
= crypto_get_attr_type(tb
);
454 if ((algt
->type
^ CRYPTO_ALG_TYPE_AEAD
) & algt
->mask
)
455 return ERR_PTR(-EINVAL
);
457 inst
= kzalloc(sizeof(*inst
) + sizeof(*ctx
), GFP_KERNEL
);
459 return ERR_PTR(-ENOMEM
);
461 ctx
= crypto_instance_ctx(inst
);
462 crypto_set_skcipher_spawn(&ctx
->ctr
, inst
);
463 err
= crypto_grab_skcipher(&ctx
->ctr
, ctr_name
, 0,
464 crypto_requires_sync(algt
->type
,
469 ctr
= crypto_skcipher_spawn_alg(&ctx
->ctr
);
471 /* We only support 16-byte blocks. */
472 if (ctr
->cra_ablkcipher
.ivsize
!= 16)
475 /* Not a stream cipher? */
477 if (ctr
->cra_blocksize
!= 1)
481 if (snprintf(inst
->alg
.cra_driver_name
, CRYPTO_MAX_ALG_NAME
,
482 "gcm_base(%s)", ctr
->cra_driver_name
) >=
486 memcpy(inst
->alg
.cra_name
, full_name
, CRYPTO_MAX_ALG_NAME
);
488 inst
->alg
.cra_flags
= CRYPTO_ALG_TYPE_AEAD
;
489 inst
->alg
.cra_flags
|= ctr
->cra_flags
& CRYPTO_ALG_ASYNC
;
490 inst
->alg
.cra_priority
= ctr
->cra_priority
;
491 inst
->alg
.cra_blocksize
= 1;
492 inst
->alg
.cra_alignmask
= ctr
->cra_alignmask
| (__alignof__(u64
) - 1);
493 inst
->alg
.cra_type
= &crypto_aead_type
;
494 inst
->alg
.cra_aead
.ivsize
= 16;
495 inst
->alg
.cra_aead
.maxauthsize
= 16;
496 inst
->alg
.cra_ctxsize
= sizeof(struct crypto_gcm_ctx
);
497 inst
->alg
.cra_init
= crypto_gcm_init_tfm
;
498 inst
->alg
.cra_exit
= crypto_gcm_exit_tfm
;
499 inst
->alg
.cra_aead
.setkey
= crypto_gcm_setkey
;
500 inst
->alg
.cra_aead
.setauthsize
= crypto_gcm_setauthsize
;
501 inst
->alg
.cra_aead
.encrypt
= crypto_gcm_encrypt
;
502 inst
->alg
.cra_aead
.decrypt
= crypto_gcm_decrypt
;
508 crypto_drop_skcipher(&ctx
->ctr
);
515 static struct crypto_instance
*crypto_gcm_alloc(struct rtattr
**tb
)
518 const char *cipher_name
;
519 char ctr_name
[CRYPTO_MAX_ALG_NAME
];
520 char full_name
[CRYPTO_MAX_ALG_NAME
];
522 cipher_name
= crypto_attr_alg_name(tb
[1]);
523 err
= PTR_ERR(cipher_name
);
524 if (IS_ERR(cipher_name
))
527 if (snprintf(ctr_name
, CRYPTO_MAX_ALG_NAME
, "ctr(%s)", cipher_name
) >=
529 return ERR_PTR(-ENAMETOOLONG
);
531 if (snprintf(full_name
, CRYPTO_MAX_ALG_NAME
, "gcm(%s)", cipher_name
) >=
533 return ERR_PTR(-ENAMETOOLONG
);
535 return crypto_gcm_alloc_common(tb
, full_name
, ctr_name
);
538 static void crypto_gcm_free(struct crypto_instance
*inst
)
540 struct gcm_instance_ctx
*ctx
= crypto_instance_ctx(inst
);
542 crypto_drop_skcipher(&ctx
->ctr
);
546 static struct crypto_template crypto_gcm_tmpl
= {
548 .alloc
= crypto_gcm_alloc
,
549 .free
= crypto_gcm_free
,
550 .module
= THIS_MODULE
,
553 static struct crypto_instance
*crypto_gcm_base_alloc(struct rtattr
**tb
)
556 const char *ctr_name
;
557 char full_name
[CRYPTO_MAX_ALG_NAME
];
559 ctr_name
= crypto_attr_alg_name(tb
[1]);
560 err
= PTR_ERR(ctr_name
);
561 if (IS_ERR(ctr_name
))
564 if (snprintf(full_name
, CRYPTO_MAX_ALG_NAME
, "gcm_base(%s)",
565 ctr_name
) >= CRYPTO_MAX_ALG_NAME
)
566 return ERR_PTR(-ENAMETOOLONG
);
568 return crypto_gcm_alloc_common(tb
, full_name
, ctr_name
);
571 static struct crypto_template crypto_gcm_base_tmpl
= {
573 .alloc
= crypto_gcm_base_alloc
,
574 .free
= crypto_gcm_free
,
575 .module
= THIS_MODULE
,
578 static int crypto_rfc4106_setkey(struct crypto_aead
*parent
, const u8
*key
,
581 struct crypto_rfc4106_ctx
*ctx
= crypto_aead_ctx(parent
);
582 struct crypto_aead
*child
= ctx
->child
;
589 memcpy(ctx
->nonce
, key
+ keylen
, 4);
591 crypto_aead_clear_flags(child
, CRYPTO_TFM_REQ_MASK
);
592 crypto_aead_set_flags(child
, crypto_aead_get_flags(parent
) &
593 CRYPTO_TFM_REQ_MASK
);
594 err
= crypto_aead_setkey(child
, key
, keylen
);
595 crypto_aead_set_flags(parent
, crypto_aead_get_flags(child
) &
596 CRYPTO_TFM_RES_MASK
);
601 static int crypto_rfc4106_setauthsize(struct crypto_aead
*parent
,
602 unsigned int authsize
)
604 struct crypto_rfc4106_ctx
*ctx
= crypto_aead_ctx(parent
);
615 return crypto_aead_setauthsize(ctx
->child
, authsize
);
618 static struct aead_request
*crypto_rfc4106_crypt(struct aead_request
*req
)
620 struct aead_request
*subreq
= aead_request_ctx(req
);
621 struct crypto_aead
*aead
= crypto_aead_reqtfm(req
);
622 struct crypto_rfc4106_ctx
*ctx
= crypto_aead_ctx(aead
);
623 struct crypto_aead
*child
= ctx
->child
;
624 u8
*iv
= PTR_ALIGN((u8
*)(subreq
+ 1) + crypto_aead_reqsize(child
),
625 crypto_aead_alignmask(child
) + 1);
627 memcpy(iv
, ctx
->nonce
, 4);
628 memcpy(iv
+ 4, req
->iv
, 8);
630 aead_request_set_tfm(subreq
, child
);
631 aead_request_set_callback(subreq
, req
->base
.flags
, req
->base
.complete
,
633 aead_request_set_crypt(subreq
, req
->src
, req
->dst
, req
->cryptlen
, iv
);
634 aead_request_set_assoc(subreq
, req
->assoc
, req
->assoclen
);
639 static int crypto_rfc4106_encrypt(struct aead_request
*req
)
641 req
= crypto_rfc4106_crypt(req
);
643 return crypto_aead_encrypt(req
);
646 static int crypto_rfc4106_decrypt(struct aead_request
*req
)
648 req
= crypto_rfc4106_crypt(req
);
650 return crypto_aead_decrypt(req
);
653 static int crypto_rfc4106_init_tfm(struct crypto_tfm
*tfm
)
655 struct crypto_instance
*inst
= (void *)tfm
->__crt_alg
;
656 struct crypto_aead_spawn
*spawn
= crypto_instance_ctx(inst
);
657 struct crypto_rfc4106_ctx
*ctx
= crypto_tfm_ctx(tfm
);
658 struct crypto_aead
*aead
;
661 aead
= crypto_spawn_aead(spawn
);
663 return PTR_ERR(aead
);
667 align
= crypto_aead_alignmask(aead
);
668 align
&= ~(crypto_tfm_ctx_alignment() - 1);
669 tfm
->crt_aead
.reqsize
= sizeof(struct aead_request
) +
670 ALIGN(crypto_aead_reqsize(aead
),
671 crypto_tfm_ctx_alignment()) +
677 static void crypto_rfc4106_exit_tfm(struct crypto_tfm
*tfm
)
679 struct crypto_rfc4106_ctx
*ctx
= crypto_tfm_ctx(tfm
);
681 crypto_free_aead(ctx
->child
);
684 static struct crypto_instance
*crypto_rfc4106_alloc(struct rtattr
**tb
)
686 struct crypto_attr_type
*algt
;
687 struct crypto_instance
*inst
;
688 struct crypto_aead_spawn
*spawn
;
689 struct crypto_alg
*alg
;
690 const char *ccm_name
;
693 algt
= crypto_get_attr_type(tb
);
698 if ((algt
->type
^ CRYPTO_ALG_TYPE_AEAD
) & algt
->mask
)
699 return ERR_PTR(-EINVAL
);
701 ccm_name
= crypto_attr_alg_name(tb
[1]);
702 err
= PTR_ERR(ccm_name
);
703 if (IS_ERR(ccm_name
))
706 inst
= kzalloc(sizeof(*inst
) + sizeof(*spawn
), GFP_KERNEL
);
708 return ERR_PTR(-ENOMEM
);
710 spawn
= crypto_instance_ctx(inst
);
711 crypto_set_aead_spawn(spawn
, inst
);
712 err
= crypto_grab_aead(spawn
, ccm_name
, 0,
713 crypto_requires_sync(algt
->type
, algt
->mask
));
717 alg
= crypto_aead_spawn_alg(spawn
);
721 /* We only support 16-byte blocks. */
722 if (alg
->cra_aead
.ivsize
!= 16)
725 /* Not a stream cipher? */
726 if (alg
->cra_blocksize
!= 1)
730 if (snprintf(inst
->alg
.cra_name
, CRYPTO_MAX_ALG_NAME
,
731 "rfc4106(%s)", alg
->cra_name
) >= CRYPTO_MAX_ALG_NAME
||
732 snprintf(inst
->alg
.cra_driver_name
, CRYPTO_MAX_ALG_NAME
,
733 "rfc4106(%s)", alg
->cra_driver_name
) >=
737 inst
->alg
.cra_flags
= CRYPTO_ALG_TYPE_AEAD
;
738 inst
->alg
.cra_flags
|= alg
->cra_flags
& CRYPTO_ALG_ASYNC
;
739 inst
->alg
.cra_priority
= alg
->cra_priority
;
740 inst
->alg
.cra_blocksize
= 1;
741 inst
->alg
.cra_alignmask
= alg
->cra_alignmask
;
742 inst
->alg
.cra_type
= &crypto_nivaead_type
;
744 inst
->alg
.cra_aead
.ivsize
= 8;
745 inst
->alg
.cra_aead
.maxauthsize
= 16;
747 inst
->alg
.cra_ctxsize
= sizeof(struct crypto_rfc4106_ctx
);
749 inst
->alg
.cra_init
= crypto_rfc4106_init_tfm
;
750 inst
->alg
.cra_exit
= crypto_rfc4106_exit_tfm
;
752 inst
->alg
.cra_aead
.setkey
= crypto_rfc4106_setkey
;
753 inst
->alg
.cra_aead
.setauthsize
= crypto_rfc4106_setauthsize
;
754 inst
->alg
.cra_aead
.encrypt
= crypto_rfc4106_encrypt
;
755 inst
->alg
.cra_aead
.decrypt
= crypto_rfc4106_decrypt
;
757 inst
->alg
.cra_aead
.geniv
= "seqiv";
763 crypto_drop_aead(spawn
);
770 static void crypto_rfc4106_free(struct crypto_instance
*inst
)
772 crypto_drop_spawn(crypto_instance_ctx(inst
));
776 static struct crypto_template crypto_rfc4106_tmpl
= {
778 .alloc
= crypto_rfc4106_alloc
,
779 .free
= crypto_rfc4106_free
,
780 .module
= THIS_MODULE
,
783 static int __init
crypto_gcm_module_init(void)
787 err
= crypto_register_template(&crypto_gcm_base_tmpl
);
791 err
= crypto_register_template(&crypto_gcm_tmpl
);
795 err
= crypto_register_template(&crypto_rfc4106_tmpl
);
803 crypto_unregister_template(&crypto_gcm_tmpl
);
805 crypto_unregister_template(&crypto_gcm_base_tmpl
);
809 static void __exit
crypto_gcm_module_exit(void)
811 crypto_unregister_template(&crypto_rfc4106_tmpl
);
812 crypto_unregister_template(&crypto_gcm_tmpl
);
813 crypto_unregister_template(&crypto_gcm_base_tmpl
);
816 module_init(crypto_gcm_module_init
);
817 module_exit(crypto_gcm_module_exit
);
819 MODULE_LICENSE("GPL");
820 MODULE_DESCRIPTION("Galois/Counter Mode");
821 MODULE_AUTHOR("Mikko Herranen <mh1@iki.fi>");
822 MODULE_ALIAS("gcm_base");
823 MODULE_ALIAS("rfc4106");