diff options
Diffstat (limited to 'arch/x86/crypto/serpent_sse2_glue.c')
-rw-r--r-- | arch/x86/crypto/serpent_sse2_glue.c | 394 |
1 files changed, 134 insertions, 260 deletions
diff --git a/arch/x86/crypto/serpent_sse2_glue.c b/arch/x86/crypto/serpent_sse2_glue.c index 7955a9b76b91..4b21be85e0a1 100644 --- a/arch/x86/crypto/serpent_sse2_glue.c +++ b/arch/x86/crypto/serpent_sse2_glue.c | |||
@@ -145,28 +145,6 @@ static int ecb_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | |||
145 | return ecb_crypt(desc, &walk, false); | 145 | return ecb_crypt(desc, &walk, false); |
146 | } | 146 | } |
147 | 147 | ||
148 | static struct crypto_alg blk_ecb_alg = { | ||
149 | .cra_name = "__ecb-serpent-sse2", | ||
150 | .cra_driver_name = "__driver-ecb-serpent-sse2", | ||
151 | .cra_priority = 0, | ||
152 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
153 | .cra_blocksize = SERPENT_BLOCK_SIZE, | ||
154 | .cra_ctxsize = sizeof(struct serpent_ctx), | ||
155 | .cra_alignmask = 0, | ||
156 | .cra_type = &crypto_blkcipher_type, | ||
157 | .cra_module = THIS_MODULE, | ||
158 | .cra_list = LIST_HEAD_INIT(blk_ecb_alg.cra_list), | ||
159 | .cra_u = { | ||
160 | .blkcipher = { | ||
161 | .min_keysize = SERPENT_MIN_KEY_SIZE, | ||
162 | .max_keysize = SERPENT_MAX_KEY_SIZE, | ||
163 | .setkey = serpent_setkey, | ||
164 | .encrypt = ecb_encrypt, | ||
165 | .decrypt = ecb_decrypt, | ||
166 | }, | ||
167 | }, | ||
168 | }; | ||
169 | |||
170 | static unsigned int __cbc_encrypt(struct blkcipher_desc *desc, | 148 | static unsigned int __cbc_encrypt(struct blkcipher_desc *desc, |
171 | struct blkcipher_walk *walk) | 149 | struct blkcipher_walk *walk) |
172 | { | 150 | { |
@@ -295,28 +273,6 @@ static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | |||
295 | return err; | 273 | return err; |
296 | } | 274 | } |
297 | 275 | ||
298 | static struct crypto_alg blk_cbc_alg = { | ||
299 | .cra_name = "__cbc-serpent-sse2", | ||
300 | .cra_driver_name = "__driver-cbc-serpent-sse2", | ||
301 | .cra_priority = 0, | ||
302 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
303 | .cra_blocksize = SERPENT_BLOCK_SIZE, | ||
304 | .cra_ctxsize = sizeof(struct serpent_ctx), | ||
305 | .cra_alignmask = 0, | ||
306 | .cra_type = &crypto_blkcipher_type, | ||
307 | .cra_module = THIS_MODULE, | ||
308 | .cra_list = LIST_HEAD_INIT(blk_cbc_alg.cra_list), | ||
309 | .cra_u = { | ||
310 | .blkcipher = { | ||
311 | .min_keysize = SERPENT_MIN_KEY_SIZE, | ||
312 | .max_keysize = SERPENT_MAX_KEY_SIZE, | ||
313 | .setkey = serpent_setkey, | ||
314 | .encrypt = cbc_encrypt, | ||
315 | .decrypt = cbc_decrypt, | ||
316 | }, | ||
317 | }, | ||
318 | }; | ||
319 | |||
320 | static inline void u128_to_be128(be128 *dst, const u128 *src) | 276 | static inline void u128_to_be128(be128 *dst, const u128 *src) |
321 | { | 277 | { |
322 | dst->a = cpu_to_be64(src->a); | 278 | dst->a = cpu_to_be64(src->a); |
@@ -439,29 +395,6 @@ static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, | |||
439 | return err; | 395 | return err; |
440 | } | 396 | } |
441 | 397 | ||
442 | static struct crypto_alg blk_ctr_alg = { | ||
443 | .cra_name = "__ctr-serpent-sse2", | ||
444 | .cra_driver_name = "__driver-ctr-serpent-sse2", | ||
445 | .cra_priority = 0, | ||
446 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
447 | .cra_blocksize = 1, | ||
448 | .cra_ctxsize = sizeof(struct serpent_ctx), | ||
449 | .cra_alignmask = 0, | ||
450 | .cra_type = &crypto_blkcipher_type, | ||
451 | .cra_module = THIS_MODULE, | ||
452 | .cra_list = LIST_HEAD_INIT(blk_ctr_alg.cra_list), | ||
453 | .cra_u = { | ||
454 | .blkcipher = { | ||
455 | .min_keysize = SERPENT_MIN_KEY_SIZE, | ||
456 | .max_keysize = SERPENT_MAX_KEY_SIZE, | ||
457 | .ivsize = SERPENT_BLOCK_SIZE, | ||
458 | .setkey = serpent_setkey, | ||
459 | .encrypt = ctr_crypt, | ||
460 | .decrypt = ctr_crypt, | ||
461 | }, | ||
462 | }, | ||
463 | }; | ||
464 | |||
465 | struct crypt_priv { | 398 | struct crypt_priv { |
466 | struct serpent_ctx *ctx; | 399 | struct serpent_ctx *ctx; |
467 | bool fpu_enabled; | 400 | bool fpu_enabled; |
@@ -580,32 +513,6 @@ static void lrw_exit_tfm(struct crypto_tfm *tfm) | |||
580 | lrw_free_table(&ctx->lrw_table); | 513 | lrw_free_table(&ctx->lrw_table); |
581 | } | 514 | } |
582 | 515 | ||
583 | static struct crypto_alg blk_lrw_alg = { | ||
584 | .cra_name = "__lrw-serpent-sse2", | ||
585 | .cra_driver_name = "__driver-lrw-serpent-sse2", | ||
586 | .cra_priority = 0, | ||
587 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
588 | .cra_blocksize = SERPENT_BLOCK_SIZE, | ||
589 | .cra_ctxsize = sizeof(struct serpent_lrw_ctx), | ||
590 | .cra_alignmask = 0, | ||
591 | .cra_type = &crypto_blkcipher_type, | ||
592 | .cra_module = THIS_MODULE, | ||
593 | .cra_list = LIST_HEAD_INIT(blk_lrw_alg.cra_list), | ||
594 | .cra_exit = lrw_exit_tfm, | ||
595 | .cra_u = { | ||
596 | .blkcipher = { | ||
597 | .min_keysize = SERPENT_MIN_KEY_SIZE + | ||
598 | SERPENT_BLOCK_SIZE, | ||
599 | .max_keysize = SERPENT_MAX_KEY_SIZE + | ||
600 | SERPENT_BLOCK_SIZE, | ||
601 | .ivsize = SERPENT_BLOCK_SIZE, | ||
602 | .setkey = lrw_serpent_setkey, | ||
603 | .encrypt = lrw_encrypt, | ||
604 | .decrypt = lrw_decrypt, | ||
605 | }, | ||
606 | }, | ||
607 | }; | ||
608 | |||
609 | struct serpent_xts_ctx { | 516 | struct serpent_xts_ctx { |
610 | struct serpent_ctx tweak_ctx; | 517 | struct serpent_ctx tweak_ctx; |
611 | struct serpent_ctx crypt_ctx; | 518 | struct serpent_ctx crypt_ctx; |
@@ -689,29 +596,6 @@ static int xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | |||
689 | return ret; | 596 | return ret; |
690 | } | 597 | } |
691 | 598 | ||
692 | static struct crypto_alg blk_xts_alg = { | ||
693 | .cra_name = "__xts-serpent-sse2", | ||
694 | .cra_driver_name = "__driver-xts-serpent-sse2", | ||
695 | .cra_priority = 0, | ||
696 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
697 | .cra_blocksize = SERPENT_BLOCK_SIZE, | ||
698 | .cra_ctxsize = sizeof(struct serpent_xts_ctx), | ||
699 | .cra_alignmask = 0, | ||
700 | .cra_type = &crypto_blkcipher_type, | ||
701 | .cra_module = THIS_MODULE, | ||
702 | .cra_list = LIST_HEAD_INIT(blk_xts_alg.cra_list), | ||
703 | .cra_u = { | ||
704 | .blkcipher = { | ||
705 | .min_keysize = SERPENT_MIN_KEY_SIZE * 2, | ||
706 | .max_keysize = SERPENT_MAX_KEY_SIZE * 2, | ||
707 | .ivsize = SERPENT_BLOCK_SIZE, | ||
708 | .setkey = xts_serpent_setkey, | ||
709 | .encrypt = xts_encrypt, | ||
710 | .decrypt = xts_decrypt, | ||
711 | }, | ||
712 | }, | ||
713 | }; | ||
714 | |||
715 | static int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key, | 599 | static int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key, |
716 | unsigned int key_len) | 600 | unsigned int key_len) |
717 | { | 601 | { |
@@ -792,28 +676,133 @@ static void ablk_exit(struct crypto_tfm *tfm) | |||
792 | cryptd_free_ablkcipher(ctx->cryptd_tfm); | 676 | cryptd_free_ablkcipher(ctx->cryptd_tfm); |
793 | } | 677 | } |
794 | 678 | ||
795 | static void ablk_init_common(struct crypto_tfm *tfm, | 679 | static int ablk_init(struct crypto_tfm *tfm) |
796 | struct cryptd_ablkcipher *cryptd_tfm) | ||
797 | { | 680 | { |
798 | struct async_serpent_ctx *ctx = crypto_tfm_ctx(tfm); | 681 | struct async_serpent_ctx *ctx = crypto_tfm_ctx(tfm); |
682 | struct cryptd_ablkcipher *cryptd_tfm; | ||
683 | char drv_name[CRYPTO_MAX_ALG_NAME]; | ||
684 | |||
685 | snprintf(drv_name, sizeof(drv_name), "__driver-%s", | ||
686 | crypto_tfm_alg_driver_name(tfm)); | ||
687 | |||
688 | cryptd_tfm = cryptd_alloc_ablkcipher(drv_name, 0, 0); | ||
689 | if (IS_ERR(cryptd_tfm)) | ||
690 | return PTR_ERR(cryptd_tfm); | ||
799 | 691 | ||
800 | ctx->cryptd_tfm = cryptd_tfm; | 692 | ctx->cryptd_tfm = cryptd_tfm; |
801 | tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) + | 693 | tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) + |
802 | crypto_ablkcipher_reqsize(&cryptd_tfm->base); | 694 | crypto_ablkcipher_reqsize(&cryptd_tfm->base); |
803 | } | ||
804 | |||
805 | static int ablk_ecb_init(struct crypto_tfm *tfm) | ||
806 | { | ||
807 | struct cryptd_ablkcipher *cryptd_tfm; | ||
808 | 695 | ||
809 | cryptd_tfm = cryptd_alloc_ablkcipher("__driver-ecb-serpent-sse2", 0, 0); | ||
810 | if (IS_ERR(cryptd_tfm)) | ||
811 | return PTR_ERR(cryptd_tfm); | ||
812 | ablk_init_common(tfm, cryptd_tfm); | ||
813 | return 0; | 696 | return 0; |
814 | } | 697 | } |
815 | 698 | ||
816 | static struct crypto_alg ablk_ecb_alg = { | 699 | static struct crypto_alg serpent_algs[10] = { { |
700 | .cra_name = "__ecb-serpent-sse2", | ||
701 | .cra_driver_name = "__driver-ecb-serpent-sse2", | ||
702 | .cra_priority = 0, | ||
703 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
704 | .cra_blocksize = SERPENT_BLOCK_SIZE, | ||
705 | .cra_ctxsize = sizeof(struct serpent_ctx), | ||
706 | .cra_alignmask = 0, | ||
707 | .cra_type = &crypto_blkcipher_type, | ||
708 | .cra_module = THIS_MODULE, | ||
709 | .cra_list = LIST_HEAD_INIT(serpent_algs[0].cra_list), | ||
710 | .cra_u = { | ||
711 | .blkcipher = { | ||
712 | .min_keysize = SERPENT_MIN_KEY_SIZE, | ||
713 | .max_keysize = SERPENT_MAX_KEY_SIZE, | ||
714 | .setkey = serpent_setkey, | ||
715 | .encrypt = ecb_encrypt, | ||
716 | .decrypt = ecb_decrypt, | ||
717 | }, | ||
718 | }, | ||
719 | }, { | ||
720 | .cra_name = "__cbc-serpent-sse2", | ||
721 | .cra_driver_name = "__driver-cbc-serpent-sse2", | ||
722 | .cra_priority = 0, | ||
723 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
724 | .cra_blocksize = SERPENT_BLOCK_SIZE, | ||
725 | .cra_ctxsize = sizeof(struct serpent_ctx), | ||
726 | .cra_alignmask = 0, | ||
727 | .cra_type = &crypto_blkcipher_type, | ||
728 | .cra_module = THIS_MODULE, | ||
729 | .cra_list = LIST_HEAD_INIT(serpent_algs[1].cra_list), | ||
730 | .cra_u = { | ||
731 | .blkcipher = { | ||
732 | .min_keysize = SERPENT_MIN_KEY_SIZE, | ||
733 | .max_keysize = SERPENT_MAX_KEY_SIZE, | ||
734 | .setkey = serpent_setkey, | ||
735 | .encrypt = cbc_encrypt, | ||
736 | .decrypt = cbc_decrypt, | ||
737 | }, | ||
738 | }, | ||
739 | }, { | ||
740 | .cra_name = "__ctr-serpent-sse2", | ||
741 | .cra_driver_name = "__driver-ctr-serpent-sse2", | ||
742 | .cra_priority = 0, | ||
743 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
744 | .cra_blocksize = 1, | ||
745 | .cra_ctxsize = sizeof(struct serpent_ctx), | ||
746 | .cra_alignmask = 0, | ||
747 | .cra_type = &crypto_blkcipher_type, | ||
748 | .cra_module = THIS_MODULE, | ||
749 | .cra_list = LIST_HEAD_INIT(serpent_algs[2].cra_list), | ||
750 | .cra_u = { | ||
751 | .blkcipher = { | ||
752 | .min_keysize = SERPENT_MIN_KEY_SIZE, | ||
753 | .max_keysize = SERPENT_MAX_KEY_SIZE, | ||
754 | .ivsize = SERPENT_BLOCK_SIZE, | ||
755 | .setkey = serpent_setkey, | ||
756 | .encrypt = ctr_crypt, | ||
757 | .decrypt = ctr_crypt, | ||
758 | }, | ||
759 | }, | ||
760 | }, { | ||
761 | .cra_name = "__lrw-serpent-sse2", | ||
762 | .cra_driver_name = "__driver-lrw-serpent-sse2", | ||
763 | .cra_priority = 0, | ||
764 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
765 | .cra_blocksize = SERPENT_BLOCK_SIZE, | ||
766 | .cra_ctxsize = sizeof(struct serpent_lrw_ctx), | ||
767 | .cra_alignmask = 0, | ||
768 | .cra_type = &crypto_blkcipher_type, | ||
769 | .cra_module = THIS_MODULE, | ||
770 | .cra_list = LIST_HEAD_INIT(serpent_algs[3].cra_list), | ||
771 | .cra_exit = lrw_exit_tfm, | ||
772 | .cra_u = { | ||
773 | .blkcipher = { | ||
774 | .min_keysize = SERPENT_MIN_KEY_SIZE + | ||
775 | SERPENT_BLOCK_SIZE, | ||
776 | .max_keysize = SERPENT_MAX_KEY_SIZE + | ||
777 | SERPENT_BLOCK_SIZE, | ||
778 | .ivsize = SERPENT_BLOCK_SIZE, | ||
779 | .setkey = lrw_serpent_setkey, | ||
780 | .encrypt = lrw_encrypt, | ||
781 | .decrypt = lrw_decrypt, | ||
782 | }, | ||
783 | }, | ||
784 | }, { | ||
785 | .cra_name = "__xts-serpent-sse2", | ||
786 | .cra_driver_name = "__driver-xts-serpent-sse2", | ||
787 | .cra_priority = 0, | ||
788 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
789 | .cra_blocksize = SERPENT_BLOCK_SIZE, | ||
790 | .cra_ctxsize = sizeof(struct serpent_xts_ctx), | ||
791 | .cra_alignmask = 0, | ||
792 | .cra_type = &crypto_blkcipher_type, | ||
793 | .cra_module = THIS_MODULE, | ||
794 | .cra_list = LIST_HEAD_INIT(serpent_algs[4].cra_list), | ||
795 | .cra_u = { | ||
796 | .blkcipher = { | ||
797 | .min_keysize = SERPENT_MIN_KEY_SIZE * 2, | ||
798 | .max_keysize = SERPENT_MAX_KEY_SIZE * 2, | ||
799 | .ivsize = SERPENT_BLOCK_SIZE, | ||
800 | .setkey = xts_serpent_setkey, | ||
801 | .encrypt = xts_encrypt, | ||
802 | .decrypt = xts_decrypt, | ||
803 | }, | ||
804 | }, | ||
805 | }, { | ||
817 | .cra_name = "ecb(serpent)", | 806 | .cra_name = "ecb(serpent)", |
818 | .cra_driver_name = "ecb-serpent-sse2", | 807 | .cra_driver_name = "ecb-serpent-sse2", |
819 | .cra_priority = 400, | 808 | .cra_priority = 400, |
@@ -823,8 +812,8 @@ static struct crypto_alg ablk_ecb_alg = { | |||
823 | .cra_alignmask = 0, | 812 | .cra_alignmask = 0, |
824 | .cra_type = &crypto_ablkcipher_type, | 813 | .cra_type = &crypto_ablkcipher_type, |
825 | .cra_module = THIS_MODULE, | 814 | .cra_module = THIS_MODULE, |
826 | .cra_list = LIST_HEAD_INIT(ablk_ecb_alg.cra_list), | 815 | .cra_list = LIST_HEAD_INIT(serpent_algs[5].cra_list), |
827 | .cra_init = ablk_ecb_init, | 816 | .cra_init = ablk_init, |
828 | .cra_exit = ablk_exit, | 817 | .cra_exit = ablk_exit, |
829 | .cra_u = { | 818 | .cra_u = { |
830 | .ablkcipher = { | 819 | .ablkcipher = { |
@@ -835,20 +824,7 @@ static struct crypto_alg ablk_ecb_alg = { | |||
835 | .decrypt = ablk_decrypt, | 824 | .decrypt = ablk_decrypt, |
836 | }, | 825 | }, |
837 | }, | 826 | }, |
838 | }; | 827 | }, { |
839 | |||
840 | static int ablk_cbc_init(struct crypto_tfm *tfm) | ||
841 | { | ||
842 | struct cryptd_ablkcipher *cryptd_tfm; | ||
843 | |||
844 | cryptd_tfm = cryptd_alloc_ablkcipher("__driver-cbc-serpent-sse2", 0, 0); | ||
845 | if (IS_ERR(cryptd_tfm)) | ||
846 | return PTR_ERR(cryptd_tfm); | ||
847 | ablk_init_common(tfm, cryptd_tfm); | ||
848 | return 0; | ||
849 | } | ||
850 | |||
851 | static struct crypto_alg ablk_cbc_alg = { | ||
852 | .cra_name = "cbc(serpent)", | 828 | .cra_name = "cbc(serpent)", |
853 | .cra_driver_name = "cbc-serpent-sse2", | 829 | .cra_driver_name = "cbc-serpent-sse2", |
854 | .cra_priority = 400, | 830 | .cra_priority = 400, |
@@ -858,8 +834,8 @@ static struct crypto_alg ablk_cbc_alg = { | |||
858 | .cra_alignmask = 0, | 834 | .cra_alignmask = 0, |
859 | .cra_type = &crypto_ablkcipher_type, | 835 | .cra_type = &crypto_ablkcipher_type, |
860 | .cra_module = THIS_MODULE, | 836 | .cra_module = THIS_MODULE, |
861 | .cra_list = LIST_HEAD_INIT(ablk_cbc_alg.cra_list), | 837 | .cra_list = LIST_HEAD_INIT(serpent_algs[6].cra_list), |
862 | .cra_init = ablk_cbc_init, | 838 | .cra_init = ablk_init, |
863 | .cra_exit = ablk_exit, | 839 | .cra_exit = ablk_exit, |
864 | .cra_u = { | 840 | .cra_u = { |
865 | .ablkcipher = { | 841 | .ablkcipher = { |
@@ -871,20 +847,7 @@ static struct crypto_alg ablk_cbc_alg = { | |||
871 | .decrypt = ablk_decrypt, | 847 | .decrypt = ablk_decrypt, |
872 | }, | 848 | }, |
873 | }, | 849 | }, |
874 | }; | 850 | }, { |
875 | |||
876 | static int ablk_ctr_init(struct crypto_tfm *tfm) | ||
877 | { | ||
878 | struct cryptd_ablkcipher *cryptd_tfm; | ||
879 | |||
880 | cryptd_tfm = cryptd_alloc_ablkcipher("__driver-ctr-serpent-sse2", 0, 0); | ||
881 | if (IS_ERR(cryptd_tfm)) | ||
882 | return PTR_ERR(cryptd_tfm); | ||
883 | ablk_init_common(tfm, cryptd_tfm); | ||
884 | return 0; | ||
885 | } | ||
886 | |||
887 | static struct crypto_alg ablk_ctr_alg = { | ||
888 | .cra_name = "ctr(serpent)", | 851 | .cra_name = "ctr(serpent)", |
889 | .cra_driver_name = "ctr-serpent-sse2", | 852 | .cra_driver_name = "ctr-serpent-sse2", |
890 | .cra_priority = 400, | 853 | .cra_priority = 400, |
@@ -894,8 +857,8 @@ static struct crypto_alg ablk_ctr_alg = { | |||
894 | .cra_alignmask = 0, | 857 | .cra_alignmask = 0, |
895 | .cra_type = &crypto_ablkcipher_type, | 858 | .cra_type = &crypto_ablkcipher_type, |
896 | .cra_module = THIS_MODULE, | 859 | .cra_module = THIS_MODULE, |
897 | .cra_list = LIST_HEAD_INIT(ablk_ctr_alg.cra_list), | 860 | .cra_list = LIST_HEAD_INIT(serpent_algs[7].cra_list), |
898 | .cra_init = ablk_ctr_init, | 861 | .cra_init = ablk_init, |
899 | .cra_exit = ablk_exit, | 862 | .cra_exit = ablk_exit, |
900 | .cra_u = { | 863 | .cra_u = { |
901 | .ablkcipher = { | 864 | .ablkcipher = { |
@@ -908,20 +871,7 @@ static struct crypto_alg ablk_ctr_alg = { | |||
908 | .geniv = "chainiv", | 871 | .geniv = "chainiv", |
909 | }, | 872 | }, |
910 | }, | 873 | }, |
911 | }; | 874 | }, { |
912 | |||
913 | static int ablk_lrw_init(struct crypto_tfm *tfm) | ||
914 | { | ||
915 | struct cryptd_ablkcipher *cryptd_tfm; | ||
916 | |||
917 | cryptd_tfm = cryptd_alloc_ablkcipher("__driver-lrw-serpent-sse2", 0, 0); | ||
918 | if (IS_ERR(cryptd_tfm)) | ||
919 | return PTR_ERR(cryptd_tfm); | ||
920 | ablk_init_common(tfm, cryptd_tfm); | ||
921 | return 0; | ||
922 | } | ||
923 | |||
924 | static struct crypto_alg ablk_lrw_alg = { | ||
925 | .cra_name = "lrw(serpent)", | 875 | .cra_name = "lrw(serpent)", |
926 | .cra_driver_name = "lrw-serpent-sse2", | 876 | .cra_driver_name = "lrw-serpent-sse2", |
927 | .cra_priority = 400, | 877 | .cra_priority = 400, |
@@ -931,8 +881,8 @@ static struct crypto_alg ablk_lrw_alg = { | |||
931 | .cra_alignmask = 0, | 881 | .cra_alignmask = 0, |
932 | .cra_type = &crypto_ablkcipher_type, | 882 | .cra_type = &crypto_ablkcipher_type, |
933 | .cra_module = THIS_MODULE, | 883 | .cra_module = THIS_MODULE, |
934 | .cra_list = LIST_HEAD_INIT(ablk_lrw_alg.cra_list), | 884 | .cra_list = LIST_HEAD_INIT(serpent_algs[8].cra_list), |
935 | .cra_init = ablk_lrw_init, | 885 | .cra_init = ablk_init, |
936 | .cra_exit = ablk_exit, | 886 | .cra_exit = ablk_exit, |
937 | .cra_u = { | 887 | .cra_u = { |
938 | .ablkcipher = { | 888 | .ablkcipher = { |
@@ -946,20 +896,7 @@ static struct crypto_alg ablk_lrw_alg = { | |||
946 | .decrypt = ablk_decrypt, | 896 | .decrypt = ablk_decrypt, |
947 | }, | 897 | }, |
948 | }, | 898 | }, |
949 | }; | 899 | }, { |
950 | |||
951 | static int ablk_xts_init(struct crypto_tfm *tfm) | ||
952 | { | ||
953 | struct cryptd_ablkcipher *cryptd_tfm; | ||
954 | |||
955 | cryptd_tfm = cryptd_alloc_ablkcipher("__driver-xts-serpent-sse2", 0, 0); | ||
956 | if (IS_ERR(cryptd_tfm)) | ||
957 | return PTR_ERR(cryptd_tfm); | ||
958 | ablk_init_common(tfm, cryptd_tfm); | ||
959 | return 0; | ||
960 | } | ||
961 | |||
962 | static struct crypto_alg ablk_xts_alg = { | ||
963 | .cra_name = "xts(serpent)", | 900 | .cra_name = "xts(serpent)", |
964 | .cra_driver_name = "xts-serpent-sse2", | 901 | .cra_driver_name = "xts-serpent-sse2", |
965 | .cra_priority = 400, | 902 | .cra_priority = 400, |
@@ -969,8 +906,8 @@ static struct crypto_alg ablk_xts_alg = { | |||
969 | .cra_alignmask = 0, | 906 | .cra_alignmask = 0, |
970 | .cra_type = &crypto_ablkcipher_type, | 907 | .cra_type = &crypto_ablkcipher_type, |
971 | .cra_module = THIS_MODULE, | 908 | .cra_module = THIS_MODULE, |
972 | .cra_list = LIST_HEAD_INIT(ablk_xts_alg.cra_list), | 909 | .cra_list = LIST_HEAD_INIT(serpent_algs[9].cra_list), |
973 | .cra_init = ablk_xts_init, | 910 | .cra_init = ablk_init, |
974 | .cra_exit = ablk_exit, | 911 | .cra_exit = ablk_exit, |
975 | .cra_u = { | 912 | .cra_u = { |
976 | .ablkcipher = { | 913 | .ablkcipher = { |
@@ -982,84 +919,21 @@ static struct crypto_alg ablk_xts_alg = { | |||
982 | .decrypt = ablk_decrypt, | 919 | .decrypt = ablk_decrypt, |
983 | }, | 920 | }, |
984 | }, | 921 | }, |
985 | }; | 922 | } }; |
986 | 923 | ||
987 | static int __init serpent_sse2_init(void) | 924 | static int __init serpent_sse2_init(void) |
988 | { | 925 | { |
989 | int err; | ||
990 | |||
991 | if (!cpu_has_xmm2) { | 926 | if (!cpu_has_xmm2) { |
992 | printk(KERN_INFO "SSE2 instructions are not detected.\n"); | 927 | printk(KERN_INFO "SSE2 instructions are not detected.\n"); |
993 | return -ENODEV; | 928 | return -ENODEV; |
994 | } | 929 | } |
995 | 930 | ||
996 | err = crypto_register_alg(&blk_ecb_alg); | 931 | return crypto_register_algs(serpent_algs, ARRAY_SIZE(serpent_algs)); |
997 | if (err) | ||
998 | goto blk_ecb_err; | ||
999 | err = crypto_register_alg(&blk_cbc_alg); | ||
1000 | if (err) | ||
1001 | goto blk_cbc_err; | ||
1002 | err = crypto_register_alg(&blk_ctr_alg); | ||
1003 | if (err) | ||
1004 | goto blk_ctr_err; | ||
1005 | err = crypto_register_alg(&ablk_ecb_alg); | ||
1006 | if (err) | ||
1007 | goto ablk_ecb_err; | ||
1008 | err = crypto_register_alg(&ablk_cbc_alg); | ||
1009 | if (err) | ||
1010 | goto ablk_cbc_err; | ||
1011 | err = crypto_register_alg(&ablk_ctr_alg); | ||
1012 | if (err) | ||
1013 | goto ablk_ctr_err; | ||
1014 | err = crypto_register_alg(&blk_lrw_alg); | ||
1015 | if (err) | ||
1016 | goto blk_lrw_err; | ||
1017 | err = crypto_register_alg(&ablk_lrw_alg); | ||
1018 | if (err) | ||
1019 | goto ablk_lrw_err; | ||
1020 | err = crypto_register_alg(&blk_xts_alg); | ||
1021 | if (err) | ||
1022 | goto blk_xts_err; | ||
1023 | err = crypto_register_alg(&ablk_xts_alg); | ||
1024 | if (err) | ||
1025 | goto ablk_xts_err; | ||
1026 | return err; | ||
1027 | |||
1028 | crypto_unregister_alg(&ablk_xts_alg); | ||
1029 | ablk_xts_err: | ||
1030 | crypto_unregister_alg(&blk_xts_alg); | ||
1031 | blk_xts_err: | ||
1032 | crypto_unregister_alg(&ablk_lrw_alg); | ||
1033 | ablk_lrw_err: | ||
1034 | crypto_unregister_alg(&blk_lrw_alg); | ||
1035 | blk_lrw_err: | ||
1036 | crypto_unregister_alg(&ablk_ctr_alg); | ||
1037 | ablk_ctr_err: | ||
1038 | crypto_unregister_alg(&ablk_cbc_alg); | ||
1039 | ablk_cbc_err: | ||
1040 | crypto_unregister_alg(&ablk_ecb_alg); | ||
1041 | ablk_ecb_err: | ||
1042 | crypto_unregister_alg(&blk_ctr_alg); | ||
1043 | blk_ctr_err: | ||
1044 | crypto_unregister_alg(&blk_cbc_alg); | ||
1045 | blk_cbc_err: | ||
1046 | crypto_unregister_alg(&blk_ecb_alg); | ||
1047 | blk_ecb_err: | ||
1048 | return err; | ||
1049 | } | 932 | } |
1050 | 933 | ||
1051 | static void __exit serpent_sse2_exit(void) | 934 | static void __exit serpent_sse2_exit(void) |
1052 | { | 935 | { |
1053 | crypto_unregister_alg(&ablk_xts_alg); | 936 | crypto_unregister_algs(serpent_algs, ARRAY_SIZE(serpent_algs)); |
1054 | crypto_unregister_alg(&blk_xts_alg); | ||
1055 | crypto_unregister_alg(&ablk_lrw_alg); | ||
1056 | crypto_unregister_alg(&blk_lrw_alg); | ||
1057 | crypto_unregister_alg(&ablk_ctr_alg); | ||
1058 | crypto_unregister_alg(&ablk_cbc_alg); | ||
1059 | crypto_unregister_alg(&ablk_ecb_alg); | ||
1060 | crypto_unregister_alg(&blk_ctr_alg); | ||
1061 | crypto_unregister_alg(&blk_cbc_alg); | ||
1062 | crypto_unregister_alg(&blk_ecb_alg); | ||
1063 | } | 937 | } |
1064 | 938 | ||
1065 | module_init(serpent_sse2_init); | 939 | module_init(serpent_sse2_init); |