summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2014-04-26 13:04:24 +0000
committerjsing <>2014-04-26 13:04:24 +0000
commit881a5b100e88cfb566ac3dadda9aa58488a5aaf9 (patch)
tree16b961d6fbca1609959ab8356b98834930b718ab /src
parent9252e528b8dc5bc122ec8aeb936555f5879863d8 (diff)
downloadopenbsd-881a5b100e88cfb566ac3dadda9aa58488a5aaf9.tar.gz
openbsd-881a5b100e88cfb566ac3dadda9aa58488a5aaf9.tar.bz2
openbsd-881a5b100e88cfb566ac3dadda9aa58488a5aaf9.zip
KNF.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/comp/c_rle.c66
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c610
-rw-r--r--src/lib/libcrypto/comp/comp.h24
-rw-r--r--src/lib/libcrypto/comp/comp_err.c47
-rw-r--r--src/lib/libcrypto/comp/comp_lib.c91
-rw-r--r--src/lib/libssl/src/crypto/comp/c_rle.c66
-rw-r--r--src/lib/libssl/src/crypto/comp/c_zlib.c610
-rw-r--r--src/lib/libssl/src/crypto/comp/comp.h24
-rw-r--r--src/lib/libssl/src/crypto/comp/comp_err.c47
-rw-r--r--src/lib/libssl/src/crypto/comp/comp_lib.c91
10 files changed, 828 insertions, 848 deletions
diff --git a/src/lib/libcrypto/comp/c_rle.c b/src/lib/libcrypto/comp/c_rle.c
index 47dfb67fbd..7a5db298c5 100644
--- a/src/lib/libcrypto/comp/c_rle.c
+++ b/src/lib/libcrypto/comp/c_rle.c
@@ -5,11 +5,11 @@
5#include <openssl/comp.h> 5#include <openssl/comp.h>
6 6
7static int rle_compress_block(COMP_CTX *ctx, unsigned char *out, 7static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
8 unsigned int olen, unsigned char *in, unsigned int ilen); 8 unsigned int olen, unsigned char *in, unsigned int ilen);
9static int rle_expand_block(COMP_CTX *ctx, unsigned char *out, 9static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
10 unsigned int olen, unsigned char *in, unsigned int ilen); 10 unsigned int olen, unsigned char *in, unsigned int ilen);
11 11
12static COMP_METHOD rle_method={ 12static COMP_METHOD rle_method = {
13 NID_rle_compression, 13 NID_rle_compression,
14 LN_rle_compression, 14 LN_rle_compression,
15 NULL, 15 NULL,
@@ -18,44 +18,44 @@ static COMP_METHOD rle_method={
18 rle_expand_block, 18 rle_expand_block,
19 NULL, 19 NULL,
20 NULL, 20 NULL,
21 }; 21};
22 22
23COMP_METHOD *COMP_rle(void) 23COMP_METHOD *
24 { 24COMP_rle(void)
25 return(&rle_method); 25{
26 } 26 return (&rle_method);
27 27}
28static int rle_compress_block(COMP_CTX *ctx, unsigned char *out, 28
29 unsigned int olen, unsigned char *in, unsigned int ilen) 29static int
30 { 30rle_compress_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
31 unsigned char *in, unsigned int ilen)
32{
31 /* int i; */ 33 /* int i; */
32 34
33 if (ilen == 0 || olen < (ilen-1)) 35 if (ilen == 0 || olen < (ilen - 1)) {
34 {
35 /* ZZZZZZZZZZZZZZZZZZZZZZ */ 36 /* ZZZZZZZZZZZZZZZZZZZZZZ */
36 return(-1); 37 return (-1);
37 }
38
39 *(out++)=0;
40 memcpy(out,in,ilen);
41 return(ilen+1);
42 } 38 }
43 39
44static int rle_expand_block(COMP_CTX *ctx, unsigned char *out, 40 *(out++) = 0;
45 unsigned int olen, unsigned char *in, unsigned int ilen) 41 memcpy(out, in, ilen);
46 { 42 return (ilen + 1);
43}
44
45static int
46rle_expand_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
47 unsigned char *in, unsigned int ilen)
48{
47 int i; 49 int i;
48 50
49 if (olen < (ilen-1)) 51 if (olen < (ilen - 1)) {
50 {
51 /* ZZZZZZZZZZZZZZZZZZZZZZ */ 52 /* ZZZZZZZZZZZZZZZZZZZZZZ */
52 return(-1); 53 return (-1);
53 } 54 }
54 55
55 i= *(in++); 56 i= *(in++);
56 if (i == 0) 57 if (i == 0) {
57 { 58 memcpy(out, in, ilen - 1);
58 memcpy(out,in,ilen-1);
59 }
60 return(ilen-1);
61 } 59 }
60 return (ilen - 1);
61}
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
index e50b6eb4a3..aaf89429b6 100644
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ b/src/lib/libcrypto/comp/c_zlib.c
@@ -7,7 +7,7 @@
7 7
8COMP_METHOD *COMP_zlib(void ); 8COMP_METHOD *COMP_zlib(void );
9 9
10static COMP_METHOD zlib_method_nozlib={ 10static COMP_METHOD zlib_method_nozlib = {
11 NID_undef, 11 NID_undef,
12 "(undef)", 12 "(undef)",
13 NULL, 13 NULL,
@@ -16,7 +16,7 @@ static COMP_METHOD zlib_method_nozlib={
16 NULL, 16 NULL,
17 NULL, 17 NULL,
18 NULL, 18 NULL,
19 }; 19};
20 20
21#ifndef ZLIB 21#ifndef ZLIB
22#undef ZLIB_SHARED 22#undef ZLIB_SHARED
@@ -27,32 +27,34 @@ static COMP_METHOD zlib_method_nozlib={
27static int zlib_stateful_init(COMP_CTX *ctx); 27static int zlib_stateful_init(COMP_CTX *ctx);
28static void zlib_stateful_finish(COMP_CTX *ctx); 28static void zlib_stateful_finish(COMP_CTX *ctx);
29static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out, 29static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
30 unsigned int olen, unsigned char *in, unsigned int ilen); 30 unsigned int olen, unsigned char *in, unsigned int ilen);
31static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, 31static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
32 unsigned int olen, unsigned char *in, unsigned int ilen); 32 unsigned int olen, unsigned char *in, unsigned int ilen);
33 33
34 34
35/* memory allocations functions for zlib intialization */ 35/* memory allocations functions for zlib intialization */
36static void* zlib_zalloc(void* opaque, unsigned int no, unsigned int size) 36static void*
37zlib_zalloc(void* opaque, unsigned int no, unsigned int size)
37{ 38{
38 return calloc(no, size); 39 return calloc(no, size);
39} 40}
40 41
41static void zlib_zfree(void* opaque, void* address) 42static void
43zlib_zfree(void* opaque, void* address)
42{ 44{
43 free(address); 45 free(address);
44} 46}
45 47
46#if 0 48#if 0
47static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, 49static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
48 unsigned int olen, unsigned char *in, unsigned int ilen); 50 unsigned int olen, unsigned char *in, unsigned int ilen);
49static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out, 51static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
50 unsigned int olen, unsigned char *in, unsigned int ilen); 52 unsigned int olen, unsigned char *in, unsigned int ilen);
51 53
52static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, 54static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
53 uLong sourceLen); 55 uLong sourceLen);
54 56
55static COMP_METHOD zlib_stateless_method={ 57static COMP_METHOD zlib_stateless_method = {
56 NID_zlib_compression, 58 NID_zlib_compression,
57 LN_zlib_compression, 59 LN_zlib_compression,
58 NULL, 60 NULL,
@@ -61,10 +63,10 @@ static COMP_METHOD zlib_stateless_method={
61 zlib_expand_block, 63 zlib_expand_block,
62 NULL, 64 NULL,
63 NULL, 65 NULL,
64 }; 66};
65#endif 67#endif
66 68
67static COMP_METHOD zlib_stateful_method={ 69static COMP_METHOD zlib_stateful_method = {
68 NID_zlib_compression, 70 NID_zlib_compression,
69 LN_zlib_compression, 71 LN_zlib_compression,
70 zlib_stateful_init, 72 zlib_stateful_init,
@@ -73,31 +75,31 @@ static COMP_METHOD zlib_stateful_method={
73 zlib_stateful_expand_block, 75 zlib_stateful_expand_block,
74 NULL, 76 NULL,
75 NULL, 77 NULL,
76 }; 78};
77 79
78#ifdef ZLIB_SHARED 80#ifdef ZLIB_SHARED
79#include <openssl/dso.h> 81#include <openssl/dso.h>
80 82
81/* Function pointers */ 83/* Function pointers */
82typedef int (*compress_ft)(Bytef *dest,uLongf *destLen, 84typedef int (*compress_ft)(Bytef *dest, uLongf *destLen, const Bytef *source,
83 const Bytef *source, uLong sourceLen); 85 uLong sourceLen);
84typedef int (*inflateEnd_ft)(z_streamp strm); 86typedef int (*inflateEnd_ft)(z_streamp strm);
85typedef int (*inflate_ft)(z_streamp strm, int flush); 87typedef int (*inflate_ft)(z_streamp strm, int flush);
86typedef int (*inflateInit__ft)(z_streamp strm, 88typedef int (*inflateInit__ft)(z_streamp strm, const char * version,
87 const char * version, int stream_size); 89 int stream_size);
88typedef int (*deflateEnd_ft)(z_streamp strm); 90typedef int (*deflateEnd_ft)(z_streamp strm);
89typedef int (*deflate_ft)(z_streamp strm, int flush); 91typedef int (*deflate_ft)(z_streamp strm, int flush);
90typedef int (*deflateInit__ft)(z_streamp strm, int level, 92typedef int (*deflateInit__ft)(z_streamp strm, int level, const char * version,
91 const char * version, int stream_size); 93 int stream_size);
92typedef const char * (*zError__ft)(int err); 94typedef const char * (*zError__ft)(int err);
93static compress_ft p_compress=NULL; 95static compress_ft p_compress = NULL;
94static inflateEnd_ft p_inflateEnd=NULL; 96static inflateEnd_ft p_inflateEnd = NULL;
95static inflate_ft p_inflate=NULL; 97static inflate_ft p_inflate = NULL;
96static inflateInit__ft p_inflateInit_=NULL; 98static inflateInit__ft p_inflateInit_ = NULL;
97static deflateEnd_ft p_deflateEnd=NULL; 99static deflateEnd_ft p_deflateEnd = NULL;
98static deflate_ft p_deflate=NULL; 100static deflate_ft p_deflate = NULL;
99static deflateInit__ft p_deflateInit_=NULL; 101static deflateInit__ft p_deflateInit_ = NULL;
100static zError__ft p_zError=NULL; 102static zError__ft p_zError = NULL;
101 103
102static int zlib_loaded = 0; /* only attempt to init func pts once */ 104static int zlib_loaded = 0; /* only attempt to init func pts once */
103static DSO *zlib_dso = NULL; 105static DSO *zlib_dso = NULL;
@@ -112,19 +114,19 @@ static DSO *zlib_dso = NULL;
112#define zError p_zError 114#define zError p_zError
113#endif /* ZLIB_SHARED */ 115#endif /* ZLIB_SHARED */
114 116
115struct zlib_state 117struct zlib_state {
116 {
117 z_stream istream; 118 z_stream istream;
118 z_stream ostream; 119 z_stream ostream;
119 }; 120};
120 121
121static int zlib_stateful_ex_idx = -1; 122static int zlib_stateful_ex_idx = -1;
122 123
123static int zlib_stateful_init(COMP_CTX *ctx) 124static int
124 { 125zlib_stateful_init(COMP_CTX *ctx)
126{
125 int err; 127 int err;
126 struct zlib_state *state = 128 struct zlib_state *state =
127 (struct zlib_state *)malloc(sizeof(struct zlib_state)); 129 (struct zlib_state *)malloc(sizeof(struct zlib_state));
128 130
129 if (state == NULL) 131 if (state == NULL)
130 goto err; 132 goto err;
@@ -136,8 +138,7 @@ static int zlib_stateful_init(COMP_CTX *ctx)
136 state->istream.next_out = Z_NULL; 138 state->istream.next_out = Z_NULL;
137 state->istream.avail_in = 0; 139 state->istream.avail_in = 0;
138 state->istream.avail_out = 0; 140 state->istream.avail_out = 0;
139 err = inflateInit_(&state->istream, 141 err = inflateInit_(&state->istream, ZLIB_VERSION, sizeof(z_stream));
140 ZLIB_VERSION, sizeof(z_stream));
141 if (err != Z_OK) 142 if (err != Z_OK)
142 goto err; 143 goto err;
143 144
@@ -148,37 +149,41 @@ static int zlib_stateful_init(COMP_CTX *ctx)
148 state->ostream.next_out = Z_NULL; 149 state->ostream.next_out = Z_NULL;
149 state->ostream.avail_in = 0; 150 state->ostream.avail_in = 0;
150 state->ostream.avail_out = 0; 151 state->ostream.avail_out = 0;
151 err = deflateInit_(&state->ostream,Z_DEFAULT_COMPRESSION, 152 err = deflateInit_(&state->ostream, Z_DEFAULT_COMPRESSION,
152 ZLIB_VERSION, sizeof(z_stream)); 153 ZLIB_VERSION, sizeof(z_stream));
153 if (err != Z_OK) 154 if (err != Z_OK)
154 goto err; 155 goto err;
155 156
156 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data); 157 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
157 CRYPTO_set_ex_data(&ctx->ex_data,zlib_stateful_ex_idx,state); 158 CRYPTO_set_ex_data(&ctx->ex_data, zlib_stateful_ex_idx, state);
158 return 1; 159 return 1;
159 err: 160
161err:
160 free(state); 162 free(state);
161 return 0; 163 return 0;
162 } 164}
163 165
164static void zlib_stateful_finish(COMP_CTX *ctx) 166static void
165 { 167zlib_stateful_finish(COMP_CTX *ctx)
168{
166 struct zlib_state *state = 169 struct zlib_state *state =
167 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data, 170 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
168 zlib_stateful_ex_idx); 171 zlib_stateful_ex_idx);
172
169 inflateEnd(&state->istream); 173 inflateEnd(&state->istream);
170 deflateEnd(&state->ostream); 174 deflateEnd(&state->ostream);
171 free(state); 175 free(state);
172 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data); 176 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
173 } 177}
174 178
175static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out, 179static int
176 unsigned int olen, unsigned char *in, unsigned int ilen) 180zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
177 { 181 unsigned int olen, unsigned char *in, unsigned int ilen)
182{
178 int err = Z_OK; 183 int err = Z_OK;
179 struct zlib_state *state = 184 struct zlib_state *state =
180 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data, 185 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
181 zlib_stateful_ex_idx); 186 zlib_stateful_ex_idx);
182 187
183 if (state == NULL) 188 if (state == NULL)
184 return -1; 189 return -1;
@@ -191,22 +196,25 @@ static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
191 err = deflate(&state->ostream, Z_SYNC_FLUSH); 196 err = deflate(&state->ostream, Z_SYNC_FLUSH);
192 if (err != Z_OK) 197 if (err != Z_OK)
193 return -1; 198 return -1;
199
194#ifdef DEBUG_ZLIB 200#ifdef DEBUG_ZLIB
195 fprintf(stderr,"compress(%4d)->%4d %s\n", 201 fprintf(stderr, "compress(%4d)->%4d %s\n",
196 ilen,olen - state->ostream.avail_out, 202 ilen, olen - state->ostream.avail_out,
197 (ilen != olen - state->ostream.avail_out)?"zlib":"clear"); 203 (ilen != olen - state->ostream.avail_out)?"zlib":"clear");
198#endif 204#endif
205
199 return olen - state->ostream.avail_out; 206 return olen - state->ostream.avail_out;
200 } 207}
201 208
202static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, 209static int
203 unsigned int olen, unsigned char *in, unsigned int ilen) 210zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
204 { 211 unsigned int olen, unsigned char *in, unsigned int ilen)
212{
205 int err = Z_OK; 213 int err = Z_OK;
206 214
207 struct zlib_state *state = 215 struct zlib_state *state =
208 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data, 216 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
209 zlib_stateful_ex_idx); 217 zlib_stateful_ex_idx);
210 218
211 if (state == NULL) 219 if (state == NULL)
212 return 0; 220 return 0;
@@ -219,194 +227,190 @@ static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
219 err = inflate(&state->istream, Z_SYNC_FLUSH); 227 err = inflate(&state->istream, Z_SYNC_FLUSH);
220 if (err != Z_OK) 228 if (err != Z_OK)
221 return -1; 229 return -1;
230
222#ifdef DEBUG_ZLIB 231#ifdef DEBUG_ZLIB
223 fprintf(stderr,"expand(%4d)->%4d %s\n", 232 fprintf(stderr, "expand(%4d)->%4d %s\n",
224 ilen,olen - state->istream.avail_out, 233 ilen, olen - state->istream.avail_out,
225 (ilen != olen - state->istream.avail_out)?"zlib":"clear"); 234 (ilen != olen - state->istream.avail_out)?"zlib":"clear");
226#endif 235#endif
236
227 return olen - state->istream.avail_out; 237 return olen - state->istream.avail_out;
228 } 238}
229 239
230#if 0 240#if 0
231static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, 241static int
232 unsigned int olen, unsigned char *in, unsigned int ilen) 242zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
233 { 243 unsigned int olen, unsigned char *in, unsigned int ilen)
244{
234 unsigned long l; 245 unsigned long l;
235 int i; 246 int i;
236 int clear=1; 247 int clear = 1;
237 248
238 if (ilen > 128) 249 if (ilen > 128) {
239 { 250 out[0] = 1;
240 out[0]=1; 251 l = olen - 1;
241 l=olen-1; 252 i = compress(&(out[1]), &l, in, (unsigned long)ilen);
242 i=compress(&(out[1]),&l,in,(unsigned long)ilen);
243 if (i != Z_OK) 253 if (i != Z_OK)
244 return(-1); 254 return (-1);
245 if (ilen > l) 255 if (ilen > l) {
246 { 256 clear = 0;
247 clear=0;
248 l++; 257 l++;
249 }
250 }
251 if (clear)
252 {
253 out[0]=0;
254 memcpy(&(out[1]),in,ilen);
255 l=ilen+1;
256 } 258 }
259 }
260 if (clear) {
261 out[0] = 0;
262 memcpy(&(out[1]), in, ilen);
263 l = ilen + 1;
264 }
265
257#ifdef DEBUG_ZLIB 266#ifdef DEBUG_ZLIB
258 fprintf(stderr,"compress(%4d)->%4d %s\n", 267 fprintf(stderr, "compress(%4d)->%4d %s\n",
259 ilen,(int)l,(clear)?"clear":"zlib"); 268 ilen,(int)l, (clear)?"clear":"zlib");
260#endif 269#endif
261 return((int)l);
262 }
263 270
264static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out, 271 return ((int)l);
265 unsigned int olen, unsigned char *in, unsigned int ilen) 272}
266 { 273
274static int
275zlib_expand_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
276 unsigned char *in, unsigned int ilen)
277{
267 unsigned long l; 278 unsigned long l;
268 int i; 279 int i;
269 280
270 if (in[0]) 281 if (in[0]) {
271 { 282 l = olen;
272 l=olen; 283 i = zz_uncompress(out, &l, &(in[1]), (unsigned long)ilen - 1);
273 i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
274 if (i != Z_OK) 284 if (i != Z_OK)
275 return(-1); 285 return (-1);
276 } 286 } else {
277 else 287 memcpy(out, &(in[1]), ilen - 1);
278 { 288 l = ilen - 1;
279 memcpy(out,&(in[1]),ilen-1); 289 }
280 l=ilen-1; 290
281 }
282#ifdef DEBUG_ZLIB 291#ifdef DEBUG_ZLIB
283 fprintf(stderr,"expand (%4d)->%4d %s\n", 292 fprintf(stderr, "expand (%4d)->%4d %s\n",
284 ilen,(int)l,in[0]?"zlib":"clear"); 293 ilen,(int)l, in[0]?"zlib":"clear");
285#endif 294#endif
286 return((int)l);
287 }
288 295
289static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, 296 return ((int)l);
290 uLong sourceLen) 297}
298
299static int
300zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
301 uLong sourceLen)
291{ 302{
292 z_stream stream; 303 z_stream stream;
293 int err; 304 int err;
294 305
295 stream.next_in = (Bytef*)source; 306 stream.next_in = (Bytef*)source;
296 stream.avail_in = (uInt)sourceLen; 307 stream.avail_in = (uInt)sourceLen;
297 /* Check for source > 64K on 16-bit machine: */ 308 /* Check for source > 64K on 16-bit machine: */
298 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 309 if ((uLong)stream.avail_in != sourceLen)
310 return Z_BUF_ERROR;
299 311
300 stream.next_out = dest; 312 stream.next_out = dest;
301 stream.avail_out = (uInt)*destLen; 313 stream.avail_out = (uInt)*destLen;
302 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 314 if ((uLong)stream.avail_out != *destLen)
315 return Z_BUF_ERROR;
303 316
304 stream.zalloc = (alloc_func)0; 317 stream.zalloc = (alloc_func)0;
305 stream.zfree = (free_func)0; 318 stream.zfree = (free_func)0;
306 319
307 err = inflateInit_(&stream, 320 err = inflateInit_(&stream, ZLIB_VERSION, sizeof(z_stream));
308 ZLIB_VERSION, sizeof(z_stream)); 321 if (err != Z_OK)
309 if (err != Z_OK) return err; 322 return err;
310 323
311 err = inflate(&stream, Z_FINISH); 324 err = inflate(&stream, Z_FINISH);
312 if (err != Z_STREAM_END) { 325 if (err != Z_STREAM_END) {
313 inflateEnd(&stream); 326 inflateEnd(&stream);
314 return err; 327 return err;
315 } 328 }
316 *destLen = stream.total_out; 329 *destLen = stream.total_out;
317 330
318 err = inflateEnd(&stream); 331 err = inflateEnd(&stream);
319 return err; 332 return err;
320} 333}
321#endif 334#endif
322 335
323#endif 336#endif
324 337
325COMP_METHOD *COMP_zlib(void) 338COMP_METHOD *
326 { 339COMP_zlib(void)
340{
327 COMP_METHOD *meth = &zlib_method_nozlib; 341 COMP_METHOD *meth = &zlib_method_nozlib;
328 342
329#ifdef ZLIB_SHARED 343#ifdef ZLIB_SHARED
330 if (!zlib_loaded) 344 if (!zlib_loaded) {
331 {
332 zlib_dso = DSO_load(NULL, "z", NULL, 0); 345 zlib_dso = DSO_load(NULL, "z", NULL, 0);
333 if (zlib_dso != NULL) 346 if (zlib_dso != NULL) {
334 { 347 p_compress = (compress_ft)DSO_bind_func(
335 p_compress 348 zlib_dso, "compress");
336 = (compress_ft) DSO_bind_func(zlib_dso, 349 p_inflateEnd = (inflateEnd_ft)DSO_bind_func(
337 "compress"); 350 zlib_dso, "inflateEnd");
338 p_inflateEnd 351 p_inflate = (inflate_ft)DSO_bind_func(
339 = (inflateEnd_ft) DSO_bind_func(zlib_dso, 352 zlib_dso, "inflate");
340 "inflateEnd"); 353 p_inflateInit_ = (inflateInit__ft)DSO_bind_func(
341 p_inflate 354 zlib_dso, "inflateInit_");
342 = (inflate_ft) DSO_bind_func(zlib_dso, 355 p_deflateEnd = (deflateEnd_ft)DSO_bind_func(
343 "inflate"); 356 zlib_dso, "deflateEnd");
344 p_inflateInit_ 357 p_deflate = (deflate_ft)DSO_bind_func(
345 = (inflateInit__ft) DSO_bind_func(zlib_dso, 358 zlib_dso, "deflate");
346 "inflateInit_"); 359 p_deflateInit_ = (deflateInit__ft)DSO_bind_func(
347 p_deflateEnd 360 zlib_dso, "deflateInit_");
348 = (deflateEnd_ft) DSO_bind_func(zlib_dso, 361 p_zError = (zError__ft)DSO_bind_func(
349 "deflateEnd"); 362 zlib_dso, "zError");
350 p_deflate 363
351 = (deflate_ft) DSO_bind_func(zlib_dso, 364 if (p_compress && p_inflateEnd && p_inflate &&
352 "deflate"); 365 p_inflateInit_ && p_deflateEnd && p_deflate &&
353 p_deflateInit_ 366 p_deflateInit_ && p_zError)
354 = (deflateInit__ft) DSO_bind_func(zlib_dso,
355 "deflateInit_");
356 p_zError
357 = (zError__ft) DSO_bind_func(zlib_dso,
358 "zError");
359
360 if (p_compress && p_inflateEnd && p_inflate
361 && p_inflateInit_ && p_deflateEnd
362 && p_deflate && p_deflateInit_ && p_zError)
363 zlib_loaded++; 367 zlib_loaded++;
364 }
365 } 368 }
369 }
366 370
367#endif 371#endif
368#ifdef ZLIB_SHARED 372#ifdef ZLIB_SHARED
369 if (zlib_loaded) 373 if (zlib_loaded)
370#endif 374#endif
371#if defined(ZLIB) || defined(ZLIB_SHARED) 375#if defined(ZLIB) || defined(ZLIB_SHARED)
372 { 376 {
373 /* init zlib_stateful_ex_idx here so that in a multi-process 377 /* init zlib_stateful_ex_idx here so that in a multi-process
374 * application it's enough to intialize openssl before forking 378 * application it's enough to intialize openssl before forking
375 * (idx will be inherited in all the children) */ 379 * (idx will be inherited in all the children) */
376 if (zlib_stateful_ex_idx == -1) 380 if (zlib_stateful_ex_idx == -1) {
377 {
378 CRYPTO_w_lock(CRYPTO_LOCK_COMP); 381 CRYPTO_w_lock(CRYPTO_LOCK_COMP);
379 if (zlib_stateful_ex_idx == -1) 382 if (zlib_stateful_ex_idx == -1)
380 zlib_stateful_ex_idx = 383 zlib_stateful_ex_idx =
381 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP, 384 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
382 0,NULL,NULL,NULL,NULL); 385 0, NULL, NULL, NULL, NULL);
383 CRYPTO_w_unlock(CRYPTO_LOCK_COMP); 386 CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
384 if (zlib_stateful_ex_idx == -1) 387 if (zlib_stateful_ex_idx == -1)
385 goto err; 388 goto err;
386 }
387
388 meth = &zlib_stateful_method;
389 } 389 }
390err:
391#endif
392 390
393 return(meth); 391 meth = &zlib_stateful_method;
394 } 392 }
395 393
396void COMP_zlib_cleanup(void) 394err:
397 { 395#endif
396
397 return (meth);
398}
399
400void
401COMP_zlib_cleanup(void)
402{
398#ifdef ZLIB_SHARED 403#ifdef ZLIB_SHARED
399 if (zlib_dso) 404 if (zlib_dso)
400 DSO_free(zlib_dso); 405 DSO_free(zlib_dso);
401#endif 406#endif
402 } 407}
403 408
404#ifdef ZLIB 409#ifdef ZLIB
405 410
406/* Zlib based compression/decompression filter BIO */ 411/* Zlib based compression/decompression filter BIO */
407 412
408typedef struct 413typedef struct {
409 {
410 unsigned char *ibuf; /* Input buffer */ 414 unsigned char *ibuf; /* Input buffer */
411 int ibufsize; /* Buffer size */ 415 int ibufsize; /* Buffer size */
412 z_stream zin; /* Input decompress context */ 416 z_stream zin; /* Input decompress context */
@@ -417,7 +421,7 @@ typedef struct
417 int odone; /* deflate EOF */ 421 int odone; /* deflate EOF */
418 int comp_level; /* Compression level to use */ 422 int comp_level; /* Compression level to use */
419 z_stream zout; /* Output compression context */ 423 z_stream zout; /* Output compression context */
420 } BIO_ZLIB_CTX; 424} BIO_ZLIB_CTX;
421 425
422#define ZLIB_DEFAULT_BUFSIZE 1024 426#define ZLIB_DEFAULT_BUFSIZE 1024
423 427
@@ -428,8 +432,7 @@ static int bio_zlib_write(BIO *b, const char *in, int inl);
428static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr); 432static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr);
429static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp); 433static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp);
430 434
431static BIO_METHOD bio_meth_zlib = 435static BIO_METHOD bio_meth_zlib = {
432 {
433 BIO_TYPE_COMP, 436 BIO_TYPE_COMP,
434 "zlib", 437 "zlib",
435 bio_zlib_write, 438 bio_zlib_write,
@@ -440,31 +443,32 @@ static BIO_METHOD bio_meth_zlib =
440 bio_zlib_new, 443 bio_zlib_new,
441 bio_zlib_free, 444 bio_zlib_free,
442 bio_zlib_callback_ctrl 445 bio_zlib_callback_ctrl
443 }; 446};
444 447
445BIO_METHOD *BIO_f_zlib(void) 448BIO_METHOD *
446 { 449BIO_f_zlib(void)
450{
447 return &bio_meth_zlib; 451 return &bio_meth_zlib;
448 } 452}
449 453
450 454
451static int bio_zlib_new(BIO *bi) 455static int
452 { 456bio_zlib_new(BIO *bi)
457{
453 BIO_ZLIB_CTX *ctx; 458 BIO_ZLIB_CTX *ctx;
459
454#ifdef ZLIB_SHARED 460#ifdef ZLIB_SHARED
455 (void)COMP_zlib(); 461 (void)COMP_zlib();
456 if (!zlib_loaded) 462 if (!zlib_loaded) {
457 {
458 COMPerr(COMP_F_BIO_ZLIB_NEW, COMP_R_ZLIB_NOT_SUPPORTED); 463 COMPerr(COMP_F_BIO_ZLIB_NEW, COMP_R_ZLIB_NOT_SUPPORTED);
459 return 0; 464 return 0;
460 } 465 }
461#endif 466#endif
462 ctx = malloc(sizeof(BIO_ZLIB_CTX)); 467 ctx = malloc(sizeof(BIO_ZLIB_CTX));
463 if(!ctx) 468 if (!ctx) {
464 {
465 COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE); 469 COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE);
466 return 0; 470 return 0;
467 } 471 }
468 ctx->ibuf = NULL; 472 ctx->ibuf = NULL;
469 ctx->obuf = NULL; 473 ctx->obuf = NULL;
470 ctx->ibufsize = ZLIB_DEFAULT_BUFSIZE; 474 ctx->ibufsize = ZLIB_DEFAULT_BUFSIZE;
@@ -487,140 +491,140 @@ static int bio_zlib_new(BIO *bi)
487 bi->ptr = (char *)ctx; 491 bi->ptr = (char *)ctx;
488 bi->flags = 0; 492 bi->flags = 0;
489 return 1; 493 return 1;
490 } 494}
491 495
492static int bio_zlib_free(BIO *bi) 496static int
493 { 497bio_zlib_free(BIO *bi)
498{
494 BIO_ZLIB_CTX *ctx; 499 BIO_ZLIB_CTX *ctx;
495 if(!bi) return 0; 500
501 if (!bi)
502 return 0;
496 ctx = (BIO_ZLIB_CTX *)bi->ptr; 503 ctx = (BIO_ZLIB_CTX *)bi->ptr;
497 if(ctx->ibuf) 504 if (ctx->ibuf) {
498 {
499 /* Destroy decompress context */ 505 /* Destroy decompress context */
500 inflateEnd(&ctx->zin); 506 inflateEnd(&ctx->zin);
501 free(ctx->ibuf); 507 free(ctx->ibuf);
502 } 508 }
503 if(ctx->obuf) 509 if (ctx->obuf) {
504 {
505 /* Destroy compress context */ 510 /* Destroy compress context */
506 deflateEnd(&ctx->zout); 511 deflateEnd(&ctx->zout);
507 free(ctx->obuf); 512 free(ctx->obuf);
508 } 513 }
509 free(ctx); 514 free(ctx);
510 bi->ptr = NULL; 515 bi->ptr = NULL;
511 bi->init = 0; 516 bi->init = 0;
512 bi->flags = 0; 517 bi->flags = 0;
513 return 1; 518 return 1;
514 } 519}
515 520
516static int bio_zlib_read(BIO *b, char *out, int outl) 521static int
517 { 522bio_zlib_read(BIO *b, char *out, int outl)
523{
518 BIO_ZLIB_CTX *ctx; 524 BIO_ZLIB_CTX *ctx;
519 int ret; 525 int ret;
520 z_stream *zin; 526 z_stream *zin;
521 if(!out || !outl) return 0; 527
528 if (!out || !outl)
529 return 0;
522 ctx = (BIO_ZLIB_CTX *)b->ptr; 530 ctx = (BIO_ZLIB_CTX *)b->ptr;
523 zin = &ctx->zin; 531 zin = &ctx->zin;
524 BIO_clear_retry_flags(b); 532 BIO_clear_retry_flags(b);
525 if(!ctx->ibuf) 533 if (!ctx->ibuf) {
526 {
527 ctx->ibuf = malloc(ctx->ibufsize); 534 ctx->ibuf = malloc(ctx->ibufsize);
528 if(!ctx->ibuf) 535 if (!ctx->ibuf) {
529 {
530 COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE); 536 COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE);
531 return 0; 537 return 0;
532 } 538 }
533 inflateInit(zin); 539 inflateInit(zin);
534 zin->next_in = ctx->ibuf; 540 zin->next_in = ctx->ibuf;
535 zin->avail_in = 0; 541 zin->avail_in = 0;
536 } 542 }
537 543
538 /* Copy output data directly to supplied buffer */ 544 /* Copy output data directly to supplied buffer */
539 zin->next_out = (unsigned char *)out; 545 zin->next_out = (unsigned char *)out;
540 zin->avail_out = (unsigned int)outl; 546 zin->avail_out = (unsigned int)outl;
541 for(;;) 547 for (;;) {
542 {
543 /* Decompress while data available */ 548 /* Decompress while data available */
544 while(zin->avail_in) 549 while (zin->avail_in) {
545 {
546 ret = inflate(zin, 0); 550 ret = inflate(zin, 0);
547 if((ret != Z_OK) && (ret != Z_STREAM_END)) 551 if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
548 {
549 COMPerr(COMP_F_BIO_ZLIB_READ, 552 COMPerr(COMP_F_BIO_ZLIB_READ,
550 COMP_R_ZLIB_INFLATE_ERROR); 553 COMP_R_ZLIB_INFLATE_ERROR);
551 ERR_add_error_data(2, "zlib error:", 554 ERR_add_error_data(2, "zlib error:",
552 zError(ret)); 555 zError(ret));
553 return 0; 556 return 0;
554 } 557 }
555 /* If EOF or we've read everything then return */ 558 /* If EOF or we've read everything then return */
556 if((ret == Z_STREAM_END) || !zin->avail_out) 559 if ((ret == Z_STREAM_END) || !zin->avail_out)
557 return outl - zin->avail_out; 560 return outl - zin->avail_out;
558 } 561 }
559 562
560 /* No data in input buffer try to read some in, 563 /* No data in input buffer try to read some in,
561 * if an error then return the total data read. 564 * if an error then return the total data read.
562 */ 565 */
563 ret = BIO_read(b->next_bio, ctx->ibuf, ctx->ibufsize); 566 ret = BIO_read(b->next_bio, ctx->ibuf, ctx->ibufsize);
564 if(ret <= 0) 567 if (ret <= 0) {
565 {
566 /* Total data read */ 568 /* Total data read */
567 int tot = outl - zin->avail_out; 569 int tot = outl - zin->avail_out;
568 BIO_copy_next_retry(b); 570 BIO_copy_next_retry(b);
569 if(ret < 0) return (tot > 0) ? tot : ret; 571 if (ret < 0)
572 return (tot > 0) ? tot : ret;
570 return tot; 573 return tot;
571 } 574 }
572 zin->avail_in = ret; 575 zin->avail_in = ret;
573 zin->next_in = ctx->ibuf; 576 zin->next_in = ctx->ibuf;
574 }
575 } 577 }
578}
576 579
577static int bio_zlib_write(BIO *b, const char *in, int inl) 580static int
578 { 581bio_zlib_write(BIO *b, const char *in, int inl)
582{
579 BIO_ZLIB_CTX *ctx; 583 BIO_ZLIB_CTX *ctx;
580 int ret; 584 int ret;
581 z_stream *zout; 585 z_stream *zout;
582 if(!in || !inl) return 0; 586
587 if (!in || !inl)
588 return 0;
583 ctx = (BIO_ZLIB_CTX *)b->ptr; 589 ctx = (BIO_ZLIB_CTX *)b->ptr;
584 if(ctx->odone) return 0; 590 if (ctx->odone)
591 return 0;
585 zout = &ctx->zout; 592 zout = &ctx->zout;
586 BIO_clear_retry_flags(b); 593 BIO_clear_retry_flags(b);
587 if(!ctx->obuf) 594 if (!ctx->obuf) {
588 {
589 ctx->obuf = malloc(ctx->obufsize); 595 ctx->obuf = malloc(ctx->obufsize);
590 /* Need error here */ 596 /* Need error here */
591 if(!ctx->obuf) 597 if (!ctx->obuf) {
592 {
593 COMPerr(COMP_F_BIO_ZLIB_WRITE, ERR_R_MALLOC_FAILURE); 598 COMPerr(COMP_F_BIO_ZLIB_WRITE, ERR_R_MALLOC_FAILURE);
594 return 0; 599 return 0;
595 } 600 }
596 ctx->optr = ctx->obuf; 601 ctx->optr = ctx->obuf;
597 ctx->ocount = 0; 602 ctx->ocount = 0;
598 deflateInit(zout, ctx->comp_level); 603 deflateInit(zout, ctx->comp_level);
599 zout->next_out = ctx->obuf; 604 zout->next_out = ctx->obuf;
600 zout->avail_out = ctx->obufsize; 605 zout->avail_out = ctx->obufsize;
601 } 606 }
602 /* Obtain input data directly from supplied buffer */ 607 /* Obtain input data directly from supplied buffer */
603 zout->next_in = (void *)in; 608 zout->next_in = (void *)in;
604 zout->avail_in = inl; 609 zout->avail_in = inl;
605 for(;;) 610 for (;;) {
606 {
607 /* If data in output buffer write it first */ 611 /* If data in output buffer write it first */
608 while(ctx->ocount) { 612 while (ctx->ocount) {
609 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount); 613 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
610 if(ret <= 0) 614 if (ret <= 0) {
611 {
612 /* Total data written */ 615 /* Total data written */
613 int tot = inl - zout->avail_in; 616 int tot = inl - zout->avail_in;
614 BIO_copy_next_retry(b); 617 BIO_copy_next_retry(b);
615 if(ret < 0) return (tot > 0) ? tot : ret; 618 if (ret < 0)
619 return (tot > 0) ? tot : ret;
616 return tot; 620 return tot;
617 } 621 }
618 ctx->optr += ret; 622 ctx->optr += ret;
619 ctx->ocount -= ret; 623 ctx->ocount -= ret;
620 } 624 }
621 625
622 /* Have we consumed all supplied data? */ 626 /* Have we consumed all supplied data? */
623 if(!zout->avail_in) 627 if (!zout->avail_in)
624 return inl; 628 return inl;
625 629
626 /* Compress some more */ 630 /* Compress some more */
@@ -631,45 +635,45 @@ static int bio_zlib_write(BIO *b, const char *in, int inl)
631 zout->avail_out = ctx->obufsize; 635 zout->avail_out = ctx->obufsize;
632 /* Compress some more */ 636 /* Compress some more */
633 ret = deflate(zout, 0); 637 ret = deflate(zout, 0);
634 if(ret != Z_OK) 638 if (ret != Z_OK) {
635 {
636 COMPerr(COMP_F_BIO_ZLIB_WRITE, 639 COMPerr(COMP_F_BIO_ZLIB_WRITE,
637 COMP_R_ZLIB_DEFLATE_ERROR); 640 COMP_R_ZLIB_DEFLATE_ERROR);
638 ERR_add_error_data(2, "zlib error:", zError(ret)); 641 ERR_add_error_data(2, "zlib error:", zError(ret));
639 return 0; 642 return 0;
640 }
641 ctx->ocount = ctx->obufsize - zout->avail_out;
642 } 643 }
644 ctx->ocount = ctx->obufsize - zout->avail_out;
643 } 645 }
646}
644 647
645static int bio_zlib_flush(BIO *b) 648static int
646 { 649bio_zlib_flush(BIO *b)
650{
647 BIO_ZLIB_CTX *ctx; 651 BIO_ZLIB_CTX *ctx;
648 int ret; 652 int ret;
649 z_stream *zout; 653 z_stream *zout;
654
650 ctx = (BIO_ZLIB_CTX *)b->ptr; 655 ctx = (BIO_ZLIB_CTX *)b->ptr;
651 /* If no data written or already flush show success */ 656 /* If no data written or already flush show success */
652 if(!ctx->obuf || (ctx->odone && !ctx->ocount)) return 1; 657 if (!ctx->obuf || (ctx->odone && !ctx->ocount))
658 return 1;
653 zout = &ctx->zout; 659 zout = &ctx->zout;
654 BIO_clear_retry_flags(b); 660 BIO_clear_retry_flags(b);
655 /* No more input data */ 661 /* No more input data */
656 zout->next_in = NULL; 662 zout->next_in = NULL;
657 zout->avail_in = 0; 663 zout->avail_in = 0;
658 for(;;) 664 for (;;) {
659 {
660 /* If data in output buffer write it first */ 665 /* If data in output buffer write it first */
661 while(ctx->ocount) 666 while (ctx->ocount) {
662 {
663 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount); 667 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
664 if(ret <= 0) 668 if (ret <= 0) {
665 {
666 BIO_copy_next_retry(b); 669 BIO_copy_next_retry(b);
667 return ret; 670 return ret;
668 } 671 }
669 ctx->optr += ret; 672 ctx->optr += ret;
670 ctx->ocount -= ret; 673 ctx->ocount -= ret;
671 } 674 }
672 if(ctx->odone) return 1; 675 if (ctx->odone)
676 return 1;
673 677
674 /* Compress some more */ 678 /* Compress some more */
675 679
@@ -679,27 +683,28 @@ static int bio_zlib_flush(BIO *b)
679 zout->avail_out = ctx->obufsize; 683 zout->avail_out = ctx->obufsize;
680 /* Compress some more */ 684 /* Compress some more */
681 ret = deflate(zout, Z_FINISH); 685 ret = deflate(zout, Z_FINISH);
682 if(ret == Z_STREAM_END) ctx->odone = 1; 686 if (ret == Z_STREAM_END)
683 else if(ret != Z_OK) 687 ctx->odone = 1;
684 { 688 else if (ret != Z_OK) {
685 COMPerr(COMP_F_BIO_ZLIB_FLUSH, 689 COMPerr(COMP_F_BIO_ZLIB_FLUSH,
686 COMP_R_ZLIB_DEFLATE_ERROR); 690 COMP_R_ZLIB_DEFLATE_ERROR);
687 ERR_add_error_data(2, "zlib error:", zError(ret)); 691 ERR_add_error_data(2, "zlib error:", zError(ret));
688 return 0; 692 return 0;
689 }
690 ctx->ocount = ctx->obufsize - zout->avail_out;
691 } 693 }
694 ctx->ocount = ctx->obufsize - zout->avail_out;
692 } 695 }
696}
693 697
694static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr) 698static long
695 { 699bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
700{
696 BIO_ZLIB_CTX *ctx; 701 BIO_ZLIB_CTX *ctx;
697 int ret, *ip; 702 int ret, *ip;
698 int ibs, obs; 703 int ibs, obs;
699 if(!b->next_bio) return 0; 704 if (!b->next_bio)
705 return 0;
700 ctx = (BIO_ZLIB_CTX *)b->ptr; 706 ctx = (BIO_ZLIB_CTX *)b->ptr;
701 switch (cmd) 707 switch (cmd) {
702 {
703 708
704 case BIO_CTRL_RESET: 709 case BIO_CTRL_RESET:
705 ctx->ocount = 0; 710 ctx->ocount = 0;
@@ -716,39 +721,32 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
716 case BIO_C_SET_BUFF_SIZE: 721 case BIO_C_SET_BUFF_SIZE:
717 ibs = -1; 722 ibs = -1;
718 obs = -1; 723 obs = -1;
719 if (ptr != NULL) 724 if (ptr != NULL) {
720 {
721 ip = ptr; 725 ip = ptr;
722 if (*ip == 0) 726 if (*ip == 0)
723 ibs = (int) num; 727 ibs = (int) num;
724 else 728 else
725 obs = (int) num; 729 obs = (int) num;
726 } 730 } else {
727 else
728 {
729 ibs = (int)num; 731 ibs = (int)num;
730 obs = ibs; 732 obs = ibs;
731 } 733 }
732 734
733 if (ibs != -1) 735 if (ibs != -1) {
734 { 736 if (ctx->ibuf) {
735 if (ctx->ibuf)
736 {
737 free(ctx->ibuf); 737 free(ctx->ibuf);
738 ctx->ibuf = NULL; 738 ctx->ibuf = NULL;
739 }
740 ctx->ibufsize = ibs;
741 } 739 }
740 ctx->ibufsize = ibs;
741 }
742 742
743 if (obs != -1) 743 if (obs != -1) {
744 { 744 if (ctx->obuf) {
745 if (ctx->obuf)
746 {
747 free(ctx->obuf); 745 free(ctx->obuf);
748 ctx->obuf = NULL; 746 ctx->obuf = NULL;
749 }
750 ctx->obufsize = obs;
751 } 747 }
748 ctx->obufsize = obs;
749 }
752 ret = 1; 750 ret = 1;
753 break; 751 break;
754 752
@@ -762,18 +760,18 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
762 ret = BIO_ctrl(b->next_bio, cmd, num, ptr); 760 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
763 break; 761 break;
764 762
765 } 763 }
766 764
767 return ret; 765 return ret;
768 } 766}
769 767
770 768
771static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 769static long
772 { 770bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
773 if(!b->next_bio) 771{
772 if (!b->next_bio)
774 return 0; 773 return 0;
775 return 774 return BIO_callback_ctrl(b->next_bio, cmd, fp);
776 BIO_callback_ctrl(b->next_bio, cmd, fp); 775}
777 }
778 776
779#endif 777#endif
diff --git a/src/lib/libcrypto/comp/comp.h b/src/lib/libcrypto/comp/comp.h
index 4b405c7d49..0f7d2da336 100644
--- a/src/lib/libcrypto/comp/comp.h
+++ b/src/lib/libcrypto/comp/comp.h
@@ -10,25 +10,21 @@ extern "C" {
10 10
11typedef struct comp_ctx_st COMP_CTX; 11typedef struct comp_ctx_st COMP_CTX;
12 12
13typedef struct comp_method_st 13typedef struct comp_method_st {
14 {
15 int type; /* NID for compression library */ 14 int type; /* NID for compression library */
16 const char *name; /* A text string to identify the library */ 15 const char *name; /* A text string to identify the library */
17 int (*init)(COMP_CTX *ctx); 16 int (*init)(COMP_CTX *ctx);
18 void (*finish)(COMP_CTX *ctx); 17 void (*finish)(COMP_CTX *ctx);
19 int (*compress)(COMP_CTX *ctx, 18 int (*compress)(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
20 unsigned char *out, unsigned int olen, 19 unsigned char *in, unsigned int ilen);
21 unsigned char *in, unsigned int ilen); 20 int (*expand)(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
22 int (*expand)(COMP_CTX *ctx, 21 unsigned char *in, unsigned int ilen);
23 unsigned char *out, unsigned int olen,
24 unsigned char *in, unsigned int ilen);
25 /* The following two do NOTHING, but are kept for backward compatibility */ 22 /* The following two do NOTHING, but are kept for backward compatibility */
26 long (*ctrl)(void); 23 long (*ctrl)(void);
27 long (*callback_ctrl)(void); 24 long (*callback_ctrl)(void);
28 } COMP_METHOD; 25} COMP_METHOD;
29 26
30struct comp_ctx_st 27struct comp_ctx_st {
31 {
32 COMP_METHOD *meth; 28 COMP_METHOD *meth;
33 unsigned long compress_in; 29 unsigned long compress_in;
34 unsigned long compress_out; 30 unsigned long compress_out;
@@ -36,15 +32,15 @@ struct comp_ctx_st
36 unsigned long expand_out; 32 unsigned long expand_out;
37 33
38 CRYPTO_EX_DATA ex_data; 34 CRYPTO_EX_DATA ex_data;
39 }; 35};
40 36
41 37
42COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); 38COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
43void COMP_CTX_free(COMP_CTX *ctx); 39void COMP_CTX_free(COMP_CTX *ctx);
44int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, 40int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
45 unsigned char *in, int ilen); 41 unsigned char *in, int ilen);
46int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, 42int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
47 unsigned char *in, int ilen); 43 unsigned char *in, int ilen);
48COMP_METHOD *COMP_rle(void ); 44COMP_METHOD *COMP_rle(void );
49COMP_METHOD *COMP_zlib(void ); 45COMP_METHOD *COMP_zlib(void );
50void COMP_zlib_cleanup(void); 46void COMP_zlib_cleanup(void);
diff --git a/src/lib/libcrypto/comp/comp_err.c b/src/lib/libcrypto/comp/comp_err.c
index 661c94c3a4..982c58567a 100644
--- a/src/lib/libcrypto/comp/comp_err.c
+++ b/src/lib/libcrypto/comp/comp_err.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -68,33 +68,30 @@
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_COMP,func,0) 68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_COMP,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_COMP,0,reason) 69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_COMP,0,reason)
70 70
71static ERR_STRING_DATA COMP_str_functs[]= 71static ERR_STRING_DATA COMP_str_functs[] = {
72 { 72 {ERR_FUNC(COMP_F_BIO_ZLIB_FLUSH), "BIO_ZLIB_FLUSH"},
73{ERR_FUNC(COMP_F_BIO_ZLIB_FLUSH), "BIO_ZLIB_FLUSH"}, 73 {ERR_FUNC(COMP_F_BIO_ZLIB_NEW), "BIO_ZLIB_NEW"},
74{ERR_FUNC(COMP_F_BIO_ZLIB_NEW), "BIO_ZLIB_NEW"}, 74 {ERR_FUNC(COMP_F_BIO_ZLIB_READ), "BIO_ZLIB_READ"},
75{ERR_FUNC(COMP_F_BIO_ZLIB_READ), "BIO_ZLIB_READ"}, 75 {ERR_FUNC(COMP_F_BIO_ZLIB_WRITE), "BIO_ZLIB_WRITE"},
76{ERR_FUNC(COMP_F_BIO_ZLIB_WRITE), "BIO_ZLIB_WRITE"}, 76 {0, NULL}
77{0,NULL} 77};
78 };
79 78
80static ERR_STRING_DATA COMP_str_reasons[]= 79static ERR_STRING_DATA COMP_str_reasons[] = {
81 { 80 {ERR_REASON(COMP_R_ZLIB_DEFLATE_ERROR) , "zlib deflate error"},
82{ERR_REASON(COMP_R_ZLIB_DEFLATE_ERROR) ,"zlib deflate error"}, 81 {ERR_REASON(COMP_R_ZLIB_INFLATE_ERROR) , "zlib inflate error"},
83{ERR_REASON(COMP_R_ZLIB_INFLATE_ERROR) ,"zlib inflate error"}, 82 {ERR_REASON(COMP_R_ZLIB_NOT_SUPPORTED) , "zlib not supported"},
84{ERR_REASON(COMP_R_ZLIB_NOT_SUPPORTED) ,"zlib not supported"}, 83 {0, NULL}
85{0,NULL} 84};
86 };
87 85
88#endif 86#endif
89 87
90void ERR_load_COMP_strings(void) 88void
91 { 89ERR_load_COMP_strings(void)
90{
92#ifndef OPENSSL_NO_ERR 91#ifndef OPENSSL_NO_ERR
93 92 if (ERR_func_error_string(COMP_str_functs[0].error) == NULL) {
94 if (ERR_func_error_string(COMP_str_functs[0].error) == NULL) 93 ERR_load_strings(0, COMP_str_functs);
95 { 94 ERR_load_strings(0, COMP_str_reasons);
96 ERR_load_strings(0,COMP_str_functs);
97 ERR_load_strings(0,COMP_str_reasons);
98 }
99#endif
100 } 95 }
96#endif
97}
diff --git a/src/lib/libcrypto/comp/comp_lib.c b/src/lib/libcrypto/comp/comp_lib.c
index feb07ea881..745c802228 100644
--- a/src/lib/libcrypto/comp/comp_lib.c
+++ b/src/lib/libcrypto/comp/comp_lib.c
@@ -4,69 +4,68 @@
4#include <openssl/objects.h> 4#include <openssl/objects.h>
5#include <openssl/comp.h> 5#include <openssl/comp.h>
6 6
7COMP_CTX *COMP_CTX_new(COMP_METHOD *meth) 7COMP_CTX *
8 { 8COMP_CTX_new(COMP_METHOD *meth)
9{
9 COMP_CTX *ret; 10 COMP_CTX *ret;
10 11
11 if ((ret=(COMP_CTX *)malloc(sizeof(COMP_CTX))) == NULL) 12 if ((ret = (COMP_CTX *)malloc(sizeof(COMP_CTX))) == NULL) {
12 {
13 /* ZZZZZZZZZZZZZZZZ */ 13 /* ZZZZZZZZZZZZZZZZ */
14 return(NULL); 14 return (NULL);
15 } 15 }
16 memset(ret,0,sizeof(COMP_CTX)); 16 memset(ret, 0, sizeof(COMP_CTX));
17 ret->meth=meth; 17 ret->meth = meth;
18 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) 18 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
19 {
20 free(ret); 19 free(ret);
21 ret=NULL; 20 ret = NULL;
22 }
23 return(ret);
24 } 21 }
22 return (ret);
23}
25 24
26void COMP_CTX_free(COMP_CTX *ctx) 25void
27 { 26COMP_CTX_free(COMP_CTX *ctx)
28 if(ctx == NULL) 27{
29 return; 28 if (ctx == NULL)
29 return;
30 30
31 if (ctx->meth->finish != NULL) 31 if (ctx->meth->finish != NULL)
32 ctx->meth->finish(ctx); 32 ctx->meth->finish(ctx);
33 33
34 free(ctx); 34 free(ctx);
35 } 35}
36 36
37int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, 37int
38 unsigned char *in, int ilen) 38COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
39 { 39 unsigned char *in, int ilen)
40{
40 int ret; 41 int ret;
41 if (ctx->meth->compress == NULL) 42
42 { 43 if (ctx->meth->compress == NULL) {
43 /* ZZZZZZZZZZZZZZZZZ */ 44 /* ZZZZZZZZZZZZZZZZZ */
44 return(-1); 45 return (-1);
45 }
46 ret=ctx->meth->compress(ctx,out,olen,in,ilen);
47 if (ret > 0)
48 {
49 ctx->compress_in+=ilen;
50 ctx->compress_out+=ret;
51 }
52 return(ret);
53 } 46 }
47 ret = ctx->meth->compress(ctx, out, olen, in, ilen);
48 if (ret > 0) {
49 ctx->compress_in += ilen;
50 ctx->compress_out += ret;
51 }
52 return (ret);
53}
54 54
55int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, 55int
56 unsigned char *in, int ilen) 56COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
57 { 57 unsigned char *in, int ilen)
58{
58 int ret; 59 int ret;
59 60
60 if (ctx->meth->expand == NULL) 61 if (ctx->meth->expand == NULL) {
61 {
62 /* ZZZZZZZZZZZZZZZZZ */ 62 /* ZZZZZZZZZZZZZZZZZ */
63 return(-1); 63 return (-1);
64 } 64 }
65 ret=ctx->meth->expand(ctx,out,olen,in,ilen); 65 ret = ctx->meth->expand(ctx, out, olen, in, ilen);
66 if (ret > 0) 66 if (ret > 0) {
67 { 67 ctx->expand_in += ilen;
68 ctx->expand_in+=ilen; 68 ctx->expand_out += ret;
69 ctx->expand_out+=ret;
70 }
71 return(ret);
72 } 69 }
70 return (ret);
71}
diff --git a/src/lib/libssl/src/crypto/comp/c_rle.c b/src/lib/libssl/src/crypto/comp/c_rle.c
index 47dfb67fbd..7a5db298c5 100644
--- a/src/lib/libssl/src/crypto/comp/c_rle.c
+++ b/src/lib/libssl/src/crypto/comp/c_rle.c
@@ -5,11 +5,11 @@
5#include <openssl/comp.h> 5#include <openssl/comp.h>
6 6
7static int rle_compress_block(COMP_CTX *ctx, unsigned char *out, 7static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
8 unsigned int olen, unsigned char *in, unsigned int ilen); 8 unsigned int olen, unsigned char *in, unsigned int ilen);
9static int rle_expand_block(COMP_CTX *ctx, unsigned char *out, 9static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
10 unsigned int olen, unsigned char *in, unsigned int ilen); 10 unsigned int olen, unsigned char *in, unsigned int ilen);
11 11
12static COMP_METHOD rle_method={ 12static COMP_METHOD rle_method = {
13 NID_rle_compression, 13 NID_rle_compression,
14 LN_rle_compression, 14 LN_rle_compression,
15 NULL, 15 NULL,
@@ -18,44 +18,44 @@ static COMP_METHOD rle_method={
18 rle_expand_block, 18 rle_expand_block,
19 NULL, 19 NULL,
20 NULL, 20 NULL,
21 }; 21};
22 22
23COMP_METHOD *COMP_rle(void) 23COMP_METHOD *
24 { 24COMP_rle(void)
25 return(&rle_method); 25{
26 } 26 return (&rle_method);
27 27}
28static int rle_compress_block(COMP_CTX *ctx, unsigned char *out, 28
29 unsigned int olen, unsigned char *in, unsigned int ilen) 29static int
30 { 30rle_compress_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
31 unsigned char *in, unsigned int ilen)
32{
31 /* int i; */ 33 /* int i; */
32 34
33 if (ilen == 0 || olen < (ilen-1)) 35 if (ilen == 0 || olen < (ilen - 1)) {
34 {
35 /* ZZZZZZZZZZZZZZZZZZZZZZ */ 36 /* ZZZZZZZZZZZZZZZZZZZZZZ */
36 return(-1); 37 return (-1);
37 }
38
39 *(out++)=0;
40 memcpy(out,in,ilen);
41 return(ilen+1);
42 } 38 }
43 39
44static int rle_expand_block(COMP_CTX *ctx, unsigned char *out, 40 *(out++) = 0;
45 unsigned int olen, unsigned char *in, unsigned int ilen) 41 memcpy(out, in, ilen);
46 { 42 return (ilen + 1);
43}
44
45static int
46rle_expand_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
47 unsigned char *in, unsigned int ilen)
48{
47 int i; 49 int i;
48 50
49 if (olen < (ilen-1)) 51 if (olen < (ilen - 1)) {
50 {
51 /* ZZZZZZZZZZZZZZZZZZZZZZ */ 52 /* ZZZZZZZZZZZZZZZZZZZZZZ */
52 return(-1); 53 return (-1);
53 } 54 }
54 55
55 i= *(in++); 56 i= *(in++);
56 if (i == 0) 57 if (i == 0) {
57 { 58 memcpy(out, in, ilen - 1);
58 memcpy(out,in,ilen-1);
59 }
60 return(ilen-1);
61 } 59 }
60 return (ilen - 1);
61}
diff --git a/src/lib/libssl/src/crypto/comp/c_zlib.c b/src/lib/libssl/src/crypto/comp/c_zlib.c
index e50b6eb4a3..aaf89429b6 100644
--- a/src/lib/libssl/src/crypto/comp/c_zlib.c
+++ b/src/lib/libssl/src/crypto/comp/c_zlib.c
@@ -7,7 +7,7 @@
7 7
8COMP_METHOD *COMP_zlib(void ); 8COMP_METHOD *COMP_zlib(void );
9 9
10static COMP_METHOD zlib_method_nozlib={ 10static COMP_METHOD zlib_method_nozlib = {
11 NID_undef, 11 NID_undef,
12 "(undef)", 12 "(undef)",
13 NULL, 13 NULL,
@@ -16,7 +16,7 @@ static COMP_METHOD zlib_method_nozlib={
16 NULL, 16 NULL,
17 NULL, 17 NULL,
18 NULL, 18 NULL,
19 }; 19};
20 20
21#ifndef ZLIB 21#ifndef ZLIB
22#undef ZLIB_SHARED 22#undef ZLIB_SHARED
@@ -27,32 +27,34 @@ static COMP_METHOD zlib_method_nozlib={
27static int zlib_stateful_init(COMP_CTX *ctx); 27static int zlib_stateful_init(COMP_CTX *ctx);
28static void zlib_stateful_finish(COMP_CTX *ctx); 28static void zlib_stateful_finish(COMP_CTX *ctx);
29static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out, 29static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
30 unsigned int olen, unsigned char *in, unsigned int ilen); 30 unsigned int olen, unsigned char *in, unsigned int ilen);
31static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, 31static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
32 unsigned int olen, unsigned char *in, unsigned int ilen); 32 unsigned int olen, unsigned char *in, unsigned int ilen);
33 33
34 34
35/* memory allocations functions for zlib intialization */ 35/* memory allocations functions for zlib intialization */
36static void* zlib_zalloc(void* opaque, unsigned int no, unsigned int size) 36static void*
37zlib_zalloc(void* opaque, unsigned int no, unsigned int size)
37{ 38{
38 return calloc(no, size); 39 return calloc(no, size);
39} 40}
40 41
41static void zlib_zfree(void* opaque, void* address) 42static void
43zlib_zfree(void* opaque, void* address)
42{ 44{
43 free(address); 45 free(address);
44} 46}
45 47
46#if 0 48#if 0
47static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, 49static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
48 unsigned int olen, unsigned char *in, unsigned int ilen); 50 unsigned int olen, unsigned char *in, unsigned int ilen);
49static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out, 51static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
50 unsigned int olen, unsigned char *in, unsigned int ilen); 52 unsigned int olen, unsigned char *in, unsigned int ilen);
51 53
52static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, 54static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
53 uLong sourceLen); 55 uLong sourceLen);
54 56
55static COMP_METHOD zlib_stateless_method={ 57static COMP_METHOD zlib_stateless_method = {
56 NID_zlib_compression, 58 NID_zlib_compression,
57 LN_zlib_compression, 59 LN_zlib_compression,
58 NULL, 60 NULL,
@@ -61,10 +63,10 @@ static COMP_METHOD zlib_stateless_method={
61 zlib_expand_block, 63 zlib_expand_block,
62 NULL, 64 NULL,
63 NULL, 65 NULL,
64 }; 66};
65#endif 67#endif
66 68
67static COMP_METHOD zlib_stateful_method={ 69static COMP_METHOD zlib_stateful_method = {
68 NID_zlib_compression, 70 NID_zlib_compression,
69 LN_zlib_compression, 71 LN_zlib_compression,
70 zlib_stateful_init, 72 zlib_stateful_init,
@@ -73,31 +75,31 @@ static COMP_METHOD zlib_stateful_method={
73 zlib_stateful_expand_block, 75 zlib_stateful_expand_block,
74 NULL, 76 NULL,
75 NULL, 77 NULL,
76 }; 78};
77 79
78#ifdef ZLIB_SHARED 80#ifdef ZLIB_SHARED
79#include <openssl/dso.h> 81#include <openssl/dso.h>
80 82
81/* Function pointers */ 83/* Function pointers */
82typedef int (*compress_ft)(Bytef *dest,uLongf *destLen, 84typedef int (*compress_ft)(Bytef *dest, uLongf *destLen, const Bytef *source,
83 const Bytef *source, uLong sourceLen); 85 uLong sourceLen);
84typedef int (*inflateEnd_ft)(z_streamp strm); 86typedef int (*inflateEnd_ft)(z_streamp strm);
85typedef int (*inflate_ft)(z_streamp strm, int flush); 87typedef int (*inflate_ft)(z_streamp strm, int flush);
86typedef int (*inflateInit__ft)(z_streamp strm, 88typedef int (*inflateInit__ft)(z_streamp strm, const char * version,
87 const char * version, int stream_size); 89 int stream_size);
88typedef int (*deflateEnd_ft)(z_streamp strm); 90typedef int (*deflateEnd_ft)(z_streamp strm);
89typedef int (*deflate_ft)(z_streamp strm, int flush); 91typedef int (*deflate_ft)(z_streamp strm, int flush);
90typedef int (*deflateInit__ft)(z_streamp strm, int level, 92typedef int (*deflateInit__ft)(z_streamp strm, int level, const char * version,
91 const char * version, int stream_size); 93 int stream_size);
92typedef const char * (*zError__ft)(int err); 94typedef const char * (*zError__ft)(int err);
93static compress_ft p_compress=NULL; 95static compress_ft p_compress = NULL;
94static inflateEnd_ft p_inflateEnd=NULL; 96static inflateEnd_ft p_inflateEnd = NULL;
95static inflate_ft p_inflate=NULL; 97static inflate_ft p_inflate = NULL;
96static inflateInit__ft p_inflateInit_=NULL; 98static inflateInit__ft p_inflateInit_ = NULL;
97static deflateEnd_ft p_deflateEnd=NULL; 99static deflateEnd_ft p_deflateEnd = NULL;
98static deflate_ft p_deflate=NULL; 100static deflate_ft p_deflate = NULL;
99static deflateInit__ft p_deflateInit_=NULL; 101static deflateInit__ft p_deflateInit_ = NULL;
100static zError__ft p_zError=NULL; 102static zError__ft p_zError = NULL;
101 103
102static int zlib_loaded = 0; /* only attempt to init func pts once */ 104static int zlib_loaded = 0; /* only attempt to init func pts once */
103static DSO *zlib_dso = NULL; 105static DSO *zlib_dso = NULL;
@@ -112,19 +114,19 @@ static DSO *zlib_dso = NULL;
112#define zError p_zError 114#define zError p_zError
113#endif /* ZLIB_SHARED */ 115#endif /* ZLIB_SHARED */
114 116
115struct zlib_state 117struct zlib_state {
116 {
117 z_stream istream; 118 z_stream istream;
118 z_stream ostream; 119 z_stream ostream;
119 }; 120};
120 121
121static int zlib_stateful_ex_idx = -1; 122static int zlib_stateful_ex_idx = -1;
122 123
123static int zlib_stateful_init(COMP_CTX *ctx) 124static int
124 { 125zlib_stateful_init(COMP_CTX *ctx)
126{
125 int err; 127 int err;
126 struct zlib_state *state = 128 struct zlib_state *state =
127 (struct zlib_state *)malloc(sizeof(struct zlib_state)); 129 (struct zlib_state *)malloc(sizeof(struct zlib_state));
128 130
129 if (state == NULL) 131 if (state == NULL)
130 goto err; 132 goto err;
@@ -136,8 +138,7 @@ static int zlib_stateful_init(COMP_CTX *ctx)
136 state->istream.next_out = Z_NULL; 138 state->istream.next_out = Z_NULL;
137 state->istream.avail_in = 0; 139 state->istream.avail_in = 0;
138 state->istream.avail_out = 0; 140 state->istream.avail_out = 0;
139 err = inflateInit_(&state->istream, 141 err = inflateInit_(&state->istream, ZLIB_VERSION, sizeof(z_stream));
140 ZLIB_VERSION, sizeof(z_stream));
141 if (err != Z_OK) 142 if (err != Z_OK)
142 goto err; 143 goto err;
143 144
@@ -148,37 +149,41 @@ static int zlib_stateful_init(COMP_CTX *ctx)
148 state->ostream.next_out = Z_NULL; 149 state->ostream.next_out = Z_NULL;
149 state->ostream.avail_in = 0; 150 state->ostream.avail_in = 0;
150 state->ostream.avail_out = 0; 151 state->ostream.avail_out = 0;
151 err = deflateInit_(&state->ostream,Z_DEFAULT_COMPRESSION, 152 err = deflateInit_(&state->ostream, Z_DEFAULT_COMPRESSION,
152 ZLIB_VERSION, sizeof(z_stream)); 153 ZLIB_VERSION, sizeof(z_stream));
153 if (err != Z_OK) 154 if (err != Z_OK)
154 goto err; 155 goto err;
155 156
156 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data); 157 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
157 CRYPTO_set_ex_data(&ctx->ex_data,zlib_stateful_ex_idx,state); 158 CRYPTO_set_ex_data(&ctx->ex_data, zlib_stateful_ex_idx, state);
158 return 1; 159 return 1;
159 err: 160
161err:
160 free(state); 162 free(state);
161 return 0; 163 return 0;
162 } 164}
163 165
164static void zlib_stateful_finish(COMP_CTX *ctx) 166static void
165 { 167zlib_stateful_finish(COMP_CTX *ctx)
168{
166 struct zlib_state *state = 169 struct zlib_state *state =
167 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data, 170 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
168 zlib_stateful_ex_idx); 171 zlib_stateful_ex_idx);
172
169 inflateEnd(&state->istream); 173 inflateEnd(&state->istream);
170 deflateEnd(&state->ostream); 174 deflateEnd(&state->ostream);
171 free(state); 175 free(state);
172 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data); 176 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
173 } 177}
174 178
175static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out, 179static int
176 unsigned int olen, unsigned char *in, unsigned int ilen) 180zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
177 { 181 unsigned int olen, unsigned char *in, unsigned int ilen)
182{
178 int err = Z_OK; 183 int err = Z_OK;
179 struct zlib_state *state = 184 struct zlib_state *state =
180 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data, 185 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
181 zlib_stateful_ex_idx); 186 zlib_stateful_ex_idx);
182 187
183 if (state == NULL) 188 if (state == NULL)
184 return -1; 189 return -1;
@@ -191,22 +196,25 @@ static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
191 err = deflate(&state->ostream, Z_SYNC_FLUSH); 196 err = deflate(&state->ostream, Z_SYNC_FLUSH);
192 if (err != Z_OK) 197 if (err != Z_OK)
193 return -1; 198 return -1;
199
194#ifdef DEBUG_ZLIB 200#ifdef DEBUG_ZLIB
195 fprintf(stderr,"compress(%4d)->%4d %s\n", 201 fprintf(stderr, "compress(%4d)->%4d %s\n",
196 ilen,olen - state->ostream.avail_out, 202 ilen, olen - state->ostream.avail_out,
197 (ilen != olen - state->ostream.avail_out)?"zlib":"clear"); 203 (ilen != olen - state->ostream.avail_out)?"zlib":"clear");
198#endif 204#endif
205
199 return olen - state->ostream.avail_out; 206 return olen - state->ostream.avail_out;
200 } 207}
201 208
202static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, 209static int
203 unsigned int olen, unsigned char *in, unsigned int ilen) 210zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
204 { 211 unsigned int olen, unsigned char *in, unsigned int ilen)
212{
205 int err = Z_OK; 213 int err = Z_OK;
206 214
207 struct zlib_state *state = 215 struct zlib_state *state =
208 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data, 216 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
209 zlib_stateful_ex_idx); 217 zlib_stateful_ex_idx);
210 218
211 if (state == NULL) 219 if (state == NULL)
212 return 0; 220 return 0;
@@ -219,194 +227,190 @@ static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
219 err = inflate(&state->istream, Z_SYNC_FLUSH); 227 err = inflate(&state->istream, Z_SYNC_FLUSH);
220 if (err != Z_OK) 228 if (err != Z_OK)
221 return -1; 229 return -1;
230
222#ifdef DEBUG_ZLIB 231#ifdef DEBUG_ZLIB
223 fprintf(stderr,"expand(%4d)->%4d %s\n", 232 fprintf(stderr, "expand(%4d)->%4d %s\n",
224 ilen,olen - state->istream.avail_out, 233 ilen, olen - state->istream.avail_out,
225 (ilen != olen - state->istream.avail_out)?"zlib":"clear"); 234 (ilen != olen - state->istream.avail_out)?"zlib":"clear");
226#endif 235#endif
236
227 return olen - state->istream.avail_out; 237 return olen - state->istream.avail_out;
228 } 238}
229 239
230#if 0 240#if 0
231static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, 241static int
232 unsigned int olen, unsigned char *in, unsigned int ilen) 242zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
233 { 243 unsigned int olen, unsigned char *in, unsigned int ilen)
244{
234 unsigned long l; 245 unsigned long l;
235 int i; 246 int i;
236 int clear=1; 247 int clear = 1;
237 248
238 if (ilen > 128) 249 if (ilen > 128) {
239 { 250 out[0] = 1;
240 out[0]=1; 251 l = olen - 1;
241 l=olen-1; 252 i = compress(&(out[1]), &l, in, (unsigned long)ilen);
242 i=compress(&(out[1]),&l,in,(unsigned long)ilen);
243 if (i != Z_OK) 253 if (i != Z_OK)
244 return(-1); 254 return (-1);
245 if (ilen > l) 255 if (ilen > l) {
246 { 256 clear = 0;
247 clear=0;
248 l++; 257 l++;
249 }
250 }
251 if (clear)
252 {
253 out[0]=0;
254 memcpy(&(out[1]),in,ilen);
255 l=ilen+1;
256 } 258 }
259 }
260 if (clear) {
261 out[0] = 0;
262 memcpy(&(out[1]), in, ilen);
263 l = ilen + 1;
264 }
265
257#ifdef DEBUG_ZLIB 266#ifdef DEBUG_ZLIB
258 fprintf(stderr,"compress(%4d)->%4d %s\n", 267 fprintf(stderr, "compress(%4d)->%4d %s\n",
259 ilen,(int)l,(clear)?"clear":"zlib"); 268 ilen,(int)l, (clear)?"clear":"zlib");
260#endif 269#endif
261 return((int)l);
262 }
263 270
264static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out, 271 return ((int)l);
265 unsigned int olen, unsigned char *in, unsigned int ilen) 272}
266 { 273
274static int
275zlib_expand_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
276 unsigned char *in, unsigned int ilen)
277{
267 unsigned long l; 278 unsigned long l;
268 int i; 279 int i;
269 280
270 if (in[0]) 281 if (in[0]) {
271 { 282 l = olen;
272 l=olen; 283 i = zz_uncompress(out, &l, &(in[1]), (unsigned long)ilen - 1);
273 i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
274 if (i != Z_OK) 284 if (i != Z_OK)
275 return(-1); 285 return (-1);
276 } 286 } else {
277 else 287 memcpy(out, &(in[1]), ilen - 1);
278 { 288 l = ilen - 1;
279 memcpy(out,&(in[1]),ilen-1); 289 }
280 l=ilen-1; 290
281 }
282#ifdef DEBUG_ZLIB 291#ifdef DEBUG_ZLIB
283 fprintf(stderr,"expand (%4d)->%4d %s\n", 292 fprintf(stderr, "expand (%4d)->%4d %s\n",
284 ilen,(int)l,in[0]?"zlib":"clear"); 293 ilen,(int)l, in[0]?"zlib":"clear");
285#endif 294#endif
286 return((int)l);
287 }
288 295
289static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, 296 return ((int)l);
290 uLong sourceLen) 297}
298
299static int
300zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
301 uLong sourceLen)
291{ 302{
292 z_stream stream; 303 z_stream stream;
293 int err; 304 int err;
294 305
295 stream.next_in = (Bytef*)source; 306 stream.next_in = (Bytef*)source;
296 stream.avail_in = (uInt)sourceLen; 307 stream.avail_in = (uInt)sourceLen;
297 /* Check for source > 64K on 16-bit machine: */ 308 /* Check for source > 64K on 16-bit machine: */
298 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 309 if ((uLong)stream.avail_in != sourceLen)
310 return Z_BUF_ERROR;
299 311
300 stream.next_out = dest; 312 stream.next_out = dest;
301 stream.avail_out = (uInt)*destLen; 313 stream.avail_out = (uInt)*destLen;
302 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 314 if ((uLong)stream.avail_out != *destLen)
315 return Z_BUF_ERROR;
303 316
304 stream.zalloc = (alloc_func)0; 317 stream.zalloc = (alloc_func)0;
305 stream.zfree = (free_func)0; 318 stream.zfree = (free_func)0;
306 319
307 err = inflateInit_(&stream, 320 err = inflateInit_(&stream, ZLIB_VERSION, sizeof(z_stream));
308 ZLIB_VERSION, sizeof(z_stream)); 321 if (err != Z_OK)
309 if (err != Z_OK) return err; 322 return err;
310 323
311 err = inflate(&stream, Z_FINISH); 324 err = inflate(&stream, Z_FINISH);
312 if (err != Z_STREAM_END) { 325 if (err != Z_STREAM_END) {
313 inflateEnd(&stream); 326 inflateEnd(&stream);
314 return err; 327 return err;
315 } 328 }
316 *destLen = stream.total_out; 329 *destLen = stream.total_out;
317 330
318 err = inflateEnd(&stream); 331 err = inflateEnd(&stream);
319 return err; 332 return err;
320} 333}
321#endif 334#endif
322 335
323#endif 336#endif
324 337
325COMP_METHOD *COMP_zlib(void) 338COMP_METHOD *
326 { 339COMP_zlib(void)
340{
327 COMP_METHOD *meth = &zlib_method_nozlib; 341 COMP_METHOD *meth = &zlib_method_nozlib;
328 342
329#ifdef ZLIB_SHARED 343#ifdef ZLIB_SHARED
330 if (!zlib_loaded) 344 if (!zlib_loaded) {
331 {
332 zlib_dso = DSO_load(NULL, "z", NULL, 0); 345 zlib_dso = DSO_load(NULL, "z", NULL, 0);
333 if (zlib_dso != NULL) 346 if (zlib_dso != NULL) {
334 { 347 p_compress = (compress_ft)DSO_bind_func(
335 p_compress 348 zlib_dso, "compress");
336 = (compress_ft) DSO_bind_func(zlib_dso, 349 p_inflateEnd = (inflateEnd_ft)DSO_bind_func(
337 "compress"); 350 zlib_dso, "inflateEnd");
338 p_inflateEnd 351 p_inflate = (inflate_ft)DSO_bind_func(
339 = (inflateEnd_ft) DSO_bind_func(zlib_dso, 352 zlib_dso, "inflate");
340 "inflateEnd"); 353 p_inflateInit_ = (inflateInit__ft)DSO_bind_func(
341 p_inflate 354 zlib_dso, "inflateInit_");
342 = (inflate_ft) DSO_bind_func(zlib_dso, 355 p_deflateEnd = (deflateEnd_ft)DSO_bind_func(
343 "inflate"); 356 zlib_dso, "deflateEnd");
344 p_inflateInit_ 357 p_deflate = (deflate_ft)DSO_bind_func(
345 = (inflateInit__ft) DSO_bind_func(zlib_dso, 358 zlib_dso, "deflate");
346 "inflateInit_"); 359 p_deflateInit_ = (deflateInit__ft)DSO_bind_func(
347 p_deflateEnd 360 zlib_dso, "deflateInit_");
348 = (deflateEnd_ft) DSO_bind_func(zlib_dso, 361 p_zError = (zError__ft)DSO_bind_func(
349 "deflateEnd"); 362 zlib_dso, "zError");
350 p_deflate 363
351 = (deflate_ft) DSO_bind_func(zlib_dso, 364 if (p_compress && p_inflateEnd && p_inflate &&
352 "deflate"); 365 p_inflateInit_ && p_deflateEnd && p_deflate &&
353 p_deflateInit_ 366 p_deflateInit_ && p_zError)
354 = (deflateInit__ft) DSO_bind_func(zlib_dso,
355 "deflateInit_");
356 p_zError
357 = (zError__ft) DSO_bind_func(zlib_dso,
358 "zError");
359
360 if (p_compress && p_inflateEnd && p_inflate
361 && p_inflateInit_ && p_deflateEnd
362 && p_deflate && p_deflateInit_ && p_zError)
363 zlib_loaded++; 367 zlib_loaded++;
364 }
365 } 368 }
369 }
366 370
367#endif 371#endif
368#ifdef ZLIB_SHARED 372#ifdef ZLIB_SHARED
369 if (zlib_loaded) 373 if (zlib_loaded)
370#endif 374#endif
371#if defined(ZLIB) || defined(ZLIB_SHARED) 375#if defined(ZLIB) || defined(ZLIB_SHARED)
372 { 376 {
373 /* init zlib_stateful_ex_idx here so that in a multi-process 377 /* init zlib_stateful_ex_idx here so that in a multi-process
374 * application it's enough to intialize openssl before forking 378 * application it's enough to intialize openssl before forking
375 * (idx will be inherited in all the children) */ 379 * (idx will be inherited in all the children) */
376 if (zlib_stateful_ex_idx == -1) 380 if (zlib_stateful_ex_idx == -1) {
377 {
378 CRYPTO_w_lock(CRYPTO_LOCK_COMP); 381 CRYPTO_w_lock(CRYPTO_LOCK_COMP);
379 if (zlib_stateful_ex_idx == -1) 382 if (zlib_stateful_ex_idx == -1)
380 zlib_stateful_ex_idx = 383 zlib_stateful_ex_idx =
381 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP, 384 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
382 0,NULL,NULL,NULL,NULL); 385 0, NULL, NULL, NULL, NULL);
383 CRYPTO_w_unlock(CRYPTO_LOCK_COMP); 386 CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
384 if (zlib_stateful_ex_idx == -1) 387 if (zlib_stateful_ex_idx == -1)
385 goto err; 388 goto err;
386 }
387
388 meth = &zlib_stateful_method;
389 } 389 }
390err:
391#endif
392 390
393 return(meth); 391 meth = &zlib_stateful_method;
394 } 392 }
395 393
396void COMP_zlib_cleanup(void) 394err:
397 { 395#endif
396
397 return (meth);
398}
399
400void
401COMP_zlib_cleanup(void)
402{
398#ifdef ZLIB_SHARED 403#ifdef ZLIB_SHARED
399 if (zlib_dso) 404 if (zlib_dso)
400 DSO_free(zlib_dso); 405 DSO_free(zlib_dso);
401#endif 406#endif
402 } 407}
403 408
404#ifdef ZLIB 409#ifdef ZLIB
405 410
406/* Zlib based compression/decompression filter BIO */ 411/* Zlib based compression/decompression filter BIO */
407 412
408typedef struct 413typedef struct {
409 {
410 unsigned char *ibuf; /* Input buffer */ 414 unsigned char *ibuf; /* Input buffer */
411 int ibufsize; /* Buffer size */ 415 int ibufsize; /* Buffer size */
412 z_stream zin; /* Input decompress context */ 416 z_stream zin; /* Input decompress context */
@@ -417,7 +421,7 @@ typedef struct
417 int odone; /* deflate EOF */ 421 int odone; /* deflate EOF */
418 int comp_level; /* Compression level to use */ 422 int comp_level; /* Compression level to use */
419 z_stream zout; /* Output compression context */ 423 z_stream zout; /* Output compression context */
420 } BIO_ZLIB_CTX; 424} BIO_ZLIB_CTX;
421 425
422#define ZLIB_DEFAULT_BUFSIZE 1024 426#define ZLIB_DEFAULT_BUFSIZE 1024
423 427
@@ -428,8 +432,7 @@ static int bio_zlib_write(BIO *b, const char *in, int inl);
428static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr); 432static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr);
429static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp); 433static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp);
430 434
431static BIO_METHOD bio_meth_zlib = 435static BIO_METHOD bio_meth_zlib = {
432 {
433 BIO_TYPE_COMP, 436 BIO_TYPE_COMP,
434 "zlib", 437 "zlib",
435 bio_zlib_write, 438 bio_zlib_write,
@@ -440,31 +443,32 @@ static BIO_METHOD bio_meth_zlib =
440 bio_zlib_new, 443 bio_zlib_new,
441 bio_zlib_free, 444 bio_zlib_free,
442 bio_zlib_callback_ctrl 445 bio_zlib_callback_ctrl
443 }; 446};
444 447
445BIO_METHOD *BIO_f_zlib(void) 448BIO_METHOD *
446 { 449BIO_f_zlib(void)
450{
447 return &bio_meth_zlib; 451 return &bio_meth_zlib;
448 } 452}
449 453
450 454
451static int bio_zlib_new(BIO *bi) 455static int
452 { 456bio_zlib_new(BIO *bi)
457{
453 BIO_ZLIB_CTX *ctx; 458 BIO_ZLIB_CTX *ctx;
459
454#ifdef ZLIB_SHARED 460#ifdef ZLIB_SHARED
455 (void)COMP_zlib(); 461 (void)COMP_zlib();
456 if (!zlib_loaded) 462 if (!zlib_loaded) {
457 {
458 COMPerr(COMP_F_BIO_ZLIB_NEW, COMP_R_ZLIB_NOT_SUPPORTED); 463 COMPerr(COMP_F_BIO_ZLIB_NEW, COMP_R_ZLIB_NOT_SUPPORTED);
459 return 0; 464 return 0;
460 } 465 }
461#endif 466#endif
462 ctx = malloc(sizeof(BIO_ZLIB_CTX)); 467 ctx = malloc(sizeof(BIO_ZLIB_CTX));
463 if(!ctx) 468 if (!ctx) {
464 {
465 COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE); 469 COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE);
466 return 0; 470 return 0;
467 } 471 }
468 ctx->ibuf = NULL; 472 ctx->ibuf = NULL;
469 ctx->obuf = NULL; 473 ctx->obuf = NULL;
470 ctx->ibufsize = ZLIB_DEFAULT_BUFSIZE; 474 ctx->ibufsize = ZLIB_DEFAULT_BUFSIZE;
@@ -487,140 +491,140 @@ static int bio_zlib_new(BIO *bi)
487 bi->ptr = (char *)ctx; 491 bi->ptr = (char *)ctx;
488 bi->flags = 0; 492 bi->flags = 0;
489 return 1; 493 return 1;
490 } 494}
491 495
492static int bio_zlib_free(BIO *bi) 496static int
493 { 497bio_zlib_free(BIO *bi)
498{
494 BIO_ZLIB_CTX *ctx; 499 BIO_ZLIB_CTX *ctx;
495 if(!bi) return 0; 500
501 if (!bi)
502 return 0;
496 ctx = (BIO_ZLIB_CTX *)bi->ptr; 503 ctx = (BIO_ZLIB_CTX *)bi->ptr;
497 if(ctx->ibuf) 504 if (ctx->ibuf) {
498 {
499 /* Destroy decompress context */ 505 /* Destroy decompress context */
500 inflateEnd(&ctx->zin); 506 inflateEnd(&ctx->zin);
501 free(ctx->ibuf); 507 free(ctx->ibuf);
502 } 508 }
503 if(ctx->obuf) 509 if (ctx->obuf) {
504 {
505 /* Destroy compress context */ 510 /* Destroy compress context */
506 deflateEnd(&ctx->zout); 511 deflateEnd(&ctx->zout);
507 free(ctx->obuf); 512 free(ctx->obuf);
508 } 513 }
509 free(ctx); 514 free(ctx);
510 bi->ptr = NULL; 515 bi->ptr = NULL;
511 bi->init = 0; 516 bi->init = 0;
512 bi->flags = 0; 517 bi->flags = 0;
513 return 1; 518 return 1;
514 } 519}
515 520
516static int bio_zlib_read(BIO *b, char *out, int outl) 521static int
517 { 522bio_zlib_read(BIO *b, char *out, int outl)
523{
518 BIO_ZLIB_CTX *ctx; 524 BIO_ZLIB_CTX *ctx;
519 int ret; 525 int ret;
520 z_stream *zin; 526 z_stream *zin;
521 if(!out || !outl) return 0; 527
528 if (!out || !outl)
529 return 0;
522 ctx = (BIO_ZLIB_CTX *)b->ptr; 530 ctx = (BIO_ZLIB_CTX *)b->ptr;
523 zin = &ctx->zin; 531 zin = &ctx->zin;
524 BIO_clear_retry_flags(b); 532 BIO_clear_retry_flags(b);
525 if(!ctx->ibuf) 533 if (!ctx->ibuf) {
526 {
527 ctx->ibuf = malloc(ctx->ibufsize); 534 ctx->ibuf = malloc(ctx->ibufsize);
528 if(!ctx->ibuf) 535 if (!ctx->ibuf) {
529 {
530 COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE); 536 COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE);
531 return 0; 537 return 0;
532 } 538 }
533 inflateInit(zin); 539 inflateInit(zin);
534 zin->next_in = ctx->ibuf; 540 zin->next_in = ctx->ibuf;
535 zin->avail_in = 0; 541 zin->avail_in = 0;
536 } 542 }
537 543
538 /* Copy output data directly to supplied buffer */ 544 /* Copy output data directly to supplied buffer */
539 zin->next_out = (unsigned char *)out; 545 zin->next_out = (unsigned char *)out;
540 zin->avail_out = (unsigned int)outl; 546 zin->avail_out = (unsigned int)outl;
541 for(;;) 547 for (;;) {
542 {
543 /* Decompress while data available */ 548 /* Decompress while data available */
544 while(zin->avail_in) 549 while (zin->avail_in) {
545 {
546 ret = inflate(zin, 0); 550 ret = inflate(zin, 0);
547 if((ret != Z_OK) && (ret != Z_STREAM_END)) 551 if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
548 {
549 COMPerr(COMP_F_BIO_ZLIB_READ, 552 COMPerr(COMP_F_BIO_ZLIB_READ,
550 COMP_R_ZLIB_INFLATE_ERROR); 553 COMP_R_ZLIB_INFLATE_ERROR);
551 ERR_add_error_data(2, "zlib error:", 554 ERR_add_error_data(2, "zlib error:",
552 zError(ret)); 555 zError(ret));
553 return 0; 556 return 0;
554 } 557 }
555 /* If EOF or we've read everything then return */ 558 /* If EOF or we've read everything then return */
556 if((ret == Z_STREAM_END) || !zin->avail_out) 559 if ((ret == Z_STREAM_END) || !zin->avail_out)
557 return outl - zin->avail_out; 560 return outl - zin->avail_out;
558 } 561 }
559 562
560 /* No data in input buffer try to read some in, 563 /* No data in input buffer try to read some in,
561 * if an error then return the total data read. 564 * if an error then return the total data read.
562 */ 565 */
563 ret = BIO_read(b->next_bio, ctx->ibuf, ctx->ibufsize); 566 ret = BIO_read(b->next_bio, ctx->ibuf, ctx->ibufsize);
564 if(ret <= 0) 567 if (ret <= 0) {
565 {
566 /* Total data read */ 568 /* Total data read */
567 int tot = outl - zin->avail_out; 569 int tot = outl - zin->avail_out;
568 BIO_copy_next_retry(b); 570 BIO_copy_next_retry(b);
569 if(ret < 0) return (tot > 0) ? tot : ret; 571 if (ret < 0)
572 return (tot > 0) ? tot : ret;
570 return tot; 573 return tot;
571 } 574 }
572 zin->avail_in = ret; 575 zin->avail_in = ret;
573 zin->next_in = ctx->ibuf; 576 zin->next_in = ctx->ibuf;
574 }
575 } 577 }
578}
576 579
577static int bio_zlib_write(BIO *b, const char *in, int inl) 580static int
578 { 581bio_zlib_write(BIO *b, const char *in, int inl)
582{
579 BIO_ZLIB_CTX *ctx; 583 BIO_ZLIB_CTX *ctx;
580 int ret; 584 int ret;
581 z_stream *zout; 585 z_stream *zout;
582 if(!in || !inl) return 0; 586
587 if (!in || !inl)
588 return 0;
583 ctx = (BIO_ZLIB_CTX *)b->ptr; 589 ctx = (BIO_ZLIB_CTX *)b->ptr;
584 if(ctx->odone) return 0; 590 if (ctx->odone)
591 return 0;
585 zout = &ctx->zout; 592 zout = &ctx->zout;
586 BIO_clear_retry_flags(b); 593 BIO_clear_retry_flags(b);
587 if(!ctx->obuf) 594 if (!ctx->obuf) {
588 {
589 ctx->obuf = malloc(ctx->obufsize); 595 ctx->obuf = malloc(ctx->obufsize);
590 /* Need error here */ 596 /* Need error here */
591 if(!ctx->obuf) 597 if (!ctx->obuf) {
592 {
593 COMPerr(COMP_F_BIO_ZLIB_WRITE, ERR_R_MALLOC_FAILURE); 598 COMPerr(COMP_F_BIO_ZLIB_WRITE, ERR_R_MALLOC_FAILURE);
594 return 0; 599 return 0;
595 } 600 }
596 ctx->optr = ctx->obuf; 601 ctx->optr = ctx->obuf;
597 ctx->ocount = 0; 602 ctx->ocount = 0;
598 deflateInit(zout, ctx->comp_level); 603 deflateInit(zout, ctx->comp_level);
599 zout->next_out = ctx->obuf; 604 zout->next_out = ctx->obuf;
600 zout->avail_out = ctx->obufsize; 605 zout->avail_out = ctx->obufsize;
601 } 606 }
602 /* Obtain input data directly from supplied buffer */ 607 /* Obtain input data directly from supplied buffer */
603 zout->next_in = (void *)in; 608 zout->next_in = (void *)in;
604 zout->avail_in = inl; 609 zout->avail_in = inl;
605 for(;;) 610 for (;;) {
606 {
607 /* If data in output buffer write it first */ 611 /* If data in output buffer write it first */
608 while(ctx->ocount) { 612 while (ctx->ocount) {
609 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount); 613 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
610 if(ret <= 0) 614 if (ret <= 0) {
611 {
612 /* Total data written */ 615 /* Total data written */
613 int tot = inl - zout->avail_in; 616 int tot = inl - zout->avail_in;
614 BIO_copy_next_retry(b); 617 BIO_copy_next_retry(b);
615 if(ret < 0) return (tot > 0) ? tot : ret; 618 if (ret < 0)
619 return (tot > 0) ? tot : ret;
616 return tot; 620 return tot;
617 } 621 }
618 ctx->optr += ret; 622 ctx->optr += ret;
619 ctx->ocount -= ret; 623 ctx->ocount -= ret;
620 } 624 }
621 625
622 /* Have we consumed all supplied data? */ 626 /* Have we consumed all supplied data? */
623 if(!zout->avail_in) 627 if (!zout->avail_in)
624 return inl; 628 return inl;
625 629
626 /* Compress some more */ 630 /* Compress some more */
@@ -631,45 +635,45 @@ static int bio_zlib_write(BIO *b, const char *in, int inl)
631 zout->avail_out = ctx->obufsize; 635 zout->avail_out = ctx->obufsize;
632 /* Compress some more */ 636 /* Compress some more */
633 ret = deflate(zout, 0); 637 ret = deflate(zout, 0);
634 if(ret != Z_OK) 638 if (ret != Z_OK) {
635 {
636 COMPerr(COMP_F_BIO_ZLIB_WRITE, 639 COMPerr(COMP_F_BIO_ZLIB_WRITE,
637 COMP_R_ZLIB_DEFLATE_ERROR); 640 COMP_R_ZLIB_DEFLATE_ERROR);
638 ERR_add_error_data(2, "zlib error:", zError(ret)); 641 ERR_add_error_data(2, "zlib error:", zError(ret));
639 return 0; 642 return 0;
640 }
641 ctx->ocount = ctx->obufsize - zout->avail_out;
642 } 643 }
644 ctx->ocount = ctx->obufsize - zout->avail_out;
643 } 645 }
646}
644 647
645static int bio_zlib_flush(BIO *b) 648static int
646 { 649bio_zlib_flush(BIO *b)
650{
647 BIO_ZLIB_CTX *ctx; 651 BIO_ZLIB_CTX *ctx;
648 int ret; 652 int ret;
649 z_stream *zout; 653 z_stream *zout;
654
650 ctx = (BIO_ZLIB_CTX *)b->ptr; 655 ctx = (BIO_ZLIB_CTX *)b->ptr;
651 /* If no data written or already flush show success */ 656 /* If no data written or already flush show success */
652 if(!ctx->obuf || (ctx->odone && !ctx->ocount)) return 1; 657 if (!ctx->obuf || (ctx->odone && !ctx->ocount))
658 return 1;
653 zout = &ctx->zout; 659 zout = &ctx->zout;
654 BIO_clear_retry_flags(b); 660 BIO_clear_retry_flags(b);
655 /* No more input data */ 661 /* No more input data */
656 zout->next_in = NULL; 662 zout->next_in = NULL;
657 zout->avail_in = 0; 663 zout->avail_in = 0;
658 for(;;) 664 for (;;) {
659 {
660 /* If data in output buffer write it first */ 665 /* If data in output buffer write it first */
661 while(ctx->ocount) 666 while (ctx->ocount) {
662 {
663 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount); 667 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
664 if(ret <= 0) 668 if (ret <= 0) {
665 {
666 BIO_copy_next_retry(b); 669 BIO_copy_next_retry(b);
667 return ret; 670 return ret;
668 } 671 }
669 ctx->optr += ret; 672 ctx->optr += ret;
670 ctx->ocount -= ret; 673 ctx->ocount -= ret;
671 } 674 }
672 if(ctx->odone) return 1; 675 if (ctx->odone)
676 return 1;
673 677
674 /* Compress some more */ 678 /* Compress some more */
675 679
@@ -679,27 +683,28 @@ static int bio_zlib_flush(BIO *b)
679 zout->avail_out = ctx->obufsize; 683 zout->avail_out = ctx->obufsize;
680 /* Compress some more */ 684 /* Compress some more */
681 ret = deflate(zout, Z_FINISH); 685 ret = deflate(zout, Z_FINISH);
682 if(ret == Z_STREAM_END) ctx->odone = 1; 686 if (ret == Z_STREAM_END)
683 else if(ret != Z_OK) 687 ctx->odone = 1;
684 { 688 else if (ret != Z_OK) {
685 COMPerr(COMP_F_BIO_ZLIB_FLUSH, 689 COMPerr(COMP_F_BIO_ZLIB_FLUSH,
686 COMP_R_ZLIB_DEFLATE_ERROR); 690 COMP_R_ZLIB_DEFLATE_ERROR);
687 ERR_add_error_data(2, "zlib error:", zError(ret)); 691 ERR_add_error_data(2, "zlib error:", zError(ret));
688 return 0; 692 return 0;
689 }
690 ctx->ocount = ctx->obufsize - zout->avail_out;
691 } 693 }
694 ctx->ocount = ctx->obufsize - zout->avail_out;
692 } 695 }
696}
693 697
694static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr) 698static long
695 { 699bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
700{
696 BIO_ZLIB_CTX *ctx; 701 BIO_ZLIB_CTX *ctx;
697 int ret, *ip; 702 int ret, *ip;
698 int ibs, obs; 703 int ibs, obs;
699 if(!b->next_bio) return 0; 704 if (!b->next_bio)
705 return 0;
700 ctx = (BIO_ZLIB_CTX *)b->ptr; 706 ctx = (BIO_ZLIB_CTX *)b->ptr;
701 switch (cmd) 707 switch (cmd) {
702 {
703 708
704 case BIO_CTRL_RESET: 709 case BIO_CTRL_RESET:
705 ctx->ocount = 0; 710 ctx->ocount = 0;
@@ -716,39 +721,32 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
716 case BIO_C_SET_BUFF_SIZE: 721 case BIO_C_SET_BUFF_SIZE:
717 ibs = -1; 722 ibs = -1;
718 obs = -1; 723 obs = -1;
719 if (ptr != NULL) 724 if (ptr != NULL) {
720 {
721 ip = ptr; 725 ip = ptr;
722 if (*ip == 0) 726 if (*ip == 0)
723 ibs = (int) num; 727 ibs = (int) num;
724 else 728 else
725 obs = (int) num; 729 obs = (int) num;
726 } 730 } else {
727 else
728 {
729 ibs = (int)num; 731 ibs = (int)num;
730 obs = ibs; 732 obs = ibs;
731 } 733 }
732 734
733 if (ibs != -1) 735 if (ibs != -1) {
734 { 736 if (ctx->ibuf) {
735 if (ctx->ibuf)
736 {
737 free(ctx->ibuf); 737 free(ctx->ibuf);
738 ctx->ibuf = NULL; 738 ctx->ibuf = NULL;
739 }
740 ctx->ibufsize = ibs;
741 } 739 }
740 ctx->ibufsize = ibs;
741 }
742 742
743 if (obs != -1) 743 if (obs != -1) {
744 { 744 if (ctx->obuf) {
745 if (ctx->obuf)
746 {
747 free(ctx->obuf); 745 free(ctx->obuf);
748 ctx->obuf = NULL; 746 ctx->obuf = NULL;
749 }
750 ctx->obufsize = obs;
751 } 747 }
748 ctx->obufsize = obs;
749 }
752 ret = 1; 750 ret = 1;
753 break; 751 break;
754 752
@@ -762,18 +760,18 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
762 ret = BIO_ctrl(b->next_bio, cmd, num, ptr); 760 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
763 break; 761 break;
764 762
765 } 763 }
766 764
767 return ret; 765 return ret;
768 } 766}
769 767
770 768
771static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 769static long
772 { 770bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
773 if(!b->next_bio) 771{
772 if (!b->next_bio)
774 return 0; 773 return 0;
775 return 774 return BIO_callback_ctrl(b->next_bio, cmd, fp);
776 BIO_callback_ctrl(b->next_bio, cmd, fp); 775}
777 }
778 776
779#endif 777#endif
diff --git a/src/lib/libssl/src/crypto/comp/comp.h b/src/lib/libssl/src/crypto/comp/comp.h
index 4b405c7d49..0f7d2da336 100644
--- a/src/lib/libssl/src/crypto/comp/comp.h
+++ b/src/lib/libssl/src/crypto/comp/comp.h
@@ -10,25 +10,21 @@ extern "C" {
10 10
11typedef struct comp_ctx_st COMP_CTX; 11typedef struct comp_ctx_st COMP_CTX;
12 12
13typedef struct comp_method_st 13typedef struct comp_method_st {
14 {
15 int type; /* NID for compression library */ 14 int type; /* NID for compression library */
16 const char *name; /* A text string to identify the library */ 15 const char *name; /* A text string to identify the library */
17 int (*init)(COMP_CTX *ctx); 16 int (*init)(COMP_CTX *ctx);
18 void (*finish)(COMP_CTX *ctx); 17 void (*finish)(COMP_CTX *ctx);
19 int (*compress)(COMP_CTX *ctx, 18 int (*compress)(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
20 unsigned char *out, unsigned int olen, 19 unsigned char *in, unsigned int ilen);
21 unsigned char *in, unsigned int ilen); 20 int (*expand)(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
22 int (*expand)(COMP_CTX *ctx, 21 unsigned char *in, unsigned int ilen);
23 unsigned char *out, unsigned int olen,
24 unsigned char *in, unsigned int ilen);
25 /* The following two do NOTHING, but are kept for backward compatibility */ 22 /* The following two do NOTHING, but are kept for backward compatibility */
26 long (*ctrl)(void); 23 long (*ctrl)(void);
27 long (*callback_ctrl)(void); 24 long (*callback_ctrl)(void);
28 } COMP_METHOD; 25} COMP_METHOD;
29 26
30struct comp_ctx_st 27struct comp_ctx_st {
31 {
32 COMP_METHOD *meth; 28 COMP_METHOD *meth;
33 unsigned long compress_in; 29 unsigned long compress_in;
34 unsigned long compress_out; 30 unsigned long compress_out;
@@ -36,15 +32,15 @@ struct comp_ctx_st
36 unsigned long expand_out; 32 unsigned long expand_out;
37 33
38 CRYPTO_EX_DATA ex_data; 34 CRYPTO_EX_DATA ex_data;
39 }; 35};
40 36
41 37
42COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); 38COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
43void COMP_CTX_free(COMP_CTX *ctx); 39void COMP_CTX_free(COMP_CTX *ctx);
44int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, 40int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
45 unsigned char *in, int ilen); 41 unsigned char *in, int ilen);
46int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, 42int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
47 unsigned char *in, int ilen); 43 unsigned char *in, int ilen);
48COMP_METHOD *COMP_rle(void ); 44COMP_METHOD *COMP_rle(void );
49COMP_METHOD *COMP_zlib(void ); 45COMP_METHOD *COMP_zlib(void );
50void COMP_zlib_cleanup(void); 46void COMP_zlib_cleanup(void);
diff --git a/src/lib/libssl/src/crypto/comp/comp_err.c b/src/lib/libssl/src/crypto/comp/comp_err.c
index 661c94c3a4..982c58567a 100644
--- a/src/lib/libssl/src/crypto/comp/comp_err.c
+++ b/src/lib/libssl/src/crypto/comp/comp_err.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -68,33 +68,30 @@
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_COMP,func,0) 68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_COMP,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_COMP,0,reason) 69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_COMP,0,reason)
70 70
71static ERR_STRING_DATA COMP_str_functs[]= 71static ERR_STRING_DATA COMP_str_functs[] = {
72 { 72 {ERR_FUNC(COMP_F_BIO_ZLIB_FLUSH), "BIO_ZLIB_FLUSH"},
73{ERR_FUNC(COMP_F_BIO_ZLIB_FLUSH), "BIO_ZLIB_FLUSH"}, 73 {ERR_FUNC(COMP_F_BIO_ZLIB_NEW), "BIO_ZLIB_NEW"},
74{ERR_FUNC(COMP_F_BIO_ZLIB_NEW), "BIO_ZLIB_NEW"}, 74 {ERR_FUNC(COMP_F_BIO_ZLIB_READ), "BIO_ZLIB_READ"},
75{ERR_FUNC(COMP_F_BIO_ZLIB_READ), "BIO_ZLIB_READ"}, 75 {ERR_FUNC(COMP_F_BIO_ZLIB_WRITE), "BIO_ZLIB_WRITE"},
76{ERR_FUNC(COMP_F_BIO_ZLIB_WRITE), "BIO_ZLIB_WRITE"}, 76 {0, NULL}
77{0,NULL} 77};
78 };
79 78
80static ERR_STRING_DATA COMP_str_reasons[]= 79static ERR_STRING_DATA COMP_str_reasons[] = {
81 { 80 {ERR_REASON(COMP_R_ZLIB_DEFLATE_ERROR) , "zlib deflate error"},
82{ERR_REASON(COMP_R_ZLIB_DEFLATE_ERROR) ,"zlib deflate error"}, 81 {ERR_REASON(COMP_R_ZLIB_INFLATE_ERROR) , "zlib inflate error"},
83{ERR_REASON(COMP_R_ZLIB_INFLATE_ERROR) ,"zlib inflate error"}, 82 {ERR_REASON(COMP_R_ZLIB_NOT_SUPPORTED) , "zlib not supported"},
84{ERR_REASON(COMP_R_ZLIB_NOT_SUPPORTED) ,"zlib not supported"}, 83 {0, NULL}
85{0,NULL} 84};
86 };
87 85
88#endif 86#endif
89 87
90void ERR_load_COMP_strings(void) 88void
91 { 89ERR_load_COMP_strings(void)
90{
92#ifndef OPENSSL_NO_ERR 91#ifndef OPENSSL_NO_ERR
93 92 if (ERR_func_error_string(COMP_str_functs[0].error) == NULL) {
94 if (ERR_func_error_string(COMP_str_functs[0].error) == NULL) 93 ERR_load_strings(0, COMP_str_functs);
95 { 94 ERR_load_strings(0, COMP_str_reasons);
96 ERR_load_strings(0,COMP_str_functs);
97 ERR_load_strings(0,COMP_str_reasons);
98 }
99#endif
100 } 95 }
96#endif
97}
diff --git a/src/lib/libssl/src/crypto/comp/comp_lib.c b/src/lib/libssl/src/crypto/comp/comp_lib.c
index feb07ea881..745c802228 100644
--- a/src/lib/libssl/src/crypto/comp/comp_lib.c
+++ b/src/lib/libssl/src/crypto/comp/comp_lib.c
@@ -4,69 +4,68 @@
4#include <openssl/objects.h> 4#include <openssl/objects.h>
5#include <openssl/comp.h> 5#include <openssl/comp.h>
6 6
7COMP_CTX *COMP_CTX_new(COMP_METHOD *meth) 7COMP_CTX *
8 { 8COMP_CTX_new(COMP_METHOD *meth)
9{
9 COMP_CTX *ret; 10 COMP_CTX *ret;
10 11
11 if ((ret=(COMP_CTX *)malloc(sizeof(COMP_CTX))) == NULL) 12 if ((ret = (COMP_CTX *)malloc(sizeof(COMP_CTX))) == NULL) {
12 {
13 /* ZZZZZZZZZZZZZZZZ */ 13 /* ZZZZZZZZZZZZZZZZ */
14 return(NULL); 14 return (NULL);
15 } 15 }
16 memset(ret,0,sizeof(COMP_CTX)); 16 memset(ret, 0, sizeof(COMP_CTX));
17 ret->meth=meth; 17 ret->meth = meth;
18 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) 18 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
19 {
20 free(ret); 19 free(ret);
21 ret=NULL; 20 ret = NULL;
22 }
23 return(ret);
24 } 21 }
22 return (ret);
23}
25 24
26void COMP_CTX_free(COMP_CTX *ctx) 25void
27 { 26COMP_CTX_free(COMP_CTX *ctx)
28 if(ctx == NULL) 27{
29 return; 28 if (ctx == NULL)
29 return;
30 30
31 if (ctx->meth->finish != NULL) 31 if (ctx->meth->finish != NULL)
32 ctx->meth->finish(ctx); 32 ctx->meth->finish(ctx);
33 33
34 free(ctx); 34 free(ctx);
35 } 35}
36 36
37int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, 37int
38 unsigned char *in, int ilen) 38COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
39 { 39 unsigned char *in, int ilen)
40{
40 int ret; 41 int ret;
41 if (ctx->meth->compress == NULL) 42
42 { 43 if (ctx->meth->compress == NULL) {
43 /* ZZZZZZZZZZZZZZZZZ */ 44 /* ZZZZZZZZZZZZZZZZZ */
44 return(-1); 45 return (-1);
45 }
46 ret=ctx->meth->compress(ctx,out,olen,in,ilen);
47 if (ret > 0)
48 {
49 ctx->compress_in+=ilen;
50 ctx->compress_out+=ret;
51 }
52 return(ret);
53 } 46 }
47 ret = ctx->meth->compress(ctx, out, olen, in, ilen);
48 if (ret > 0) {
49 ctx->compress_in += ilen;
50 ctx->compress_out += ret;
51 }
52 return (ret);
53}
54 54
55int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, 55int
56 unsigned char *in, int ilen) 56COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
57 { 57 unsigned char *in, int ilen)
58{
58 int ret; 59 int ret;
59 60
60 if (ctx->meth->expand == NULL) 61 if (ctx->meth->expand == NULL) {
61 {
62 /* ZZZZZZZZZZZZZZZZZ */ 62 /* ZZZZZZZZZZZZZZZZZ */
63 return(-1); 63 return (-1);
64 } 64 }
65 ret=ctx->meth->expand(ctx,out,olen,in,ilen); 65 ret = ctx->meth->expand(ctx, out, olen, in, ilen);
66 if (ret > 0) 66 if (ret > 0) {
67 { 67 ctx->expand_in += ilen;
68 ctx->expand_in+=ilen; 68 ctx->expand_out += ret;
69 ctx->expand_out+=ret;
70 }
71 return(ret);
72 } 69 }
70 return (ret);
71}