diff options
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r-- | crypto/testmgr.c | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index a75f11ffb957..e750357b898f 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
@@ -72,6 +72,13 @@ struct comp_test_suite { | |||
72 | } comp, decomp; | 72 | } comp, decomp; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | struct pcomp_test_suite { | ||
76 | struct { | ||
77 | struct pcomp_testvec *vecs; | ||
78 | unsigned int count; | ||
79 | } comp, decomp; | ||
80 | }; | ||
81 | |||
75 | struct hash_test_suite { | 82 | struct hash_test_suite { |
76 | struct hash_testvec *vecs; | 83 | struct hash_testvec *vecs; |
77 | unsigned int count; | 84 | unsigned int count; |
@@ -86,6 +93,7 @@ struct alg_test_desc { | |||
86 | struct aead_test_suite aead; | 93 | struct aead_test_suite aead; |
87 | struct cipher_test_suite cipher; | 94 | struct cipher_test_suite cipher; |
88 | struct comp_test_suite comp; | 95 | struct comp_test_suite comp; |
96 | struct pcomp_test_suite pcomp; | ||
89 | struct hash_test_suite hash; | 97 | struct hash_test_suite hash; |
90 | } suite; | 98 | } suite; |
91 | }; | 99 | }; |
@@ -898,6 +906,159 @@ out: | |||
898 | return ret; | 906 | return ret; |
899 | } | 907 | } |
900 | 908 | ||
909 | static int test_pcomp(struct crypto_pcomp *tfm, | ||
910 | struct pcomp_testvec *ctemplate, | ||
911 | struct pcomp_testvec *dtemplate, int ctcount, | ||
912 | int dtcount) | ||
913 | { | ||
914 | const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm)); | ||
915 | unsigned int i; | ||
916 | char result[COMP_BUF_SIZE]; | ||
917 | int error; | ||
918 | |||
919 | for (i = 0; i < ctcount; i++) { | ||
920 | struct comp_request req; | ||
921 | |||
922 | error = crypto_compress_setup(tfm, ctemplate[i].params, | ||
923 | ctemplate[i].paramsize); | ||
924 | if (error) { | ||
925 | pr_err("alg: pcomp: compression setup failed on test " | ||
926 | "%d for %s: error=%d\n", i + 1, algo, error); | ||
927 | return error; | ||
928 | } | ||
929 | |||
930 | error = crypto_compress_init(tfm); | ||
931 | if (error) { | ||
932 | pr_err("alg: pcomp: compression init failed on test " | ||
933 | "%d for %s: error=%d\n", i + 1, algo, error); | ||
934 | return error; | ||
935 | } | ||
936 | |||
937 | memset(result, 0, sizeof(result)); | ||
938 | |||
939 | req.next_in = ctemplate[i].input; | ||
940 | req.avail_in = ctemplate[i].inlen / 2; | ||
941 | req.next_out = result; | ||
942 | req.avail_out = ctemplate[i].outlen / 2; | ||
943 | |||
944 | error = crypto_compress_update(tfm, &req); | ||
945 | if (error && (error != -EAGAIN || req.avail_in)) { | ||
946 | pr_err("alg: pcomp: compression update failed on test " | ||
947 | "%d for %s: error=%d\n", i + 1, algo, error); | ||
948 | return error; | ||
949 | } | ||
950 | |||
951 | /* Add remaining input data */ | ||
952 | req.avail_in += (ctemplate[i].inlen + 1) / 2; | ||
953 | |||
954 | error = crypto_compress_update(tfm, &req); | ||
955 | if (error && (error != -EAGAIN || req.avail_in)) { | ||
956 | pr_err("alg: pcomp: compression update failed on test " | ||
957 | "%d for %s: error=%d\n", i + 1, algo, error); | ||
958 | return error; | ||
959 | } | ||
960 | |||
961 | /* Provide remaining output space */ | ||
962 | req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2; | ||
963 | |||
964 | error = crypto_compress_final(tfm, &req); | ||
965 | if (error) { | ||
966 | pr_err("alg: pcomp: compression final failed on test " | ||
967 | "%d for %s: error=%d\n", i + 1, algo, error); | ||
968 | return error; | ||
969 | } | ||
970 | |||
971 | if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) { | ||
972 | pr_err("alg: comp: Compression test %d failed for %s: " | ||
973 | "output len = %d (expected %d)\n", i + 1, algo, | ||
974 | COMP_BUF_SIZE - req.avail_out, | ||
975 | ctemplate[i].outlen); | ||
976 | return -EINVAL; | ||
977 | } | ||
978 | |||
979 | if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) { | ||
980 | pr_err("alg: pcomp: Compression test %d failed for " | ||
981 | "%s\n", i + 1, algo); | ||
982 | hexdump(result, ctemplate[i].outlen); | ||
983 | return -EINVAL; | ||
984 | } | ||
985 | } | ||
986 | |||
987 | for (i = 0; i < dtcount; i++) { | ||
988 | struct comp_request req; | ||
989 | |||
990 | error = crypto_decompress_setup(tfm, dtemplate[i].params, | ||
991 | dtemplate[i].paramsize); | ||
992 | if (error) { | ||
993 | pr_err("alg: pcomp: decompression setup failed on " | ||
994 | "test %d for %s: error=%d\n", i + 1, algo, | ||
995 | error); | ||
996 | return error; | ||
997 | } | ||
998 | |||
999 | error = crypto_decompress_init(tfm); | ||
1000 | if (error) { | ||
1001 | pr_err("alg: pcomp: decompression init failed on test " | ||
1002 | "%d for %s: error=%d\n", i + 1, algo, error); | ||
1003 | return error; | ||
1004 | } | ||
1005 | |||
1006 | memset(result, 0, sizeof(result)); | ||
1007 | |||
1008 | req.next_in = dtemplate[i].input; | ||
1009 | req.avail_in = dtemplate[i].inlen / 2; | ||
1010 | req.next_out = result; | ||
1011 | req.avail_out = dtemplate[i].outlen / 2; | ||
1012 | |||
1013 | error = crypto_decompress_update(tfm, &req); | ||
1014 | if (error && (error != -EAGAIN || req.avail_in)) { | ||
1015 | pr_err("alg: pcomp: decompression update failed on " | ||
1016 | "test %d for %s: error=%d\n", i + 1, algo, | ||
1017 | error); | ||
1018 | return error; | ||
1019 | } | ||
1020 | |||
1021 | /* Add remaining input data */ | ||
1022 | req.avail_in += (dtemplate[i].inlen + 1) / 2; | ||
1023 | |||
1024 | error = crypto_decompress_update(tfm, &req); | ||
1025 | if (error && (error != -EAGAIN || req.avail_in)) { | ||
1026 | pr_err("alg: pcomp: decompression update failed on " | ||
1027 | "test %d for %s: error=%d\n", i + 1, algo, | ||
1028 | error); | ||
1029 | return error; | ||
1030 | } | ||
1031 | |||
1032 | /* Provide remaining output space */ | ||
1033 | req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2; | ||
1034 | |||
1035 | error = crypto_decompress_final(tfm, &req); | ||
1036 | if (error && (error != -EAGAIN || req.avail_in)) { | ||
1037 | pr_err("alg: pcomp: decompression final failed on " | ||
1038 | "test %d for %s: error=%d\n", i + 1, algo, | ||
1039 | error); | ||
1040 | return error; | ||
1041 | } | ||
1042 | |||
1043 | if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) { | ||
1044 | pr_err("alg: comp: Decompression test %d failed for " | ||
1045 | "%s: output len = %d (expected %d)\n", i + 1, | ||
1046 | algo, COMP_BUF_SIZE - req.avail_out, | ||
1047 | dtemplate[i].outlen); | ||
1048 | return -EINVAL; | ||
1049 | } | ||
1050 | |||
1051 | if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) { | ||
1052 | pr_err("alg: pcomp: Decompression test %d failed for " | ||
1053 | "%s\n", i + 1, algo); | ||
1054 | hexdump(result, dtemplate[i].outlen); | ||
1055 | return -EINVAL; | ||
1056 | } | ||
1057 | } | ||
1058 | |||
1059 | return 0; | ||
1060 | } | ||
1061 | |||
901 | static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, | 1062 | static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, |
902 | u32 type, u32 mask) | 1063 | u32 type, u32 mask) |
903 | { | 1064 | { |
@@ -1007,6 +1168,28 @@ static int alg_test_comp(const struct alg_test_desc *desc, const char *driver, | |||
1007 | return err; | 1168 | return err; |
1008 | } | 1169 | } |
1009 | 1170 | ||
1171 | static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver, | ||
1172 | u32 type, u32 mask) | ||
1173 | { | ||
1174 | struct crypto_pcomp *tfm; | ||
1175 | int err; | ||
1176 | |||
1177 | tfm = crypto_alloc_pcomp(driver, type, mask); | ||
1178 | if (IS_ERR(tfm)) { | ||
1179 | pr_err("alg: pcomp: Failed to load transform for %s: %ld\n", | ||
1180 | driver, PTR_ERR(tfm)); | ||
1181 | return PTR_ERR(tfm); | ||
1182 | } | ||
1183 | |||
1184 | err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs, | ||
1185 | desc->suite.pcomp.decomp.vecs, | ||
1186 | desc->suite.pcomp.comp.count, | ||
1187 | desc->suite.pcomp.decomp.count); | ||
1188 | |||
1189 | crypto_free_pcomp(tfm); | ||
1190 | return err; | ||
1191 | } | ||
1192 | |||
1010 | static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, | 1193 | static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, |
1011 | u32 type, u32 mask) | 1194 | u32 type, u32 mask) |
1012 | { | 1195 | { |