aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/tcrypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r--crypto/tcrypt.c106
1 files changed, 2 insertions, 104 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 606777074671..56d0d8b3bcf2 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -762,108 +762,6 @@ out:
762 crypto_free_tfm(tfm); 762 crypto_free_tfm(tfm);
763} 763}
764 764
765static void test_crc32c(void)
766{
767#define NUMVEC 6
768#define VECSIZE 40
769
770 int i, j, pass;
771 u32 crc;
772 u8 b, test_vec[NUMVEC][VECSIZE];
773 static u32 vec_results[NUMVEC] = {
774 0x0e2c157f, 0xe980ebf6, 0xde74bded,
775 0xd579c862, 0xba979ad0, 0x2b29d913
776 };
777 static u32 tot_vec_results = 0x24c5d375;
778
779 struct scatterlist sg[NUMVEC];
780 struct crypto_tfm *tfm;
781 char *fmtdata = "testing crc32c initialized to %08x: %s\n";
782#define SEEDTESTVAL 0xedcba987
783 u32 seed;
784
785 printk("\ntesting crc32c\n");
786
787 tfm = crypto_alloc_tfm("crc32c", 0);
788 if (tfm == NULL) {
789 printk("failed to load transform for crc32c\n");
790 return;
791 }
792
793 crypto_digest_init(tfm);
794 crypto_digest_final(tfm, (u8*)&crc);
795 printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR");
796
797 /*
798 * stuff test_vec with known values, simple incrementing
799 * byte values.
800 */
801 b = 0;
802 for (i = 0; i < NUMVEC; i++) {
803 for (j = 0; j < VECSIZE; j++)
804 test_vec[i][j] = ++b;
805 sg_set_buf(&sg[i], test_vec[i], VECSIZE);
806 }
807
808 seed = SEEDTESTVAL;
809 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
810 crypto_digest_init(tfm);
811 crypto_digest_final(tfm, (u8*)&crc);
812 printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ?
813 "pass" : "ERROR");
814
815 printk("testing crc32c using update/final:\n");
816
817 pass = 1; /* assume all is well */
818
819 for (i = 0; i < NUMVEC; i++) {
820 seed = ~(u32)0;
821 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
822 crypto_digest_init(tfm);
823 crypto_digest_update(tfm, &sg[i], 1);
824 crypto_digest_final(tfm, (u8*)&crc);
825 if (crc == vec_results[i]) {
826 printk(" %08x:OK", crc);
827 } else {
828 printk(" %08x:BAD, wanted %08x\n", crc, vec_results[i]);
829 pass = 0;
830 }
831 }
832
833 printk("\ntesting crc32c using incremental accumulator:\n");
834 crc = 0;
835 for (i = 0; i < NUMVEC; i++) {
836 seed = (crc ^ ~(u32)0);
837 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
838 crypto_digest_init(tfm);
839 crypto_digest_update(tfm, &sg[i], 1);
840 crypto_digest_final(tfm, (u8*)&crc);
841 }
842 if (crc == tot_vec_results) {
843 printk(" %08x:OK", crc);
844 } else {
845 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
846 pass = 0;
847 }
848
849 printk("\ntesting crc32c using digest:\n");
850 seed = ~(u32)0;
851 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
852 crypto_digest_init(tfm);
853 crypto_digest_digest(tfm, sg, NUMVEC, (u8*)&crc);
854 if (crc == tot_vec_results) {
855 printk(" %08x:OK", crc);
856 } else {
857 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
858 pass = 0;
859 }
860
861 printk("\n%s\n", pass ? "pass" : "ERROR");
862
863 crypto_free_tfm(tfm);
864 printk("crc32c test complete\n");
865}
866
867static void test_available(void) 765static void test_available(void)
868{ 766{
869 char **name = check; 767 char **name = check;
@@ -969,7 +867,7 @@ static void do_test(void)
969 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); 867 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
970 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); 868 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
971 test_deflate(); 869 test_deflate();
972 test_crc32c(); 870 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
973#ifdef CONFIG_CRYPTO_HMAC 871#ifdef CONFIG_CRYPTO_HMAC
974 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); 872 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
975 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); 873 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
@@ -1065,7 +963,7 @@ static void do_test(void)
1065 break; 963 break;
1066 964
1067 case 18: 965 case 18:
1068 test_crc32c(); 966 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1069 break; 967 break;
1070 968
1071 case 19: 969 case 19: