aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorGeert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>2009-05-27 01:05:02 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2009-06-02 00:04:56 -0400
commit3ce858cb04de8bc83449eac707c8012a1944daca (patch)
tree0bdf275d63a6f53f01703255d52a6129df9fd3dc /crypto
parente9736c16da9077728802f42393d18258e6685428 (diff)
crypto: compress - Return produced bytes in crypto_{,de}compress_{update,final}
If crypto_{,de}compress_{update,final}() succeed, return the actual number of bytes produced instead of zero, so their users don't have to calculate that theirselves. Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/testmgr.c117
-rw-r--r--crypto/zlib.c24
2 files changed, 82 insertions, 59 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);
diff --git a/crypto/zlib.c b/crypto/zlib.c
index 33609bab614e..c3015733c990 100644
--- a/crypto/zlib.c
+++ b/crypto/zlib.c
@@ -165,15 +165,15 @@ static int zlib_compress_update(struct crypto_pcomp *tfm,
165 return -EINVAL; 165 return -EINVAL;
166 } 166 }
167 167
168 ret = req->avail_out - stream->avail_out;
168 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", 169 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
169 stream->avail_in, stream->avail_out, 170 stream->avail_in, stream->avail_out,
170 req->avail_in - stream->avail_in, 171 req->avail_in - stream->avail_in, ret);
171 req->avail_out - stream->avail_out);
172 req->next_in = stream->next_in; 172 req->next_in = stream->next_in;
173 req->avail_in = stream->avail_in; 173 req->avail_in = stream->avail_in;
174 req->next_out = stream->next_out; 174 req->next_out = stream->next_out;
175 req->avail_out = stream->avail_out; 175 req->avail_out = stream->avail_out;
176 return 0; 176 return ret;
177} 177}
178 178
179static int zlib_compress_final(struct crypto_pcomp *tfm, 179static int zlib_compress_final(struct crypto_pcomp *tfm,
@@ -195,15 +195,15 @@ static int zlib_compress_final(struct crypto_pcomp *tfm,
195 return -EINVAL; 195 return -EINVAL;
196 } 196 }
197 197
198 ret = req->avail_out - stream->avail_out;
198 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", 199 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
199 stream->avail_in, stream->avail_out, 200 stream->avail_in, stream->avail_out,
200 req->avail_in - stream->avail_in, 201 req->avail_in - stream->avail_in, ret);
201 req->avail_out - stream->avail_out);
202 req->next_in = stream->next_in; 202 req->next_in = stream->next_in;
203 req->avail_in = stream->avail_in; 203 req->avail_in = stream->avail_in;
204 req->next_out = stream->next_out; 204 req->next_out = stream->next_out;
205 req->avail_out = stream->avail_out; 205 req->avail_out = stream->avail_out;
206 return 0; 206 return ret;
207} 207}
208 208
209 209
@@ -280,15 +280,15 @@ static int zlib_decompress_update(struct crypto_pcomp *tfm,
280 return -EINVAL; 280 return -EINVAL;
281 } 281 }
282 282
283 ret = req->avail_out - stream->avail_out;
283 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", 284 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
284 stream->avail_in, stream->avail_out, 285 stream->avail_in, stream->avail_out,
285 req->avail_in - stream->avail_in, 286 req->avail_in - stream->avail_in, ret);
286 req->avail_out - stream->avail_out);
287 req->next_in = stream->next_in; 287 req->next_in = stream->next_in;
288 req->avail_in = stream->avail_in; 288 req->avail_in = stream->avail_in;
289 req->next_out = stream->next_out; 289 req->next_out = stream->next_out;
290 req->avail_out = stream->avail_out; 290 req->avail_out = stream->avail_out;
291 return 0; 291 return ret;
292} 292}
293 293
294static int zlib_decompress_final(struct crypto_pcomp *tfm, 294static int zlib_decompress_final(struct crypto_pcomp *tfm,
@@ -328,15 +328,15 @@ static int zlib_decompress_final(struct crypto_pcomp *tfm,
328 return -EINVAL; 328 return -EINVAL;
329 } 329 }
330 330
331 ret = req->avail_out - stream->avail_out;
331 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", 332 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
332 stream->avail_in, stream->avail_out, 333 stream->avail_in, stream->avail_out,
333 req->avail_in - stream->avail_in, 334 req->avail_in - stream->avail_in, ret);
334 req->avail_out - stream->avail_out);
335 req->next_in = stream->next_in; 335 req->next_in = stream->next_in;
336 req->avail_in = stream->avail_in; 336 req->avail_in = stream->avail_in;
337 req->next_out = stream->next_out; 337 req->next_out = stream->next_out;
338 req->avail_out = stream->avail_out; 338 req->avail_out = stream->avail_out;
339 return 0; 339 return ret;
340} 340}
341 341
342 342