aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/testmgr.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r--crypto/testmgr.c117
1 files changed, 70 insertions, 47 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index f93b26d0fcfb..376ea88158b9 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1002,24 +1002,25 @@ static int test_pcomp(struct crypto_pcomp *tfm,
1002 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm)); 1002 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1003 unsigned int i; 1003 unsigned int i;
1004 char result[COMP_BUF_SIZE]; 1004 char result[COMP_BUF_SIZE];
1005 int error; 1005 int res;
1006 1006
1007 for (i = 0; i < ctcount; i++) { 1007 for (i = 0; i < ctcount; i++) {
1008 struct comp_request req; 1008 struct comp_request req;
1009 unsigned int produced = 0;
1009 1010
1010 error = crypto_compress_setup(tfm, ctemplate[i].params, 1011 res = crypto_compress_setup(tfm, ctemplate[i].params,
1011 ctemplate[i].paramsize); 1012 ctemplate[i].paramsize);
1012 if (error) { 1013 if (res) {
1013 pr_err("alg: pcomp: compression setup failed on test " 1014 pr_err("alg: pcomp: compression setup failed on test "
1014 "%d for %s: error=%d\n", i + 1, algo, error); 1015 "%d for %s: error=%d\n", i + 1, algo, res);
1015 return error; 1016 return res;
1016 } 1017 }
1017 1018
1018 error = crypto_compress_init(tfm); 1019 res = crypto_compress_init(tfm);
1019 if (error) { 1020 if (res) {
1020 pr_err("alg: pcomp: compression init failed on test " 1021 pr_err("alg: pcomp: compression init failed on test "
1021 "%d for %s: error=%d\n", i + 1, algo, error); 1022 "%d for %s: error=%d\n", i + 1, algo, res);
1022 return error; 1023 return res;
1023 } 1024 }
1024 1025
1025 memset(result, 0, sizeof(result)); 1026 memset(result, 0, sizeof(result));
@@ -1029,32 +1030,37 @@ static int test_pcomp(struct crypto_pcomp *tfm,
1029 req.next_out = result; 1030 req.next_out = result;
1030 req.avail_out = ctemplate[i].outlen / 2; 1031 req.avail_out = ctemplate[i].outlen / 2;
1031 1032
1032 error = crypto_compress_update(tfm, &req); 1033 res = crypto_compress_update(tfm, &req);
1033 if (error && (error != -EAGAIN || req.avail_in)) { 1034 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1034 pr_err("alg: pcomp: compression update failed on test " 1035 pr_err("alg: pcomp: compression update failed on test "
1035 "%d for %s: error=%d\n", i + 1, algo, error); 1036 "%d for %s: error=%d\n", i + 1, algo, res);
1036 return error; 1037 return res;
1037 } 1038 }
1039 if (res > 0)
1040 produced += res;
1038 1041
1039 /* Add remaining input data */ 1042 /* Add remaining input data */
1040 req.avail_in += (ctemplate[i].inlen + 1) / 2; 1043 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1041 1044
1042 error = crypto_compress_update(tfm, &req); 1045 res = crypto_compress_update(tfm, &req);
1043 if (error && (error != -EAGAIN || req.avail_in)) { 1046 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1044 pr_err("alg: pcomp: compression update failed on test " 1047 pr_err("alg: pcomp: compression update failed on test "
1045 "%d for %s: error=%d\n", i + 1, algo, error); 1048 "%d for %s: error=%d\n", i + 1, algo, res);
1046 return error; 1049 return res;
1047 } 1050 }
1051 if (res > 0)
1052 produced += res;
1048 1053
1049 /* Provide remaining output space */ 1054 /* Provide remaining output space */
1050 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2; 1055 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1051 1056
1052 error = crypto_compress_final(tfm, &req); 1057 res = crypto_compress_final(tfm, &req);
1053 if (error) { 1058 if (res < 0) {
1054 pr_err("alg: pcomp: compression final failed on test " 1059 pr_err("alg: pcomp: compression final failed on test "
1055 "%d for %s: error=%d\n", i + 1, algo, error); 1060 "%d for %s: error=%d\n", i + 1, algo, res);
1056 return error; 1061 return res;
1057 } 1062 }
1063 produced += res;
1058 1064
1059 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) { 1065 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1060 pr_err("alg: comp: Compression test %d failed for %s: " 1066 pr_err("alg: comp: Compression test %d failed for %s: "
@@ -1064,6 +1070,13 @@ static int test_pcomp(struct crypto_pcomp *tfm,
1064 return -EINVAL; 1070 return -EINVAL;
1065 } 1071 }
1066 1072
1073 if (produced != ctemplate[i].outlen) {
1074 pr_err("alg: comp: Compression test %d failed for %s: "
1075 "returned len = %u (expected %d)\n", i + 1,
1076 algo, produced, ctemplate[i].outlen);
1077 return -EINVAL;
1078 }
1079
1067 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) { 1080 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1068 pr_err("alg: pcomp: Compression test %d failed for " 1081 pr_err("alg: pcomp: Compression test %d failed for "
1069 "%s\n", i + 1, algo); 1082 "%s\n", i + 1, algo);
@@ -1074,21 +1087,21 @@ static int test_pcomp(struct crypto_pcomp *tfm,
1074 1087
1075 for (i = 0; i < dtcount; i++) { 1088 for (i = 0; i < dtcount; i++) {
1076 struct comp_request req; 1089 struct comp_request req;
1090 unsigned int produced = 0;
1077 1091
1078 error = crypto_decompress_setup(tfm, dtemplate[i].params, 1092 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1079 dtemplate[i].paramsize); 1093 dtemplate[i].paramsize);
1080 if (error) { 1094 if (res) {
1081 pr_err("alg: pcomp: decompression setup failed on " 1095 pr_err("alg: pcomp: decompression setup failed on "
1082 "test %d for %s: error=%d\n", i + 1, algo, 1096 "test %d for %s: error=%d\n", i + 1, algo, res);
1083 error); 1097 return res;
1084 return error;
1085 } 1098 }
1086 1099
1087 error = crypto_decompress_init(tfm); 1100 res = crypto_decompress_init(tfm);
1088 if (error) { 1101 if (res) {
1089 pr_err("alg: pcomp: decompression init failed on test " 1102 pr_err("alg: pcomp: decompression init failed on test "
1090 "%d for %s: error=%d\n", i + 1, algo, error); 1103 "%d for %s: error=%d\n", i + 1, algo, res);
1091 return error; 1104 return res;
1092 } 1105 }
1093 1106
1094 memset(result, 0, sizeof(result)); 1107 memset(result, 0, sizeof(result));
@@ -1098,35 +1111,38 @@ static int test_pcomp(struct crypto_pcomp *tfm,
1098 req.next_out = result; 1111 req.next_out = result;
1099 req.avail_out = dtemplate[i].outlen / 2; 1112 req.avail_out = dtemplate[i].outlen / 2;
1100 1113
1101 error = crypto_decompress_update(tfm, &req); 1114 res = crypto_decompress_update(tfm, &req);
1102 if (error && (error != -EAGAIN || req.avail_in)) { 1115 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1103 pr_err("alg: pcomp: decompression update failed on " 1116 pr_err("alg: pcomp: decompression update failed on "
1104 "test %d for %s: error=%d\n", i + 1, algo, 1117 "test %d for %s: error=%d\n", i + 1, algo, res);
1105 error); 1118 return res;
1106 return error;
1107 } 1119 }
1120 if (res > 0)
1121 produced += res;
1108 1122
1109 /* Add remaining input data */ 1123 /* Add remaining input data */
1110 req.avail_in += (dtemplate[i].inlen + 1) / 2; 1124 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1111 1125
1112 error = crypto_decompress_update(tfm, &req); 1126 res = crypto_decompress_update(tfm, &req);
1113 if (error && (error != -EAGAIN || req.avail_in)) { 1127 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1114 pr_err("alg: pcomp: decompression update failed on " 1128 pr_err("alg: pcomp: decompression update failed on "
1115 "test %d for %s: error=%d\n", i + 1, algo, 1129 "test %d for %s: error=%d\n", i + 1, algo, res);
1116 error); 1130 return res;
1117 return error;
1118 } 1131 }
1132 if (res > 0)
1133 produced += res;
1119 1134
1120 /* Provide remaining output space */ 1135 /* Provide remaining output space */
1121 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2; 1136 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1122 1137
1123 error = crypto_decompress_final(tfm, &req); 1138 res = crypto_decompress_final(tfm, &req);
1124 if (error && (error != -EAGAIN || req.avail_in)) { 1139 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1125 pr_err("alg: pcomp: decompression final failed on " 1140 pr_err("alg: pcomp: decompression final failed on "
1126 "test %d for %s: error=%d\n", i + 1, algo, 1141 "test %d for %s: error=%d\n", i + 1, algo, res);
1127 error); 1142 return res;
1128 return error;
1129 } 1143 }
1144 if (res > 0)
1145 produced += res;
1130 1146
1131 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) { 1147 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1132 pr_err("alg: comp: Decompression test %d failed for " 1148 pr_err("alg: comp: Decompression test %d failed for "
@@ -1136,6 +1152,13 @@ static int test_pcomp(struct crypto_pcomp *tfm,
1136 return -EINVAL; 1152 return -EINVAL;
1137 } 1153 }
1138 1154
1155 if (produced != dtemplate[i].outlen) {
1156 pr_err("alg: comp: Decompression test %d failed for "
1157 "%s: returned len = %u (expected %d)\n", i + 1,
1158 algo, produced, dtemplate[i].outlen);
1159 return -EINVAL;
1160 }
1161
1139 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) { 1162 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1140 pr_err("alg: pcomp: Decompression test %d failed for " 1163 pr_err("alg: pcomp: Decompression test %d failed for "
1141 "%s\n", i + 1, algo); 1164 "%s\n", i + 1, algo);