diff options
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r-- | crypto/testmgr.c | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index b828c6cf1b1d..a75f11ffb957 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
@@ -843,6 +843,14 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, | |||
843 | goto out; | 843 | goto out; |
844 | } | 844 | } |
845 | 845 | ||
846 | if (dlen != ctemplate[i].outlen) { | ||
847 | printk(KERN_ERR "alg: comp: Compression test %d " | ||
848 | "failed for %s: output len = %d\n", i + 1, algo, | ||
849 | dlen); | ||
850 | ret = -EINVAL; | ||
851 | goto out; | ||
852 | } | ||
853 | |||
846 | if (memcmp(result, ctemplate[i].output, dlen)) { | 854 | if (memcmp(result, ctemplate[i].output, dlen)) { |
847 | printk(KERN_ERR "alg: comp: Compression test %d " | 855 | printk(KERN_ERR "alg: comp: Compression test %d " |
848 | "failed for %s\n", i + 1, algo); | 856 | "failed for %s\n", i + 1, algo); |
@@ -853,7 +861,7 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, | |||
853 | } | 861 | } |
854 | 862 | ||
855 | for (i = 0; i < dtcount; i++) { | 863 | for (i = 0; i < dtcount; i++) { |
856 | int ilen, ret, dlen = COMP_BUF_SIZE; | 864 | int ilen, dlen = COMP_BUF_SIZE; |
857 | 865 | ||
858 | memset(result, 0, sizeof (result)); | 866 | memset(result, 0, sizeof (result)); |
859 | 867 | ||
@@ -867,6 +875,14 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, | |||
867 | goto out; | 875 | goto out; |
868 | } | 876 | } |
869 | 877 | ||
878 | if (dlen != dtemplate[i].outlen) { | ||
879 | printk(KERN_ERR "alg: comp: Decompression test %d " | ||
880 | "failed for %s: output len = %d\n", i + 1, algo, | ||
881 | dlen); | ||
882 | ret = -EINVAL; | ||
883 | goto out; | ||
884 | } | ||
885 | |||
870 | if (memcmp(result, dtemplate[i].output, dlen)) { | 886 | if (memcmp(result, dtemplate[i].output, dlen)) { |
871 | printk(KERN_ERR "alg: comp: Decompression test %d " | 887 | printk(KERN_ERR "alg: comp: Decompression test %d " |
872 | "failed for %s\n", i + 1, algo); | 888 | "failed for %s\n", i + 1, algo); |
@@ -1010,6 +1026,55 @@ static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, | |||
1010 | return err; | 1026 | return err; |
1011 | } | 1027 | } |
1012 | 1028 | ||
1029 | static int alg_test_crc32c(const struct alg_test_desc *desc, | ||
1030 | const char *driver, u32 type, u32 mask) | ||
1031 | { | ||
1032 | struct crypto_shash *tfm; | ||
1033 | u32 val; | ||
1034 | int err; | ||
1035 | |||
1036 | err = alg_test_hash(desc, driver, type, mask); | ||
1037 | if (err) | ||
1038 | goto out; | ||
1039 | |||
1040 | tfm = crypto_alloc_shash(driver, type, mask); | ||
1041 | if (IS_ERR(tfm)) { | ||
1042 | printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: " | ||
1043 | "%ld\n", driver, PTR_ERR(tfm)); | ||
1044 | err = PTR_ERR(tfm); | ||
1045 | goto out; | ||
1046 | } | ||
1047 | |||
1048 | do { | ||
1049 | struct { | ||
1050 | struct shash_desc shash; | ||
1051 | char ctx[crypto_shash_descsize(tfm)]; | ||
1052 | } sdesc; | ||
1053 | |||
1054 | sdesc.shash.tfm = tfm; | ||
1055 | sdesc.shash.flags = 0; | ||
1056 | |||
1057 | *(u32 *)sdesc.ctx = le32_to_cpu(420553207); | ||
1058 | err = crypto_shash_final(&sdesc.shash, (u8 *)&val); | ||
1059 | if (err) { | ||
1060 | printk(KERN_ERR "alg: crc32c: Operation failed for " | ||
1061 | "%s: %d\n", driver, err); | ||
1062 | break; | ||
1063 | } | ||
1064 | |||
1065 | if (val != ~420553207) { | ||
1066 | printk(KERN_ERR "alg: crc32c: Test failed for %s: " | ||
1067 | "%d\n", driver, val); | ||
1068 | err = -EINVAL; | ||
1069 | } | ||
1070 | } while (0); | ||
1071 | |||
1072 | crypto_free_shash(tfm); | ||
1073 | |||
1074 | out: | ||
1075 | return err; | ||
1076 | } | ||
1077 | |||
1013 | /* Please keep this list sorted by algorithm name. */ | 1078 | /* Please keep this list sorted by algorithm name. */ |
1014 | static const struct alg_test_desc alg_test_descs[] = { | 1079 | static const struct alg_test_desc alg_test_descs[] = { |
1015 | { | 1080 | { |
@@ -1134,7 +1199,7 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
1134 | } | 1199 | } |
1135 | }, { | 1200 | }, { |
1136 | .alg = "crc32c", | 1201 | .alg = "crc32c", |
1137 | .test = alg_test_hash, | 1202 | .test = alg_test_crc32c, |
1138 | .suite = { | 1203 | .suite = { |
1139 | .hash = { | 1204 | .hash = { |
1140 | .vecs = crc32c_tv_template, | 1205 | .vecs = crc32c_tv_template, |
@@ -1801,6 +1866,7 @@ static int alg_find_test(const char *alg) | |||
1801 | int alg_test(const char *driver, const char *alg, u32 type, u32 mask) | 1866 | int alg_test(const char *driver, const char *alg, u32 type, u32 mask) |
1802 | { | 1867 | { |
1803 | int i; | 1868 | int i; |
1869 | int rc; | ||
1804 | 1870 | ||
1805 | if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) { | 1871 | if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) { |
1806 | char nalg[CRYPTO_MAX_ALG_NAME]; | 1872 | char nalg[CRYPTO_MAX_ALG_NAME]; |
@@ -1820,8 +1886,12 @@ int alg_test(const char *driver, const char *alg, u32 type, u32 mask) | |||
1820 | if (i < 0) | 1886 | if (i < 0) |
1821 | goto notest; | 1887 | goto notest; |
1822 | 1888 | ||
1823 | return alg_test_descs[i].test(alg_test_descs + i, driver, | 1889 | rc = alg_test_descs[i].test(alg_test_descs + i, driver, |
1824 | type, mask); | 1890 | type, mask); |
1891 | if (fips_enabled && rc) | ||
1892 | panic("%s: %s alg self test failed in fips mode!\n", driver, alg); | ||
1893 | |||
1894 | return rc; | ||
1825 | 1895 | ||
1826 | notest: | 1896 | notest: |
1827 | printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); | 1897 | printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); |