diff options
-rw-r--r-- | crypto/tcrypt.c | 2 | ||||
-rw-r--r-- | crypto/testmgr.c | 6 | ||||
-rw-r--r-- | crypto/testmgr.h | 102 | ||||
-rw-r--r-- | crypto/vmac.c | 84 |
4 files changed, 8 insertions, 186 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index d5bcdd905007..078ec36007bf 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -1939,7 +1939,7 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) | |||
1939 | break; | 1939 | break; |
1940 | 1940 | ||
1941 | case 109: | 1941 | case 109: |
1942 | ret += tcrypt_test("vmac(aes)"); | 1942 | ret += tcrypt_test("vmac64(aes)"); |
1943 | break; | 1943 | break; |
1944 | 1944 | ||
1945 | case 111: | 1945 | case 111: |
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 60a557b0f8d3..63f263fd1dae 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
@@ -3478,12 +3478,6 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
3478 | .hash = __VECS(tgr192_tv_template) | 3478 | .hash = __VECS(tgr192_tv_template) |
3479 | } | 3479 | } |
3480 | }, { | 3480 | }, { |
3481 | .alg = "vmac(aes)", | ||
3482 | .test = alg_test_hash, | ||
3483 | .suite = { | ||
3484 | .hash = __VECS(aes_vmac128_tv_template) | ||
3485 | } | ||
3486 | }, { | ||
3487 | .alg = "vmac64(aes)", | 3481 | .alg = "vmac64(aes)", |
3488 | .test = alg_test_hash, | 3482 | .test = alg_test_hash, |
3489 | .suite = { | 3483 | .suite = { |
diff --git a/crypto/testmgr.h b/crypto/testmgr.h index 7b022c47a623..b6362169771a 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h | |||
@@ -4603,108 +4603,6 @@ static const struct hash_testvec aes_xcbc128_tv_template[] = { | |||
4603 | } | 4603 | } |
4604 | }; | 4604 | }; |
4605 | 4605 | ||
4606 | static const char vmac_string1[128] = {'\x01', '\x01', '\x01', '\x01', | ||
4607 | '\x02', '\x03', '\x02', '\x02', | ||
4608 | '\x02', '\x04', '\x01', '\x07', | ||
4609 | '\x04', '\x01', '\x04', '\x03',}; | ||
4610 | static const char vmac_string2[128] = {'a', 'b', 'c',}; | ||
4611 | static const char vmac_string3[128] = {'a', 'b', 'c', 'a', 'b', 'c', | ||
4612 | 'a', 'b', 'c', 'a', 'b', 'c', | ||
4613 | 'a', 'b', 'c', 'a', 'b', 'c', | ||
4614 | 'a', 'b', 'c', 'a', 'b', 'c', | ||
4615 | 'a', 'b', 'c', 'a', 'b', 'c', | ||
4616 | 'a', 'b', 'c', 'a', 'b', 'c', | ||
4617 | 'a', 'b', 'c', 'a', 'b', 'c', | ||
4618 | 'a', 'b', 'c', 'a', 'b', 'c', | ||
4619 | }; | ||
4620 | |||
4621 | static const char vmac_string4[17] = {'b', 'c', 'e', 'f', | ||
4622 | 'i', 'j', 'l', 'm', | ||
4623 | 'o', 'p', 'r', 's', | ||
4624 | 't', 'u', 'w', 'x', 'z'}; | ||
4625 | |||
4626 | static const char vmac_string5[127] = {'r', 'm', 'b', 't', 'c', | ||
4627 | 'o', 'l', 'k', ']', '%', | ||
4628 | '9', '2', '7', '!', 'A'}; | ||
4629 | |||
4630 | static const char vmac_string6[129] = {'p', 't', '*', '7', 'l', | ||
4631 | 'i', '!', '#', 'w', '0', | ||
4632 | 'z', '/', '4', 'A', 'n'}; | ||
4633 | |||
4634 | static const struct hash_testvec aes_vmac128_tv_template[] = { | ||
4635 | { | ||
4636 | .key = "\x00\x01\x02\x03\x04\x05\x06\x07" | ||
4637 | "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", | ||
4638 | .plaintext = NULL, | ||
4639 | .digest = "\x07\x58\x80\x35\x77\xa4\x7b\x54", | ||
4640 | .psize = 0, | ||
4641 | .ksize = 16, | ||
4642 | }, { | ||
4643 | .key = "\x00\x01\x02\x03\x04\x05\x06\x07" | ||
4644 | "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", | ||
4645 | .plaintext = vmac_string1, | ||
4646 | .digest = "\xce\xf5\x3c\xd3\xae\x68\x8c\xa1", | ||
4647 | .psize = 128, | ||
4648 | .ksize = 16, | ||
4649 | }, { | ||
4650 | .key = "\x00\x01\x02\x03\x04\x05\x06\x07" | ||
4651 | "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", | ||
4652 | .plaintext = vmac_string2, | ||
4653 | .digest = "\xc9\x27\xb0\x73\x81\xbd\x14\x2d", | ||
4654 | .psize = 128, | ||
4655 | .ksize = 16, | ||
4656 | }, { | ||
4657 | .key = "\x00\x01\x02\x03\x04\x05\x06\x07" | ||
4658 | "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", | ||
4659 | .plaintext = vmac_string3, | ||
4660 | .digest = "\x8d\x1a\x95\x8c\x98\x47\x0b\x19", | ||
4661 | .psize = 128, | ||
4662 | .ksize = 16, | ||
4663 | }, { | ||
4664 | .key = "abcdefghijklmnop", | ||
4665 | .plaintext = NULL, | ||
4666 | .digest = "\x3b\x89\xa1\x26\x9e\x55\x8f\x84", | ||
4667 | .psize = 0, | ||
4668 | .ksize = 16, | ||
4669 | }, { | ||
4670 | .key = "abcdefghijklmnop", | ||
4671 | .plaintext = vmac_string1, | ||
4672 | .digest = "\xab\x5e\xab\xb0\xf6\x8d\x74\xc2", | ||
4673 | .psize = 128, | ||
4674 | .ksize = 16, | ||
4675 | }, { | ||
4676 | .key = "abcdefghijklmnop", | ||
4677 | .plaintext = vmac_string2, | ||
4678 | .digest = "\x11\x15\x68\x42\x3d\x7b\x09\xdf", | ||
4679 | .psize = 128, | ||
4680 | .ksize = 16, | ||
4681 | }, { | ||
4682 | .key = "abcdefghijklmnop", | ||
4683 | .plaintext = vmac_string3, | ||
4684 | .digest = "\x8b\x32\x8f\xe1\xed\x8f\xfa\xd4", | ||
4685 | .psize = 128, | ||
4686 | .ksize = 16, | ||
4687 | }, { | ||
4688 | .key = "a09b5cd!f#07K\x00\x00\x00", | ||
4689 | .plaintext = vmac_string4, | ||
4690 | .digest = "\xab\xa5\x0f\xea\x42\x4e\xa1\x5f", | ||
4691 | .psize = sizeof(vmac_string4), | ||
4692 | .ksize = 16, | ||
4693 | }, { | ||
4694 | .key = "a09b5cd!f#07K\x00\x00\x00", | ||
4695 | .plaintext = vmac_string5, | ||
4696 | .digest = "\x25\x31\x98\xbc\x1d\xe8\x67\x60", | ||
4697 | .psize = sizeof(vmac_string5), | ||
4698 | .ksize = 16, | ||
4699 | }, { | ||
4700 | .key = "a09b5cd!f#07K\x00\x00\x00", | ||
4701 | .plaintext = vmac_string6, | ||
4702 | .digest = "\xc4\xae\x9b\x47\x95\x65\xeb\x41", | ||
4703 | .psize = sizeof(vmac_string6), | ||
4704 | .ksize = 16, | ||
4705 | }, | ||
4706 | }; | ||
4707 | |||
4708 | static const char vmac64_string1[144] = { | 4606 | static const char vmac64_string1[144] = { |
4709 | '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', | 4607 | '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', |
4710 | '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', | 4608 | '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', |
diff --git a/crypto/vmac.c b/crypto/vmac.c index bf1e385bc684..5f436dfdfc61 100644 --- a/crypto/vmac.c +++ b/crypto/vmac.c | |||
@@ -490,16 +490,6 @@ static int vmac_init(struct shash_desc *desc) | |||
490 | return 0; | 490 | return 0; |
491 | } | 491 | } |
492 | 492 | ||
493 | static int vmac_init_with_hardcoded_nonce(struct shash_desc *desc) | ||
494 | { | ||
495 | struct vmac_desc_ctx *dctx = shash_desc_ctx(desc); | ||
496 | |||
497 | vmac_init(desc); | ||
498 | memset(&dctx->nonce, 0, VMAC_NONCEBYTES); | ||
499 | dctx->nonce_size = VMAC_NONCEBYTES; | ||
500 | return 0; | ||
501 | } | ||
502 | |||
503 | static int vmac_update(struct shash_desc *desc, const u8 *p, unsigned int len) | 493 | static int vmac_update(struct shash_desc *desc, const u8 *p, unsigned int len) |
504 | { | 494 | { |
505 | const struct vmac_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); | 495 | const struct vmac_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); |
@@ -570,7 +560,7 @@ static u64 vhash_final(const struct vmac_tfm_ctx *tctx, | |||
570 | return l3hash(ch, cl, tctx->l3key[0], tctx->l3key[1], partial * 8); | 560 | return l3hash(ch, cl, tctx->l3key[0], tctx->l3key[1], partial * 8); |
571 | } | 561 | } |
572 | 562 | ||
573 | static int __vmac_final(struct shash_desc *desc, u64 *mac) | 563 | static int vmac_final(struct shash_desc *desc, u8 *out) |
574 | { | 564 | { |
575 | const struct vmac_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); | 565 | const struct vmac_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); |
576 | struct vmac_desc_ctx *dctx = shash_desc_ctx(desc); | 566 | struct vmac_desc_ctx *dctx = shash_desc_ctx(desc); |
@@ -601,31 +591,7 @@ static int __vmac_final(struct shash_desc *desc, u64 *mac) | |||
601 | pad = be64_to_cpu(dctx->nonce.pads[index]); | 591 | pad = be64_to_cpu(dctx->nonce.pads[index]); |
602 | 592 | ||
603 | /* The VMAC is the sum of VHASH and the pseudorandom pad */ | 593 | /* The VMAC is the sum of VHASH and the pseudorandom pad */ |
604 | *mac = hash + pad; | 594 | put_unaligned_be64(hash + pad, out); |
605 | return 0; | ||
606 | } | ||
607 | |||
608 | static int vmac_final_le(struct shash_desc *desc, u8 *out) | ||
609 | { | ||
610 | u64 mac; | ||
611 | int err; | ||
612 | |||
613 | err = __vmac_final(desc, &mac); | ||
614 | if (err) | ||
615 | return err; | ||
616 | put_unaligned_le64(mac, out); | ||
617 | return 0; | ||
618 | } | ||
619 | |||
620 | static int vmac_final_be(struct shash_desc *desc, u8 *out) | ||
621 | { | ||
622 | u64 mac; | ||
623 | int err; | ||
624 | |||
625 | err = __vmac_final(desc, &mac); | ||
626 | if (err) | ||
627 | return err; | ||
628 | put_unaligned_be64(mac, out); | ||
629 | return 0; | 595 | return 0; |
630 | } | 596 | } |
631 | 597 | ||
@@ -651,8 +617,7 @@ static void vmac_exit_tfm(struct crypto_tfm *tfm) | |||
651 | crypto_free_cipher(tctx->cipher); | 617 | crypto_free_cipher(tctx->cipher); |
652 | } | 618 | } |
653 | 619 | ||
654 | static int vmac_create_common(struct crypto_template *tmpl, struct rtattr **tb, | 620 | static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb) |
655 | bool vmac64) | ||
656 | { | 621 | { |
657 | struct shash_instance *inst; | 622 | struct shash_instance *inst; |
658 | struct crypto_alg *alg; | 623 | struct crypto_alg *alg; |
@@ -692,15 +657,9 @@ static int vmac_create_common(struct crypto_template *tmpl, struct rtattr **tb, | |||
692 | 657 | ||
693 | inst->alg.descsize = sizeof(struct vmac_desc_ctx); | 658 | inst->alg.descsize = sizeof(struct vmac_desc_ctx); |
694 | inst->alg.digestsize = VMAC_TAG_LEN / 8; | 659 | inst->alg.digestsize = VMAC_TAG_LEN / 8; |
695 | if (vmac64) { | 660 | inst->alg.init = vmac_init; |
696 | inst->alg.init = vmac_init; | ||
697 | inst->alg.final = vmac_final_be; | ||
698 | } else { | ||
699 | pr_warn("vmac: using insecure hardcoded nonce\n"); | ||
700 | inst->alg.init = vmac_init_with_hardcoded_nonce; | ||
701 | inst->alg.final = vmac_final_le; | ||
702 | } | ||
703 | inst->alg.update = vmac_update; | 661 | inst->alg.update = vmac_update; |
662 | inst->alg.final = vmac_final; | ||
704 | inst->alg.setkey = vmac_setkey; | 663 | inst->alg.setkey = vmac_setkey; |
705 | 664 | ||
706 | err = shash_register_instance(tmpl, inst); | 665 | err = shash_register_instance(tmpl, inst); |
@@ -714,48 +673,20 @@ out_put_alg: | |||
714 | return err; | 673 | return err; |
715 | } | 674 | } |
716 | 675 | ||
717 | static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb) | ||
718 | { | ||
719 | return vmac_create_common(tmpl, tb, false); | ||
720 | } | ||
721 | |||
722 | static int vmac64_create(struct crypto_template *tmpl, struct rtattr **tb) | ||
723 | { | ||
724 | return vmac_create_common(tmpl, tb, true); | ||
725 | } | ||
726 | |||
727 | static struct crypto_template vmac_tmpl = { | ||
728 | .name = "vmac", | ||
729 | .create = vmac_create, | ||
730 | .free = shash_free_instance, | ||
731 | .module = THIS_MODULE, | ||
732 | }; | ||
733 | |||
734 | static struct crypto_template vmac64_tmpl = { | 676 | static struct crypto_template vmac64_tmpl = { |
735 | .name = "vmac64", | 677 | .name = "vmac64", |
736 | .create = vmac64_create, | 678 | .create = vmac_create, |
737 | .free = shash_free_instance, | 679 | .free = shash_free_instance, |
738 | .module = THIS_MODULE, | 680 | .module = THIS_MODULE, |
739 | }; | 681 | }; |
740 | 682 | ||
741 | static int __init vmac_module_init(void) | 683 | static int __init vmac_module_init(void) |
742 | { | 684 | { |
743 | int err; | 685 | return crypto_register_template(&vmac64_tmpl); |
744 | |||
745 | err = crypto_register_template(&vmac_tmpl); | ||
746 | if (err) | ||
747 | return err; | ||
748 | |||
749 | err = crypto_register_template(&vmac64_tmpl); | ||
750 | if (err) | ||
751 | crypto_unregister_template(&vmac_tmpl); | ||
752 | |||
753 | return err; | ||
754 | } | 686 | } |
755 | 687 | ||
756 | static void __exit vmac_module_exit(void) | 688 | static void __exit vmac_module_exit(void) |
757 | { | 689 | { |
758 | crypto_unregister_template(&vmac_tmpl); | ||
759 | crypto_unregister_template(&vmac64_tmpl); | 690 | crypto_unregister_template(&vmac64_tmpl); |
760 | } | 691 | } |
761 | 692 | ||
@@ -764,5 +695,4 @@ module_exit(vmac_module_exit); | |||
764 | 695 | ||
765 | MODULE_LICENSE("GPL"); | 696 | MODULE_LICENSE("GPL"); |
766 | MODULE_DESCRIPTION("VMAC hash algorithm"); | 697 | MODULE_DESCRIPTION("VMAC hash algorithm"); |
767 | MODULE_ALIAS_CRYPTO("vmac"); | ||
768 | MODULE_ALIAS_CRYPTO("vmac64"); | 698 | MODULE_ALIAS_CRYPTO("vmac64"); |