.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * CCM: Counter with CBC-MAC |
---|
3 | 4 | * |
---|
4 | 5 | * (C) Copyright IBM Corp. 2007 - Joy Latten <latten@us.ibm.com> |
---|
5 | | - * |
---|
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) |
---|
9 | | - * any later version. |
---|
10 | | - * |
---|
11 | 6 | */ |
---|
12 | 7 | |
---|
13 | 8 | #include <crypto/internal/aead.h> |
---|
| 9 | +#include <crypto/internal/cipher.h> |
---|
14 | 10 | #include <crypto/internal/hash.h> |
---|
15 | 11 | #include <crypto/internal/skcipher.h> |
---|
16 | 12 | #include <crypto/scatterwalk.h> |
---|
.. | .. |
---|
19 | 15 | #include <linux/kernel.h> |
---|
20 | 16 | #include <linux/module.h> |
---|
21 | 17 | #include <linux/slab.h> |
---|
22 | | - |
---|
23 | | -#include "internal.h" |
---|
24 | 18 | |
---|
25 | 19 | struct ccm_instance_ctx { |
---|
26 | 20 | struct crypto_skcipher_spawn ctr; |
---|
.. | .. |
---|
50 | 44 | u32 flags; |
---|
51 | 45 | struct scatterlist src[3]; |
---|
52 | 46 | struct scatterlist dst[3]; |
---|
53 | | - struct skcipher_request skreq; |
---|
| 47 | + union { |
---|
| 48 | + struct ahash_request ahreq; |
---|
| 49 | + struct skcipher_request skreq; |
---|
| 50 | + }; |
---|
54 | 51 | }; |
---|
55 | 52 | |
---|
56 | 53 | struct cbcmac_tfm_ctx { |
---|
.. | .. |
---|
93 | 90 | struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead); |
---|
94 | 91 | struct crypto_skcipher *ctr = ctx->ctr; |
---|
95 | 92 | struct crypto_ahash *mac = ctx->mac; |
---|
96 | | - int err = 0; |
---|
| 93 | + int err; |
---|
97 | 94 | |
---|
98 | 95 | crypto_skcipher_clear_flags(ctr, CRYPTO_TFM_REQ_MASK); |
---|
99 | 96 | crypto_skcipher_set_flags(ctr, crypto_aead_get_flags(aead) & |
---|
100 | 97 | CRYPTO_TFM_REQ_MASK); |
---|
101 | 98 | err = crypto_skcipher_setkey(ctr, key, keylen); |
---|
102 | | - crypto_aead_set_flags(aead, crypto_skcipher_get_flags(ctr) & |
---|
103 | | - CRYPTO_TFM_RES_MASK); |
---|
104 | 99 | if (err) |
---|
105 | | - goto out; |
---|
| 100 | + return err; |
---|
106 | 101 | |
---|
107 | 102 | crypto_ahash_clear_flags(mac, CRYPTO_TFM_REQ_MASK); |
---|
108 | 103 | crypto_ahash_set_flags(mac, crypto_aead_get_flags(aead) & |
---|
109 | 104 | CRYPTO_TFM_REQ_MASK); |
---|
110 | | - err = crypto_ahash_setkey(mac, key, keylen); |
---|
111 | | - crypto_aead_set_flags(aead, crypto_ahash_get_flags(mac) & |
---|
112 | | - CRYPTO_TFM_RES_MASK); |
---|
113 | | - |
---|
114 | | -out: |
---|
115 | | - return err; |
---|
| 105 | + return crypto_ahash_setkey(mac, key, keylen); |
---|
116 | 106 | } |
---|
117 | 107 | |
---|
118 | 108 | static int crypto_ccm_setauthsize(struct crypto_aead *tfm, |
---|
.. | .. |
---|
181 | 171 | struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req); |
---|
182 | 172 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
---|
183 | 173 | struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead); |
---|
184 | | - AHASH_REQUEST_ON_STACK(ahreq, ctx->mac); |
---|
| 174 | + struct ahash_request *ahreq = &pctx->ahreq; |
---|
185 | 175 | unsigned int assoclen = req->assoclen; |
---|
186 | 176 | struct scatterlist sg[3]; |
---|
187 | 177 | u8 *odata = pctx->odata; |
---|
.. | .. |
---|
427 | 417 | crypto_aead_set_reqsize( |
---|
428 | 418 | tfm, |
---|
429 | 419 | align + sizeof(struct crypto_ccm_req_priv_ctx) + |
---|
430 | | - crypto_skcipher_reqsize(ctr)); |
---|
| 420 | + max(crypto_ahash_reqsize(mac), crypto_skcipher_reqsize(ctr))); |
---|
431 | 421 | |
---|
432 | 422 | return 0; |
---|
433 | 423 | |
---|
.. | .. |
---|
458 | 448 | const char *ctr_name, |
---|
459 | 449 | const char *mac_name) |
---|
460 | 450 | { |
---|
461 | | - struct crypto_attr_type *algt; |
---|
| 451 | + u32 mask; |
---|
462 | 452 | struct aead_instance *inst; |
---|
463 | | - struct skcipher_alg *ctr; |
---|
464 | | - struct crypto_alg *mac_alg; |
---|
465 | | - struct hash_alg_common *mac; |
---|
466 | 453 | struct ccm_instance_ctx *ictx; |
---|
| 454 | + struct skcipher_alg *ctr; |
---|
| 455 | + struct hash_alg_common *mac; |
---|
467 | 456 | int err; |
---|
468 | 457 | |
---|
469 | | - algt = crypto_get_attr_type(tb); |
---|
470 | | - if (IS_ERR(algt)) |
---|
471 | | - return PTR_ERR(algt); |
---|
| 458 | + err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD, &mask); |
---|
| 459 | + if (err) |
---|
| 460 | + return err; |
---|
472 | 461 | |
---|
473 | | - if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) |
---|
474 | | - return -EINVAL; |
---|
| 462 | + inst = kzalloc(sizeof(*inst) + sizeof(*ictx), GFP_KERNEL); |
---|
| 463 | + if (!inst) |
---|
| 464 | + return -ENOMEM; |
---|
| 465 | + ictx = aead_instance_ctx(inst); |
---|
475 | 466 | |
---|
476 | | - mac_alg = crypto_find_alg(mac_name, &crypto_ahash_type, |
---|
477 | | - CRYPTO_ALG_TYPE_HASH, |
---|
478 | | - CRYPTO_ALG_TYPE_AHASH_MASK | |
---|
479 | | - CRYPTO_ALG_ASYNC); |
---|
480 | | - if (IS_ERR(mac_alg)) |
---|
481 | | - return PTR_ERR(mac_alg); |
---|
| 467 | + err = crypto_grab_ahash(&ictx->mac, aead_crypto_instance(inst), |
---|
| 468 | + mac_name, 0, mask | CRYPTO_ALG_ASYNC); |
---|
| 469 | + if (err) |
---|
| 470 | + goto err_free_inst; |
---|
| 471 | + mac = crypto_spawn_ahash_alg(&ictx->mac); |
---|
482 | 472 | |
---|
483 | | - mac = __crypto_hash_alg_common(mac_alg); |
---|
484 | 473 | err = -EINVAL; |
---|
485 | 474 | if (strncmp(mac->base.cra_name, "cbcmac(", 7) != 0 || |
---|
486 | 475 | mac->digestsize != 16) |
---|
487 | | - goto out_put_mac; |
---|
488 | | - |
---|
489 | | - inst = kzalloc(sizeof(*inst) + sizeof(*ictx), GFP_KERNEL); |
---|
490 | | - err = -ENOMEM; |
---|
491 | | - if (!inst) |
---|
492 | | - goto out_put_mac; |
---|
493 | | - |
---|
494 | | - ictx = aead_instance_ctx(inst); |
---|
495 | | - err = crypto_init_ahash_spawn(&ictx->mac, mac, |
---|
496 | | - aead_crypto_instance(inst)); |
---|
497 | | - if (err) |
---|
498 | 476 | goto err_free_inst; |
---|
499 | 477 | |
---|
500 | | - crypto_set_skcipher_spawn(&ictx->ctr, aead_crypto_instance(inst)); |
---|
501 | | - err = crypto_grab_skcipher(&ictx->ctr, ctr_name, 0, |
---|
502 | | - crypto_requires_sync(algt->type, |
---|
503 | | - algt->mask)); |
---|
| 478 | + err = crypto_grab_skcipher(&ictx->ctr, aead_crypto_instance(inst), |
---|
| 479 | + ctr_name, 0, mask); |
---|
504 | 480 | if (err) |
---|
505 | | - goto err_drop_mac; |
---|
506 | | - |
---|
| 481 | + goto err_free_inst; |
---|
507 | 482 | ctr = crypto_spawn_skcipher_alg(&ictx->ctr); |
---|
508 | 483 | |
---|
509 | 484 | /* The skcipher algorithm must be CTR mode, using 16-byte blocks. */ |
---|
.. | .. |
---|
511 | 486 | if (strncmp(ctr->base.cra_name, "ctr(", 4) != 0 || |
---|
512 | 487 | crypto_skcipher_alg_ivsize(ctr) != 16 || |
---|
513 | 488 | ctr->base.cra_blocksize != 1) |
---|
514 | | - goto err_drop_ctr; |
---|
| 489 | + goto err_free_inst; |
---|
515 | 490 | |
---|
516 | 491 | /* ctr and cbcmac must use the same underlying block cipher. */ |
---|
517 | 492 | if (strcmp(ctr->base.cra_name + 4, mac->base.cra_name + 7) != 0) |
---|
518 | | - goto err_drop_ctr; |
---|
| 493 | + goto err_free_inst; |
---|
519 | 494 | |
---|
520 | 495 | err = -ENAMETOOLONG; |
---|
521 | 496 | if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, |
---|
522 | 497 | "ccm(%s", ctr->base.cra_name + 4) >= CRYPTO_MAX_ALG_NAME) |
---|
523 | | - goto err_drop_ctr; |
---|
| 498 | + goto err_free_inst; |
---|
524 | 499 | |
---|
525 | 500 | if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
---|
526 | 501 | "ccm_base(%s,%s)", ctr->base.cra_driver_name, |
---|
527 | 502 | mac->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME) |
---|
528 | | - goto err_drop_ctr; |
---|
| 503 | + goto err_free_inst; |
---|
529 | 504 | |
---|
530 | | - inst->alg.base.cra_flags = ctr->base.cra_flags & CRYPTO_ALG_ASYNC; |
---|
531 | 505 | inst->alg.base.cra_priority = (mac->base.cra_priority + |
---|
532 | 506 | ctr->base.cra_priority) / 2; |
---|
533 | 507 | inst->alg.base.cra_blocksize = 1; |
---|
.. | .. |
---|
547 | 521 | inst->free = crypto_ccm_free; |
---|
548 | 522 | |
---|
549 | 523 | err = aead_register_instance(tmpl, inst); |
---|
550 | | - if (err) |
---|
551 | | - goto err_drop_ctr; |
---|
552 | | - |
---|
553 | | -out_put_mac: |
---|
554 | | - crypto_mod_put(mac_alg); |
---|
555 | | - return err; |
---|
556 | | - |
---|
557 | | -err_drop_ctr: |
---|
558 | | - crypto_drop_skcipher(&ictx->ctr); |
---|
559 | | -err_drop_mac: |
---|
560 | | - crypto_drop_ahash(&ictx->mac); |
---|
| 524 | + if (err) { |
---|
561 | 525 | err_free_inst: |
---|
562 | | - kfree(inst); |
---|
563 | | - goto out_put_mac; |
---|
| 526 | + crypto_ccm_free(inst); |
---|
| 527 | + } |
---|
| 528 | + return err; |
---|
564 | 529 | } |
---|
565 | 530 | |
---|
566 | 531 | static int crypto_ccm_create(struct crypto_template *tmpl, struct rtattr **tb) |
---|
.. | .. |
---|
584 | 549 | return crypto_ccm_create_common(tmpl, tb, ctr_name, mac_name); |
---|
585 | 550 | } |
---|
586 | 551 | |
---|
587 | | -static struct crypto_template crypto_ccm_tmpl = { |
---|
588 | | - .name = "ccm", |
---|
589 | | - .create = crypto_ccm_create, |
---|
590 | | - .module = THIS_MODULE, |
---|
591 | | -}; |
---|
592 | | - |
---|
593 | 552 | static int crypto_ccm_base_create(struct crypto_template *tmpl, |
---|
594 | 553 | struct rtattr **tb) |
---|
595 | 554 | { |
---|
.. | .. |
---|
607 | 566 | return crypto_ccm_create_common(tmpl, tb, ctr_name, mac_name); |
---|
608 | 567 | } |
---|
609 | 568 | |
---|
610 | | -static struct crypto_template crypto_ccm_base_tmpl = { |
---|
611 | | - .name = "ccm_base", |
---|
612 | | - .create = crypto_ccm_base_create, |
---|
613 | | - .module = THIS_MODULE, |
---|
614 | | -}; |
---|
615 | | - |
---|
616 | 569 | static int crypto_rfc4309_setkey(struct crypto_aead *parent, const u8 *key, |
---|
617 | 570 | unsigned int keylen) |
---|
618 | 571 | { |
---|
619 | 572 | struct crypto_rfc4309_ctx *ctx = crypto_aead_ctx(parent); |
---|
620 | 573 | struct crypto_aead *child = ctx->child; |
---|
621 | | - int err; |
---|
622 | 574 | |
---|
623 | 575 | if (keylen < 3) |
---|
624 | 576 | return -EINVAL; |
---|
.. | .. |
---|
629 | 581 | crypto_aead_clear_flags(child, CRYPTO_TFM_REQ_MASK); |
---|
630 | 582 | crypto_aead_set_flags(child, crypto_aead_get_flags(parent) & |
---|
631 | 583 | CRYPTO_TFM_REQ_MASK); |
---|
632 | | - err = crypto_aead_setkey(child, key, keylen); |
---|
633 | | - crypto_aead_set_flags(parent, crypto_aead_get_flags(child) & |
---|
634 | | - CRYPTO_TFM_RES_MASK); |
---|
635 | | - |
---|
636 | | - return err; |
---|
| 584 | + return crypto_aead_setkey(child, key, keylen); |
---|
637 | 585 | } |
---|
638 | 586 | |
---|
639 | 587 | static int crypto_rfc4309_setauthsize(struct crypto_aead *parent, |
---|
.. | .. |
---|
758 | 706 | static int crypto_rfc4309_create(struct crypto_template *tmpl, |
---|
759 | 707 | struct rtattr **tb) |
---|
760 | 708 | { |
---|
761 | | - struct crypto_attr_type *algt; |
---|
| 709 | + u32 mask; |
---|
762 | 710 | struct aead_instance *inst; |
---|
763 | 711 | struct crypto_aead_spawn *spawn; |
---|
764 | 712 | struct aead_alg *alg; |
---|
765 | | - const char *ccm_name; |
---|
766 | 713 | int err; |
---|
767 | 714 | |
---|
768 | | - algt = crypto_get_attr_type(tb); |
---|
769 | | - if (IS_ERR(algt)) |
---|
770 | | - return PTR_ERR(algt); |
---|
771 | | - |
---|
772 | | - if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) |
---|
773 | | - return -EINVAL; |
---|
774 | | - |
---|
775 | | - ccm_name = crypto_attr_alg_name(tb[1]); |
---|
776 | | - if (IS_ERR(ccm_name)) |
---|
777 | | - return PTR_ERR(ccm_name); |
---|
| 715 | + err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD, &mask); |
---|
| 716 | + if (err) |
---|
| 717 | + return err; |
---|
778 | 718 | |
---|
779 | 719 | inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); |
---|
780 | 720 | if (!inst) |
---|
781 | 721 | return -ENOMEM; |
---|
782 | 722 | |
---|
783 | 723 | spawn = aead_instance_ctx(inst); |
---|
784 | | - crypto_set_aead_spawn(spawn, aead_crypto_instance(inst)); |
---|
785 | | - err = crypto_grab_aead(spawn, ccm_name, 0, |
---|
786 | | - crypto_requires_sync(algt->type, algt->mask)); |
---|
| 724 | + err = crypto_grab_aead(spawn, aead_crypto_instance(inst), |
---|
| 725 | + crypto_attr_alg_name(tb[1]), 0, mask); |
---|
787 | 726 | if (err) |
---|
788 | | - goto out_free_inst; |
---|
| 727 | + goto err_free_inst; |
---|
789 | 728 | |
---|
790 | 729 | alg = crypto_spawn_aead_alg(spawn); |
---|
791 | 730 | |
---|
.. | .. |
---|
793 | 732 | |
---|
794 | 733 | /* We only support 16-byte blocks. */ |
---|
795 | 734 | if (crypto_aead_alg_ivsize(alg) != 16) |
---|
796 | | - goto out_drop_alg; |
---|
| 735 | + goto err_free_inst; |
---|
797 | 736 | |
---|
798 | 737 | /* Not a stream cipher? */ |
---|
799 | 738 | if (alg->base.cra_blocksize != 1) |
---|
800 | | - goto out_drop_alg; |
---|
| 739 | + goto err_free_inst; |
---|
801 | 740 | |
---|
802 | 741 | err = -ENAMETOOLONG; |
---|
803 | 742 | if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, |
---|
.. | .. |
---|
806 | 745 | snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
---|
807 | 746 | "rfc4309(%s)", alg->base.cra_driver_name) >= |
---|
808 | 747 | CRYPTO_MAX_ALG_NAME) |
---|
809 | | - goto out_drop_alg; |
---|
| 748 | + goto err_free_inst; |
---|
810 | 749 | |
---|
811 | | - inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC; |
---|
812 | 750 | inst->alg.base.cra_priority = alg->base.cra_priority; |
---|
813 | 751 | inst->alg.base.cra_blocksize = 1; |
---|
814 | 752 | inst->alg.base.cra_alignmask = alg->base.cra_alignmask; |
---|
.. | .. |
---|
830 | 768 | inst->free = crypto_rfc4309_free; |
---|
831 | 769 | |
---|
832 | 770 | err = aead_register_instance(tmpl, inst); |
---|
833 | | - if (err) |
---|
834 | | - goto out_drop_alg; |
---|
835 | | - |
---|
836 | | -out: |
---|
| 771 | + if (err) { |
---|
| 772 | +err_free_inst: |
---|
| 773 | + crypto_rfc4309_free(inst); |
---|
| 774 | + } |
---|
837 | 775 | return err; |
---|
838 | | - |
---|
839 | | -out_drop_alg: |
---|
840 | | - crypto_drop_aead(spawn); |
---|
841 | | -out_free_inst: |
---|
842 | | - kfree(inst); |
---|
843 | | - goto out; |
---|
844 | 776 | } |
---|
845 | | - |
---|
846 | | -static struct crypto_template crypto_rfc4309_tmpl = { |
---|
847 | | - .name = "rfc4309", |
---|
848 | | - .create = crypto_rfc4309_create, |
---|
849 | | - .module = THIS_MODULE, |
---|
850 | | -}; |
---|
851 | 777 | |
---|
852 | 778 | static int crypto_cbcmac_digest_setkey(struct crypto_shash *parent, |
---|
853 | 779 | const u8 *inkey, unsigned int keylen) |
---|
.. | .. |
---|
916 | 842 | { |
---|
917 | 843 | struct crypto_cipher *cipher; |
---|
918 | 844 | struct crypto_instance *inst = (void *)tfm->__crt_alg; |
---|
919 | | - struct crypto_spawn *spawn = crypto_instance_ctx(inst); |
---|
| 845 | + struct crypto_cipher_spawn *spawn = crypto_instance_ctx(inst); |
---|
920 | 846 | struct cbcmac_tfm_ctx *ctx = crypto_tfm_ctx(tfm); |
---|
921 | 847 | |
---|
922 | 848 | cipher = crypto_spawn_cipher(spawn); |
---|
.. | .. |
---|
937 | 863 | static int cbcmac_create(struct crypto_template *tmpl, struct rtattr **tb) |
---|
938 | 864 | { |
---|
939 | 865 | struct shash_instance *inst; |
---|
| 866 | + struct crypto_cipher_spawn *spawn; |
---|
940 | 867 | struct crypto_alg *alg; |
---|
| 868 | + u32 mask; |
---|
941 | 869 | int err; |
---|
942 | 870 | |
---|
943 | | - err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH); |
---|
| 871 | + err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask); |
---|
944 | 872 | if (err) |
---|
945 | 873 | return err; |
---|
946 | 874 | |
---|
947 | | - alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, |
---|
948 | | - CRYPTO_ALG_TYPE_MASK); |
---|
949 | | - if (IS_ERR(alg)) |
---|
950 | | - return PTR_ERR(alg); |
---|
| 875 | + inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); |
---|
| 876 | + if (!inst) |
---|
| 877 | + return -ENOMEM; |
---|
| 878 | + spawn = shash_instance_ctx(inst); |
---|
951 | 879 | |
---|
952 | | - inst = shash_alloc_instance("cbcmac", alg); |
---|
953 | | - err = PTR_ERR(inst); |
---|
954 | | - if (IS_ERR(inst)) |
---|
955 | | - goto out_put_alg; |
---|
956 | | - |
---|
957 | | - err = crypto_init_spawn(shash_instance_ctx(inst), alg, |
---|
958 | | - shash_crypto_instance(inst), |
---|
959 | | - CRYPTO_ALG_TYPE_MASK); |
---|
| 880 | + err = crypto_grab_cipher(spawn, shash_crypto_instance(inst), |
---|
| 881 | + crypto_attr_alg_name(tb[1]), 0, mask); |
---|
960 | 882 | if (err) |
---|
961 | | - goto out_free_inst; |
---|
| 883 | + goto err_free_inst; |
---|
| 884 | + alg = crypto_spawn_cipher_alg(spawn); |
---|
| 885 | + |
---|
| 886 | + err = crypto_inst_setname(shash_crypto_instance(inst), tmpl->name, alg); |
---|
| 887 | + if (err) |
---|
| 888 | + goto err_free_inst; |
---|
962 | 889 | |
---|
963 | 890 | inst->alg.base.cra_priority = alg->cra_priority; |
---|
964 | 891 | inst->alg.base.cra_blocksize = 1; |
---|
.. | .. |
---|
977 | 904 | inst->alg.final = crypto_cbcmac_digest_final; |
---|
978 | 905 | inst->alg.setkey = crypto_cbcmac_digest_setkey; |
---|
979 | 906 | |
---|
| 907 | + inst->free = shash_free_singlespawn_instance; |
---|
| 908 | + |
---|
980 | 909 | err = shash_register_instance(tmpl, inst); |
---|
981 | | - |
---|
982 | | -out_free_inst: |
---|
983 | | - if (err) |
---|
984 | | - shash_free_instance(shash_crypto_instance(inst)); |
---|
985 | | - |
---|
986 | | -out_put_alg: |
---|
987 | | - crypto_mod_put(alg); |
---|
| 910 | + if (err) { |
---|
| 911 | +err_free_inst: |
---|
| 912 | + shash_free_singlespawn_instance(inst); |
---|
| 913 | + } |
---|
988 | 914 | return err; |
---|
989 | 915 | } |
---|
990 | 916 | |
---|
991 | | -static struct crypto_template crypto_cbcmac_tmpl = { |
---|
992 | | - .name = "cbcmac", |
---|
993 | | - .create = cbcmac_create, |
---|
994 | | - .free = shash_free_instance, |
---|
995 | | - .module = THIS_MODULE, |
---|
| 917 | +static struct crypto_template crypto_ccm_tmpls[] = { |
---|
| 918 | + { |
---|
| 919 | + .name = "cbcmac", |
---|
| 920 | + .create = cbcmac_create, |
---|
| 921 | + .module = THIS_MODULE, |
---|
| 922 | + }, { |
---|
| 923 | + .name = "ccm_base", |
---|
| 924 | + .create = crypto_ccm_base_create, |
---|
| 925 | + .module = THIS_MODULE, |
---|
| 926 | + }, { |
---|
| 927 | + .name = "ccm", |
---|
| 928 | + .create = crypto_ccm_create, |
---|
| 929 | + .module = THIS_MODULE, |
---|
| 930 | + }, { |
---|
| 931 | + .name = "rfc4309", |
---|
| 932 | + .create = crypto_rfc4309_create, |
---|
| 933 | + .module = THIS_MODULE, |
---|
| 934 | + }, |
---|
996 | 935 | }; |
---|
997 | 936 | |
---|
998 | 937 | static int __init crypto_ccm_module_init(void) |
---|
999 | 938 | { |
---|
1000 | | - int err; |
---|
1001 | | - |
---|
1002 | | - err = crypto_register_template(&crypto_cbcmac_tmpl); |
---|
1003 | | - if (err) |
---|
1004 | | - goto out; |
---|
1005 | | - |
---|
1006 | | - err = crypto_register_template(&crypto_ccm_base_tmpl); |
---|
1007 | | - if (err) |
---|
1008 | | - goto out_undo_cbcmac; |
---|
1009 | | - |
---|
1010 | | - err = crypto_register_template(&crypto_ccm_tmpl); |
---|
1011 | | - if (err) |
---|
1012 | | - goto out_undo_base; |
---|
1013 | | - |
---|
1014 | | - err = crypto_register_template(&crypto_rfc4309_tmpl); |
---|
1015 | | - if (err) |
---|
1016 | | - goto out_undo_ccm; |
---|
1017 | | - |
---|
1018 | | -out: |
---|
1019 | | - return err; |
---|
1020 | | - |
---|
1021 | | -out_undo_ccm: |
---|
1022 | | - crypto_unregister_template(&crypto_ccm_tmpl); |
---|
1023 | | -out_undo_base: |
---|
1024 | | - crypto_unregister_template(&crypto_ccm_base_tmpl); |
---|
1025 | | -out_undo_cbcmac: |
---|
1026 | | - crypto_register_template(&crypto_cbcmac_tmpl); |
---|
1027 | | - goto out; |
---|
| 939 | + return crypto_register_templates(crypto_ccm_tmpls, |
---|
| 940 | + ARRAY_SIZE(crypto_ccm_tmpls)); |
---|
1028 | 941 | } |
---|
1029 | 942 | |
---|
1030 | 943 | static void __exit crypto_ccm_module_exit(void) |
---|
1031 | 944 | { |
---|
1032 | | - crypto_unregister_template(&crypto_rfc4309_tmpl); |
---|
1033 | | - crypto_unregister_template(&crypto_ccm_tmpl); |
---|
1034 | | - crypto_unregister_template(&crypto_ccm_base_tmpl); |
---|
1035 | | - crypto_unregister_template(&crypto_cbcmac_tmpl); |
---|
| 945 | + crypto_unregister_templates(crypto_ccm_tmpls, |
---|
| 946 | + ARRAY_SIZE(crypto_ccm_tmpls)); |
---|
1036 | 947 | } |
---|
1037 | 948 | |
---|
1038 | | -module_init(crypto_ccm_module_init); |
---|
| 949 | +subsys_initcall(crypto_ccm_module_init); |
---|
1039 | 950 | module_exit(crypto_ccm_module_exit); |
---|
1040 | 951 | |
---|
1041 | 952 | MODULE_LICENSE("GPL"); |
---|
.. | .. |
---|
1043 | 954 | MODULE_ALIAS_CRYPTO("ccm_base"); |
---|
1044 | 955 | MODULE_ALIAS_CRYPTO("rfc4309"); |
---|
1045 | 956 | MODULE_ALIAS_CRYPTO("ccm"); |
---|
| 957 | +MODULE_ALIAS_CRYPTO("cbcmac"); |
---|
| 958 | +MODULE_IMPORT_NS(CRYPTO_INTERNAL); |
---|