summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/comp
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2023-04-23 13:43:47 +0000
committercvs2svn <admin@example.com>2023-04-23 13:43:47 +0000
commite2496982472bdf233be95c5ea72d1c4dc6c91db3 (patch)
tree316488e5daf86864d8466bce0e5b000d85768378 /src/lib/libcrypto/comp
parent097d0cf840b9007212bcd2516ed5e18939e6da3d (diff)
downloadopenbsd-tb_20230422.tar.gz
openbsd-tb_20230422.tar.bz2
openbsd-tb_20230422.zip
This commit was manufactured by cvs2git to create tag 'tb_20230422'.tb_20230422
Diffstat (limited to 'src/lib/libcrypto/comp')
-rw-r--r--src/lib/libcrypto/comp/c_rle.c171
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c682
-rw-r--r--src/lib/libcrypto/comp/comp.h158
-rw-r--r--src/lib/libcrypto/comp/comp_err.c94
-rw-r--r--src/lib/libcrypto/comp/comp_lib.c184
-rw-r--r--src/lib/libcrypto/comp/comp_local.h148
6 files changed, 0 insertions, 1437 deletions
diff --git a/src/lib/libcrypto/comp/c_rle.c b/src/lib/libcrypto/comp/c_rle.c
deleted file mode 100644
index c2c279dc04..0000000000
--- a/src/lib/libcrypto/comp/c_rle.c
+++ /dev/null
@@ -1,171 +0,0 @@
1/* $OpenBSD: c_rle.c,v 1.11 2022/12/24 07:12:09 tb Exp $ */
2/*
3 * ---------------------------------------------------------------------------
4 * Patches to this file were contributed by
5 * Ulf Moeller <ulf@openssl.org> and Bodo Moeller <bodo@openssl.org>.
6 * ---------------------------------------------------------------------------
7 * Copyright (c) 1999, 2011 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 *
53 * ---------------------------------------------------------------------------
54 * Parts of this file are derived from SSLeay code
55 * which is covered by the following Copyright and license:
56 * ---------------------------------------------------------------------------
57 * Copyright (c) 1998 Eric Young <eay@cryptsoft.com>
58 * All rights reserved.
59 *
60 * This package is an SSL implementation written
61 * by Eric Young <eay@cryptsoft.com>.
62 * The implementation was written so as to conform with Netscapes SSL.
63 *
64 * This library is free for commercial and non-commercial use as long as
65 * the following conditions are aheared to. The following conditions
66 * apply to all code found in this distribution, be it the RC4, RSA,
67 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
68 * included with this distribution is covered by the same copyright terms
69 * except that the holder is Tim Hudson <tjh@cryptsoft.com>.
70 *
71 * Copyright remains Eric Young's, and as such any Copyright notices in
72 * the code are not to be removed.
73 * If this package is used in a product, Eric Young should be given
74 * attribution as the author of the parts of the library used.
75 * This can be in the form of a textual message at program startup or
76 * in documentation (online or textual) provided with the package.
77 *
78 * Redistribution and use in source and binary forms, with or without
79 * modification, are permitted provided that the following conditions
80 * are met:
81 * 1. Redistributions of source code must retain the copyright
82 * notice, this list of conditions and the following disclaimer.
83 * 2. Redistributions in binary form must reproduce the above copyright
84 * notice, this list of conditions and the following disclaimer in the
85 * documentation and/or other materials provided with the distribution.
86 * 3. All advertising materials mentioning features or use of this software
87 * must display the following acknowledgement:
88 * "This product includes cryptographic software written by
89 * Eric Young <eay@cryptsoft.com>"
90 * The word 'cryptographic' can be left out if the rouines from the
91 * library being used are not cryptographic related :-).
92 * 4. If you include any Windows specific code (or a derivative thereof)
93 * from the apps directory (application code) you must include an
94 * acknowledgement: "This product includes software written
95 * by Tim Hudson <tjh@cryptsoft.com>"
96 *
97 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
98 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
99 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
100 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
101 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
102 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
103 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
104 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
105 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
106 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
107 * SUCH DAMAGE.
108 *
109 * The licence and distribution terms for any publically available version
110 * or derivative of this code cannot be changed. i.e. this code cannot
111 * simply be copied and put under another distribution licence
112 * [including the GNU Public Licence.]
113 */
114
115#include <stdio.h>
116#include <stdlib.h>
117#include <string.h>
118
119#include <openssl/objects.h>
120#include <openssl/comp.h>
121
122#include "comp_local.h"
123
124static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
125 unsigned int olen, unsigned char *in, unsigned int ilen);
126static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
127 unsigned int olen, unsigned char *in, unsigned int ilen);
128
129static COMP_METHOD rle_method = {
130 .type = NID_rle_compression,
131 .name = LN_rle_compression,
132 .compress = rle_compress_block,
133 .expand = rle_expand_block
134};
135
136COMP_METHOD *
137COMP_rle(void)
138{
139 return (&rle_method);
140}
141
142static int
143rle_compress_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
144 unsigned char *in, unsigned int ilen)
145{
146
147 if (ilen == 0 || olen < (ilen - 1)) {
148 return (-1);
149 }
150
151 *(out++) = 0;
152 memcpy(out, in, ilen);
153 return (ilen + 1);
154}
155
156static int
157rle_expand_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
158 unsigned char *in, unsigned int ilen)
159{
160 int i;
161
162 if (olen < (ilen - 1)) {
163 return (-1);
164 }
165
166 i= *(in++);
167 if (i == 0) {
168 memcpy(out, in, ilen - 1);
169 }
170 return (ilen - 1);
171}
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
deleted file mode 100644
index 009737d59d..0000000000
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ /dev/null
@@ -1,682 +0,0 @@
1/* $OpenBSD: c_zlib.c,v 1.26 2023/04/17 13:18:00 tb Exp $ */
2/*
3 * ---------------------------------------------------------------------------
4 * Major patches to this file were contributed by
5 * Richard Levitte <levitte@openssl.org>, Nils Larsch <nils@openssl.org>,
6 * and Dr. Stephen Henson <steve@openssl.org>.
7 * ---------------------------------------------------------------------------
8 * Copyright (c) 2002, 2003, 2007, 2008, 2010 The OpenSSL Project.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 *
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in
20 * the documentation and/or other materials provided with the
21 * distribution.
22 *
23 * 3. All advertising materials mentioning features or use of this
24 * software must display the following acknowledgment:
25 * "This product includes software developed by the OpenSSL Project
26 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
27 *
28 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
29 * endorse or promote products derived from this software without
30 * prior written permission. For written permission, please contact
31 * licensing@OpenSSL.org.
32 *
33 * 5. Products derived from this software may not be called "OpenSSL"
34 * nor may "OpenSSL" appear in their names without prior written
35 * permission of the OpenSSL Project.
36 *
37 * 6. Redistributions of any form whatsoever must retain the following
38 * acknowledgment:
39 * "This product includes software developed by the OpenSSL Project
40 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
43 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
46 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53 * OF THE POSSIBILITY OF SUCH DAMAGE.
54 *
55 * ---------------------------------------------------------------------------
56 * Parts of this file are derived from SSLeay code
57 * which is covered by the following Copyright and license:
58 * ---------------------------------------------------------------------------
59 * Copyright (c) 1998 Eric Young <eay@cryptsoft.com>
60 * All rights reserved.
61 *
62 * This package is an SSL implementation written
63 * by Eric Young <eay@cryptsoft.com>.
64 * The implementation was written so as to conform with Netscapes SSL.
65 *
66 * This library is free for commercial and non-commercial use as long as
67 * the following conditions are aheared to. The following conditions
68 * apply to all code found in this distribution, be it the RC4, RSA,
69 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
70 * included with this distribution is covered by the same copyright terms
71 * except that the holder is Tim Hudson <tjh@cryptsoft.com>.
72 *
73 * Copyright remains Eric Young's, and as such any Copyright notices in
74 * the code are not to be removed.
75 * If this package is used in a product, Eric Young should be given
76 * attribution as the author of the parts of the library used.
77 * This can be in the form of a textual message at program startup or
78 * in documentation (online or textual) provided with the package.
79 *
80 * Redistribution and use in source and binary forms, with or without
81 * modification, are permitted provided that the following conditions
82 * are met:
83 * 1. Redistributions of source code must retain the copyright
84 * notice, this list of conditions and the following disclaimer.
85 * 2. Redistributions in binary form must reproduce the above copyright
86 * notice, this list of conditions and the following disclaimer in the
87 * documentation and/or other materials provided with the distribution.
88 * 3. All advertising materials mentioning features or use of this software
89 * must display the following acknowledgement:
90 * "This product includes cryptographic software written by
91 * Eric Young <eay@cryptsoft.com>"
92 * The word 'cryptographic' can be left out if the rouines from the
93 * library being used are not cryptographic related :-).
94 * 4. If you include any Windows specific code (or a derivative thereof)
95 * from the apps directory (application code) you must include an
96 * acknowledgement: "This product includes software written
97 * by Tim Hudson <tjh@cryptsoft.com>"
98 *
99 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
100 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
102 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
103 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
104 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
105 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
106 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
107 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
108 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
109 * SUCH DAMAGE.
110 *
111 * The licence and distribution terms for any publically available version
112 * or derivative of this code cannot be changed. i.e. this code cannot
113 * simply be copied and put under another distribution licence
114 * [including the GNU Public Licence.]
115 */
116
117#include <stdio.h>
118#include <stdlib.h>
119#include <string.h>
120
121#include <openssl/objects.h>
122#include <openssl/comp.h>
123#include <openssl/err.h>
124
125#include "bio_local.h"
126#include "comp_local.h"
127
128COMP_METHOD *COMP_zlib(void );
129
130static COMP_METHOD zlib_method_nozlib = {
131 .type = NID_undef,
132 .name = "(undef)"
133};
134
135#ifdef ZLIB
136
137#include <zlib.h>
138
139static int zlib_stateful_init(COMP_CTX *ctx);
140static void zlib_stateful_finish(COMP_CTX *ctx);
141static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
142 unsigned int olen, unsigned char *in, unsigned int ilen);
143static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
144 unsigned int olen, unsigned char *in, unsigned int ilen);
145
146
147/* memory allocations functions for zlib initialization */
148static void*
149zlib_zalloc(void* opaque, unsigned int no, unsigned int size)
150{
151 return calloc(no, size);
152}
153
154static void
155zlib_zfree(void* opaque, void* address)
156{
157 free(address);
158}
159
160static COMP_METHOD zlib_stateful_method = {
161 .type = NID_zlib_compression,
162 .name = LN_zlib_compression,
163 .init = zlib_stateful_init,
164 .finish = zlib_stateful_finish,
165 .compress = zlib_stateful_compress_block,
166 .expand = zlib_stateful_expand_block
167};
168
169struct zlib_state {
170 z_stream istream;
171 z_stream ostream;
172};
173
174static int zlib_stateful_ex_idx = -1;
175
176static int
177zlib_stateful_init(COMP_CTX *ctx)
178{
179 int err;
180 struct zlib_state *state = malloc(sizeof(struct zlib_state));
181
182 if (state == NULL)
183 goto err;
184
185 state->istream.zalloc = zlib_zalloc;
186 state->istream.zfree = zlib_zfree;
187 state->istream.opaque = Z_NULL;
188 state->istream.next_in = Z_NULL;
189 state->istream.next_out = Z_NULL;
190 state->istream.avail_in = 0;
191 state->istream.avail_out = 0;
192 err = inflateInit_(&state->istream, ZLIB_VERSION, sizeof(z_stream));
193 if (err != Z_OK)
194 goto err;
195
196 state->ostream.zalloc = zlib_zalloc;
197 state->ostream.zfree = zlib_zfree;
198 state->ostream.opaque = Z_NULL;
199 state->ostream.next_in = Z_NULL;
200 state->ostream.next_out = Z_NULL;
201 state->ostream.avail_in = 0;
202 state->ostream.avail_out = 0;
203 err = deflateInit_(&state->ostream, Z_DEFAULT_COMPRESSION,
204 ZLIB_VERSION, sizeof(z_stream));
205 if (err != Z_OK)
206 goto err;
207
208 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
209 CRYPTO_set_ex_data(&ctx->ex_data, zlib_stateful_ex_idx, state);
210 return 1;
211
212err:
213 free(state);
214 return 0;
215}
216
217static void
218zlib_stateful_finish(COMP_CTX *ctx)
219{
220 struct zlib_state *state =
221 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
222 zlib_stateful_ex_idx);
223
224 inflateEnd(&state->istream);
225 deflateEnd(&state->ostream);
226 free(state);
227 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
228}
229
230static int
231zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
232 unsigned int olen, unsigned char *in, unsigned int ilen)
233{
234 int err = Z_OK;
235 struct zlib_state *state =
236 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
237 zlib_stateful_ex_idx);
238
239 if (state == NULL)
240 return -1;
241
242 state->ostream.next_in = in;
243 state->ostream.avail_in = ilen;
244 state->ostream.next_out = out;
245 state->ostream.avail_out = olen;
246 if (ilen > 0)
247 err = deflate(&state->ostream, Z_SYNC_FLUSH);
248 if (err != Z_OK)
249 return -1;
250
251#ifdef DEBUG_ZLIB
252 fprintf(stderr, "compress(%4d)->%4d %s\n",
253 ilen, olen - state->ostream.avail_out,
254 (ilen != olen - state->ostream.avail_out)?"zlib":"clear");
255#endif
256
257 return olen - state->ostream.avail_out;
258}
259
260static int
261zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
262 unsigned int olen, unsigned char *in, unsigned int ilen)
263{
264 int err = Z_OK;
265
266 struct zlib_state *state =
267 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
268 zlib_stateful_ex_idx);
269
270 if (state == NULL)
271 return 0;
272
273 state->istream.next_in = in;
274 state->istream.avail_in = ilen;
275 state->istream.next_out = out;
276 state->istream.avail_out = olen;
277 if (ilen > 0)
278 err = inflate(&state->istream, Z_SYNC_FLUSH);
279 if (err != Z_OK)
280 return -1;
281
282#ifdef DEBUG_ZLIB
283 fprintf(stderr, "expand(%4d)->%4d %s\n",
284 ilen, olen - state->istream.avail_out,
285 (ilen != olen - state->istream.avail_out)?"zlib":"clear");
286#endif
287
288 return olen - state->istream.avail_out;
289}
290
291#endif
292
293COMP_METHOD *
294COMP_zlib(void)
295{
296 COMP_METHOD *meth = &zlib_method_nozlib;
297
298#ifdef ZLIB
299 {
300 /* init zlib_stateful_ex_idx here so that in a multi-process
301 * application it's enough to initialize openssl before forking
302 * (idx will be inherited in all the children) */
303 if (zlib_stateful_ex_idx == -1) {
304 CRYPTO_w_lock(CRYPTO_LOCK_COMP);
305 if (zlib_stateful_ex_idx == -1)
306 zlib_stateful_ex_idx =
307 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
308 0, NULL, NULL, NULL, NULL);
309 CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
310 if (zlib_stateful_ex_idx == -1)
311 goto err;
312 }
313 if (!OPENSSL_init_crypto(0, NULL))
314 goto err;
315
316 meth = &zlib_stateful_method;
317 }
318
319err:
320#endif
321
322 return (meth);
323}
324
325void
326COMP_zlib_cleanup(void)
327{
328}
329
330#ifdef ZLIB
331
332/* Zlib based compression/decompression filter BIO */
333
334typedef struct {
335 unsigned char *ibuf; /* Input buffer */
336 int ibufsize; /* Buffer size */
337 z_stream zin; /* Input decompress context */
338 unsigned char *obuf; /* Output buffer */
339 int obufsize; /* Output buffer size */
340 unsigned char *optr; /* Position in output buffer */
341 int ocount; /* Amount of data in output buffer */
342 int odone; /* deflate EOF */
343 int comp_level; /* Compression level to use */
344 z_stream zout; /* Output compression context */
345} BIO_ZLIB_CTX;
346
347#define ZLIB_DEFAULT_BUFSIZE 1024
348
349static int bio_zlib_new(BIO *bi);
350static int bio_zlib_free(BIO *bi);
351static int bio_zlib_read(BIO *b, char *out, int outl);
352static int bio_zlib_write(BIO *b, const char *in, int inl);
353static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr);
354static long bio_zlib_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp);
355
356static BIO_METHOD bio_meth_zlib = {
357 .type = BIO_TYPE_COMP,
358 .name = "zlib",
359 .bwrite = bio_zlib_write,
360 .bread = bio_zlib_read,
361 .ctrl = bio_zlib_ctrl,
362 .create = bio_zlib_new,
363 .destroy = bio_zlib_free,
364 .callback_ctrl = bio_zlib_callback_ctrl
365};
366
367BIO_METHOD *
368BIO_f_zlib(void)
369{
370 return &bio_meth_zlib;
371}
372
373
374static int
375bio_zlib_new(BIO *bi)
376{
377 BIO_ZLIB_CTX *ctx;
378
379 ctx = malloc(sizeof(BIO_ZLIB_CTX));
380 if (!ctx) {
381 COMPerror(ERR_R_MALLOC_FAILURE);
382 return 0;
383 }
384 ctx->ibuf = NULL;
385 ctx->obuf = NULL;
386 ctx->ibufsize = ZLIB_DEFAULT_BUFSIZE;
387 ctx->obufsize = ZLIB_DEFAULT_BUFSIZE;
388 ctx->zin.zalloc = Z_NULL;
389 ctx->zin.zfree = Z_NULL;
390 ctx->zin.next_in = NULL;
391 ctx->zin.avail_in = 0;
392 ctx->zin.next_out = NULL;
393 ctx->zin.avail_out = 0;
394 ctx->zout.zalloc = Z_NULL;
395 ctx->zout.zfree = Z_NULL;
396 ctx->zout.next_in = NULL;
397 ctx->zout.avail_in = 0;
398 ctx->zout.next_out = NULL;
399 ctx->zout.avail_out = 0;
400 ctx->odone = 0;
401 ctx->comp_level = Z_DEFAULT_COMPRESSION;
402 bi->init = 1;
403 bi->ptr = (char *)ctx;
404 bi->flags = 0;
405 return 1;
406}
407
408static int
409bio_zlib_free(BIO *bi)
410{
411 BIO_ZLIB_CTX *ctx;
412
413 if (!bi)
414 return 0;
415 ctx = (BIO_ZLIB_CTX *)bi->ptr;
416 if (ctx->ibuf) {
417 /* Destroy decompress context */
418 inflateEnd(&ctx->zin);
419 free(ctx->ibuf);
420 }
421 if (ctx->obuf) {
422 /* Destroy compress context */
423 deflateEnd(&ctx->zout);
424 free(ctx->obuf);
425 }
426 free(ctx);
427 bi->ptr = NULL;
428 bi->init = 0;
429 bi->flags = 0;
430 return 1;
431}
432
433static int
434bio_zlib_read(BIO *b, char *out, int outl)
435{
436 BIO_ZLIB_CTX *ctx;
437 int ret;
438 z_stream *zin;
439
440 if (!out || !outl)
441 return 0;
442 ctx = (BIO_ZLIB_CTX *)b->ptr;
443 zin = &ctx->zin;
444 BIO_clear_retry_flags(b);
445 if (!ctx->ibuf) {
446 ctx->ibuf = malloc(ctx->ibufsize);
447 if (!ctx->ibuf) {
448 COMPerror(ERR_R_MALLOC_FAILURE);
449 return 0;
450 }
451 inflateInit(zin);
452 zin->next_in = ctx->ibuf;
453 zin->avail_in = 0;
454 }
455
456 /* Copy output data directly to supplied buffer */
457 zin->next_out = (unsigned char *)out;
458 zin->avail_out = (unsigned int)outl;
459 for (;;) {
460 /* Decompress while data available */
461 while (zin->avail_in) {
462 ret = inflate(zin, 0);
463 if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
464 COMPerror(COMP_R_ZLIB_INFLATE_ERROR);
465 ERR_asprintf_error_data("zlib error:%s",
466 zError(ret));
467 return 0;
468 }
469 /* If EOF or we've read everything then return */
470 if ((ret == Z_STREAM_END) || !zin->avail_out)
471 return outl - zin->avail_out;
472 }
473
474 /* No data in input buffer try to read some in,
475 * if an error then return the total data read.
476 */
477 ret = BIO_read(b->next_bio, ctx->ibuf, ctx->ibufsize);
478 if (ret <= 0) {
479 /* Total data read */
480 int tot = outl - zin->avail_out;
481 BIO_copy_next_retry(b);
482 if (ret < 0)
483 return (tot > 0) ? tot : ret;
484 return tot;
485 }
486 zin->avail_in = ret;
487 zin->next_in = ctx->ibuf;
488 }
489}
490
491static int
492bio_zlib_write(BIO *b, const char *in, int inl)
493{
494 BIO_ZLIB_CTX *ctx;
495 int ret;
496 z_stream *zout;
497
498 if (!in || !inl)
499 return 0;
500 ctx = (BIO_ZLIB_CTX *)b->ptr;
501 if (ctx->odone)
502 return 0;
503 zout = &ctx->zout;
504 BIO_clear_retry_flags(b);
505 if (!ctx->obuf) {
506 ctx->obuf = malloc(ctx->obufsize);
507 /* Need error here */
508 if (!ctx->obuf) {
509 COMPerror(ERR_R_MALLOC_FAILURE);
510 return 0;
511 }
512 ctx->optr = ctx->obuf;
513 ctx->ocount = 0;
514 deflateInit(zout, ctx->comp_level);
515 zout->next_out = ctx->obuf;
516 zout->avail_out = ctx->obufsize;
517 }
518 /* Obtain input data directly from supplied buffer */
519 zout->next_in = (void *)in;
520 zout->avail_in = inl;
521 for (;;) {
522 /* If data in output buffer write it first */
523 while (ctx->ocount) {
524 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
525 if (ret <= 0) {
526 /* Total data written */
527 int tot = inl - zout->avail_in;
528 BIO_copy_next_retry(b);
529 if (ret < 0)
530 return (tot > 0) ? tot : ret;
531 return tot;
532 }
533 ctx->optr += ret;
534 ctx->ocount -= ret;
535 }
536
537 /* Have we consumed all supplied data? */
538 if (!zout->avail_in)
539 return inl;
540
541 /* Compress some more */
542
543 /* Reset buffer */
544 ctx->optr = ctx->obuf;
545 zout->next_out = ctx->obuf;
546 zout->avail_out = ctx->obufsize;
547 /* Compress some more */
548 ret = deflate(zout, 0);
549 if (ret != Z_OK) {
550 COMPerror(COMP_R_ZLIB_DEFLATE_ERROR);
551 ERR_asprintf_error_data("zlib error:%s", zError(ret));
552 return 0;
553 }
554 ctx->ocount = ctx->obufsize - zout->avail_out;
555 }
556}
557
558static int
559bio_zlib_flush(BIO *b)
560{
561 BIO_ZLIB_CTX *ctx;
562 int ret;
563 z_stream *zout;
564
565 ctx = (BIO_ZLIB_CTX *)b->ptr;
566 /* If no data written or already flush show success */
567 if (!ctx->obuf || (ctx->odone && !ctx->ocount))
568 return 1;
569 zout = &ctx->zout;
570 BIO_clear_retry_flags(b);
571 /* No more input data */
572 zout->next_in = NULL;
573 zout->avail_in = 0;
574 for (;;) {
575 /* If data in output buffer write it first */
576 while (ctx->ocount) {
577 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
578 if (ret <= 0) {
579 BIO_copy_next_retry(b);
580 return ret;
581 }
582 ctx->optr += ret;
583 ctx->ocount -= ret;
584 }
585 if (ctx->odone)
586 return 1;
587
588 /* Compress some more */
589
590 /* Reset buffer */
591 ctx->optr = ctx->obuf;
592 zout->next_out = ctx->obuf;
593 zout->avail_out = ctx->obufsize;
594 /* Compress some more */
595 ret = deflate(zout, Z_FINISH);
596 if (ret == Z_STREAM_END)
597 ctx->odone = 1;
598 else if (ret != Z_OK) {
599 COMPerror(COMP_R_ZLIB_DEFLATE_ERROR);
600 ERR_asprintf_error_data("zlib error:%s", zError(ret));
601 return 0;
602 }
603 ctx->ocount = ctx->obufsize - zout->avail_out;
604 }
605}
606
607static long
608bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
609{
610 BIO_ZLIB_CTX *ctx;
611 int ret, *ip;
612 int ibs, obs;
613 if (!b->next_bio)
614 return 0;
615 ctx = (BIO_ZLIB_CTX *)b->ptr;
616 switch (cmd) {
617
618 case BIO_CTRL_RESET:
619 ctx->ocount = 0;
620 ctx->odone = 0;
621 ret = 1;
622 break;
623
624 case BIO_CTRL_FLUSH:
625 ret = bio_zlib_flush(b);
626 if (ret > 0)
627 ret = BIO_flush(b->next_bio);
628 break;
629
630 case BIO_C_SET_BUFF_SIZE:
631 ibs = -1;
632 obs = -1;
633 if (ptr != NULL) {
634 ip = ptr;
635 if (*ip == 0)
636 ibs = (int) num;
637 else
638 obs = (int) num;
639 } else {
640 ibs = (int)num;
641 obs = ibs;
642 }
643
644 if (ibs != -1) {
645 free(ctx->ibuf);
646 ctx->ibuf = NULL;
647 ctx->ibufsize = ibs;
648 }
649
650 if (obs != -1) {
651 free(ctx->obuf);
652 ctx->obuf = NULL;
653 ctx->obufsize = obs;
654 }
655 ret = 1;
656 break;
657
658 case BIO_C_DO_STATE_MACHINE:
659 BIO_clear_retry_flags(b);
660 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
661 BIO_copy_next_retry(b);
662 break;
663
664 default:
665 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
666 break;
667
668 }
669
670 return ret;
671}
672
673
674static long
675bio_zlib_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
676{
677 if (!b->next_bio)
678 return 0;
679 return BIO_callback_ctrl(b->next_bio, cmd, fp);
680}
681
682#endif
diff --git a/src/lib/libcrypto/comp/comp.h b/src/lib/libcrypto/comp/comp.h
deleted file mode 100644
index 58b51c6e82..0000000000
--- a/src/lib/libcrypto/comp/comp.h
+++ /dev/null
@@ -1,158 +0,0 @@
1/* $OpenBSD: comp.h,v 1.11 2022/12/24 07:12:09 tb Exp $ */
2/*
3 * ---------------------------------------------------------------------------
4 * Patches to this file were contributed by
5 * Dr. Stephen Henson <steve@openssl.org>.
6 * ---------------------------------------------------------------------------
7 * Copyright (c) 1999, 2002, 2008 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 *
53 * ---------------------------------------------------------------------------
54 * Parts of this file are derived from SSLeay code
55 * which is covered by the following Copyright and license:
56 * ---------------------------------------------------------------------------
57 * Copyright (c) 1998 Eric Young <eay@cryptsoft.com>
58 * All rights reserved.
59 *
60 * This package is an SSL implementation written
61 * by Eric Young <eay@cryptsoft.com>.
62 * The implementation was written so as to conform with Netscapes SSL.
63 *
64 * This library is free for commercial and non-commercial use as long as
65 * the following conditions are aheared to. The following conditions
66 * apply to all code found in this distribution, be it the RC4, RSA,
67 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
68 * included with this distribution is covered by the same copyright terms
69 * except that the holder is Tim Hudson <tjh@cryptsoft.com>.
70 *
71 * Copyright remains Eric Young's, and as such any Copyright notices in
72 * the code are not to be removed.
73 * If this package is used in a product, Eric Young should be given
74 * attribution as the author of the parts of the library used.
75 * This can be in the form of a textual message at program startup or
76 * in documentation (online or textual) provided with the package.
77 *
78 * Redistribution and use in source and binary forms, with or without
79 * modification, are permitted provided that the following conditions
80 * are met:
81 * 1. Redistributions of source code must retain the copyright
82 * notice, this list of conditions and the following disclaimer.
83 * 2. Redistributions in binary form must reproduce the above copyright
84 * notice, this list of conditions and the following disclaimer in the
85 * documentation and/or other materials provided with the distribution.
86 * 3. All advertising materials mentioning features or use of this software
87 * must display the following acknowledgement:
88 * "This product includes cryptographic software written by
89 * Eric Young <eay@cryptsoft.com>"
90 * The word 'cryptographic' can be left out if the rouines from the
91 * library being used are not cryptographic related :-).
92 * 4. If you include any Windows specific code (or a derivative thereof)
93 * from the apps directory (application code) you must include an
94 * acknowledgement: "This product includes software written
95 * by Tim Hudson <tjh@cryptsoft.com>"
96 *
97 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
98 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
99 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
100 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
101 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
102 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
103 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
104 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
105 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
106 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
107 * SUCH DAMAGE.
108 *
109 * The licence and distribution terms for any publically available version
110 * or derivative of this code cannot be changed. i.e. this code cannot
111 * simply be copied and put under another distribution licence
112 * [including the GNU Public Licence.]
113 */
114
115#ifndef HEADER_COMP_H
116#define HEADER_COMP_H
117
118#include <openssl/crypto.h>
119
120#ifdef __cplusplus
121extern "C" {
122#endif
123
124COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
125void COMP_CTX_free(COMP_CTX *ctx);
126int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
127 unsigned char *in, int ilen);
128int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
129 unsigned char *in, int ilen);
130COMP_METHOD *COMP_rle(void );
131COMP_METHOD *COMP_zlib(void );
132void COMP_zlib_cleanup(void);
133
134#ifdef HEADER_BIO_H
135#ifdef ZLIB
136BIO_METHOD *BIO_f_zlib(void);
137#endif
138#endif
139
140void ERR_load_COMP_strings(void);
141
142/* Error codes for the COMP functions. */
143
144/* Function codes. */
145#define COMP_F_BIO_ZLIB_FLUSH 99
146#define COMP_F_BIO_ZLIB_NEW 100
147#define COMP_F_BIO_ZLIB_READ 101
148#define COMP_F_BIO_ZLIB_WRITE 102
149
150/* Reason codes. */
151#define COMP_R_ZLIB_DEFLATE_ERROR 99
152#define COMP_R_ZLIB_INFLATE_ERROR 100
153#define COMP_R_ZLIB_NOT_SUPPORTED 101
154
155#ifdef __cplusplus
156}
157#endif
158#endif
diff --git a/src/lib/libcrypto/comp/comp_err.c b/src/lib/libcrypto/comp/comp_err.c
deleted file mode 100644
index 5ec5039f80..0000000000
--- a/src/lib/libcrypto/comp/comp_err.c
+++ /dev/null
@@ -1,94 +0,0 @@
1/* $OpenBSD: comp_err.c,v 1.13 2022/12/23 23:23:02 schwarze Exp $ */
2/* ====================================================================
3 * This file was written by Dr. Stephen Henson <steve@openssl.org>.
4 * Copyright (c) 1999, 2005, 2008 The OpenSSL Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the OpenSSL Project
21 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
22 *
23 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 * endorse or promote products derived from this software without
25 * prior written permission. For written permission, please contact
26 * openssl-core@OpenSSL.org.
27 *
28 * 5. Products derived from this software may not be called "OpenSSL"
29 * nor may "OpenSSL" appear in their names without prior written
30 * permission of the OpenSSL Project.
31 *
32 * 6. Redistributions of any form whatsoever must retain the following
33 * acknowledgment:
34 * "This product includes software developed by the OpenSSL Project
35 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This product includes cryptographic software written by Eric Young
52 * (eay@cryptsoft.com). This product includes software written by Tim
53 * Hudson (tjh@cryptsoft.com).
54 *
55 */
56
57#include <stdio.h>
58
59#include <openssl/opensslconf.h>
60
61#include <openssl/comp.h>
62#include <openssl/err.h>
63
64#include "comp_local.h"
65
66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_COMP,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_COMP,0,reason)
70
71static ERR_STRING_DATA COMP_str_functs[] = {
72 {ERR_FUNC(0xfff), "CRYPTO_internal"},
73 {0, NULL}
74};
75
76static ERR_STRING_DATA COMP_str_reasons[] = {
77 {ERR_REASON(COMP_R_ZLIB_DEFLATE_ERROR) , "zlib deflate error"},
78 {ERR_REASON(COMP_R_ZLIB_INFLATE_ERROR) , "zlib inflate error"},
79 {ERR_REASON(COMP_R_ZLIB_NOT_SUPPORTED) , "zlib not supported"},
80 {0, NULL}
81};
82
83#endif
84
85void
86ERR_load_COMP_strings(void)
87{
88#ifndef OPENSSL_NO_ERR
89 if (ERR_func_error_string(COMP_str_functs[0].error) == NULL) {
90 ERR_load_strings(0, COMP_str_functs);
91 ERR_load_strings(0, COMP_str_reasons);
92 }
93#endif
94}
diff --git a/src/lib/libcrypto/comp/comp_lib.c b/src/lib/libcrypto/comp/comp_lib.c
deleted file mode 100644
index 5cb2335bf5..0000000000
--- a/src/lib/libcrypto/comp/comp_lib.c
+++ /dev/null
@@ -1,184 +0,0 @@
1/* $OpenBSD: comp_lib.c,v 1.11 2022/12/24 07:12:09 tb Exp $ */
2/*
3 * ---------------------------------------------------------------------------
4 * Patches to this file were contributed by
5 * Ben Laurie <ben@openssl.org> and Ulf Moeller <ulf@openssl.org>.
6 * ---------------------------------------------------------------------------
7 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 *
53 * ---------------------------------------------------------------------------
54 * Parts of this file are derived from SSLeay code
55 * which is covered by the following Copyright and license:
56 * ---------------------------------------------------------------------------
57 * Copyright (c) 1998 Eric Young <eay@cryptsoft.com>
58 * All rights reserved.
59 *
60 * This package is an SSL implementation written
61 * by Eric Young <eay@cryptsoft.com>.
62 * The implementation was written so as to conform with Netscapes SSL.
63 *
64 * This library is free for commercial and non-commercial use as long as
65 * the following conditions are aheared to. The following conditions
66 * apply to all code found in this distribution, be it the RC4, RSA,
67 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
68 * included with this distribution is covered by the same copyright terms
69 * except that the holder is Tim Hudson <tjh@cryptsoft.com>.
70 *
71 * Copyright remains Eric Young's, and as such any Copyright notices in
72 * the code are not to be removed.
73 * If this package is used in a product, Eric Young should be given
74 * attribution as the author of the parts of the library used.
75 * This can be in the form of a textual message at program startup or
76 * in documentation (online or textual) provided with the package.
77 *
78 * Redistribution and use in source and binary forms, with or without
79 * modification, are permitted provided that the following conditions
80 * are met:
81 * 1. Redistributions of source code must retain the copyright
82 * notice, this list of conditions and the following disclaimer.
83 * 2. Redistributions in binary form must reproduce the above copyright
84 * notice, this list of conditions and the following disclaimer in the
85 * documentation and/or other materials provided with the distribution.
86 * 3. All advertising materials mentioning features or use of this software
87 * must display the following acknowledgement:
88 * "This product includes cryptographic software written by
89 * Eric Young <eay@cryptsoft.com>"
90 * The word 'cryptographic' can be left out if the rouines from the
91 * library being used are not cryptographic related :-).
92 * 4. If you include any Windows specific code (or a derivative thereof)
93 * from the apps directory (application code) you must include an
94 * acknowledgement: "This product includes software written
95 * by Tim Hudson <tjh@cryptsoft.com>"
96 *
97 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
98 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
99 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
100 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
101 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
102 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
103 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
104 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
105 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
106 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
107 * SUCH DAMAGE.
108 *
109 * The licence and distribution terms for any publically available version
110 * or derivative of this code cannot be changed. i.e. this code cannot
111 * simply be copied and put under another distribution licence
112 * [including the GNU Public Licence.]
113 */
114
115#include <stdio.h>
116#include <stdlib.h>
117#include <string.h>
118
119#include <openssl/objects.h>
120#include <openssl/comp.h>
121
122#include "comp_local.h"
123
124COMP_CTX *
125COMP_CTX_new(COMP_METHOD *meth)
126{
127 COMP_CTX *ret;
128
129 if ((ret = calloc(1, sizeof(COMP_CTX))) == NULL) {
130 return (NULL);
131 }
132 ret->meth = meth;
133 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
134 free(ret);
135 ret = NULL;
136 }
137 return (ret);
138}
139
140void
141COMP_CTX_free(COMP_CTX *ctx)
142{
143 if (ctx == NULL)
144 return;
145
146 if (ctx->meth->finish != NULL)
147 ctx->meth->finish(ctx);
148
149 free(ctx);
150}
151
152int
153COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
154 unsigned char *in, int ilen)
155{
156 int ret;
157
158 if (ctx->meth->compress == NULL) {
159 return (-1);
160 }
161 ret = ctx->meth->compress(ctx, out, olen, in, ilen);
162 if (ret > 0) {
163 ctx->compress_in += ilen;
164 ctx->compress_out += ret;
165 }
166 return (ret);
167}
168
169int
170COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
171 unsigned char *in, int ilen)
172{
173 int ret;
174
175 if (ctx->meth->expand == NULL) {
176 return (-1);
177 }
178 ret = ctx->meth->expand(ctx, out, olen, in, ilen);
179 if (ret > 0) {
180 ctx->expand_in += ilen;
181 ctx->expand_out += ret;
182 }
183 return (ret);
184}
diff --git a/src/lib/libcrypto/comp/comp_local.h b/src/lib/libcrypto/comp/comp_local.h
deleted file mode 100644
index e26a800ba3..0000000000
--- a/src/lib/libcrypto/comp/comp_local.h
+++ /dev/null
@@ -1,148 +0,0 @@
1/* $OpenBSD: comp_local.h,v 1.4 2022/12/24 07:12:09 tb Exp $ */
2/*
3 * ---------------------------------------------------------------------------
4 * Patches to this file were contributed by
5 * Richard Levitte <levitte@openssl.org>.
6 * ---------------------------------------------------------------------------
7 * Copyright (c) 1999, 2000, 2003 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 *
53 * ---------------------------------------------------------------------------
54 * Parts of this file are derived from SSLeay code
55 * which is covered by the following Copyright and license:
56 * ---------------------------------------------------------------------------
57 * Copyright (c) 1998 Eric Young <eay@cryptsoft.com>
58 * All rights reserved.
59 *
60 * This package is an SSL implementation written
61 * by Eric Young <eay@cryptsoft.com>.
62 * The implementation was written so as to conform with Netscapes SSL.
63 *
64 * This library is free for commercial and non-commercial use as long as
65 * the following conditions are aheared to. The following conditions
66 * apply to all code found in this distribution, be it the RC4, RSA,
67 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
68 * included with this distribution is covered by the same copyright terms
69 * except that the holder is Tim Hudson <tjh@cryptsoft.com>.
70 *
71 * Copyright remains Eric Young's, and as such any Copyright notices in
72 * the code are not to be removed.
73 * If this package is used in a product, Eric Young should be given
74 * attribution as the author of the parts of the library used.
75 * This can be in the form of a textual message at program startup or
76 * in documentation (online or textual) provided with the package.
77 *
78 * Redistribution and use in source and binary forms, with or without
79 * modification, are permitted provided that the following conditions
80 * are met:
81 * 1. Redistributions of source code must retain the copyright
82 * notice, this list of conditions and the following disclaimer.
83 * 2. Redistributions in binary form must reproduce the above copyright
84 * notice, this list of conditions and the following disclaimer in the
85 * documentation and/or other materials provided with the distribution.
86 * 3. All advertising materials mentioning features or use of this software
87 * must display the following acknowledgement:
88 * "This product includes cryptographic software written by
89 * Eric Young <eay@cryptsoft.com>"
90 * The word 'cryptographic' can be left out if the rouines from the
91 * library being used are not cryptographic related :-).
92 * 4. If you include any Windows specific code (or a derivative thereof)
93 * from the apps directory (application code) you must include an
94 * acknowledgement: "This product includes software written
95 * by Tim Hudson <tjh@cryptsoft.com>"
96 *
97 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
98 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
99 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
100 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
101 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
102 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
103 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
104 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
105 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
106 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
107 * SUCH DAMAGE.
108 *
109 * The licence and distribution terms for any publically available version
110 * or derivative of this code cannot be changed. i.e. this code cannot
111 * simply be copied and put under another distribution licence
112 * [including the GNU Public Licence.]
113 */
114
115#ifndef HEADER_COMP_LOCAL_H
116#define HEADER_COMP_LOCAL_H
117
118__BEGIN_HIDDEN_DECLS
119
120struct CMP_CTX;
121
122struct comp_method_st {
123 int type; /* NID for compression library */
124 const char *name; /* A text string to identify the library */
125 int (*init)(COMP_CTX *ctx);
126 void (*finish)(COMP_CTX *ctx);
127 int (*compress)(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
128 unsigned char *in, unsigned int ilen);
129 int (*expand)(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
130 unsigned char *in, unsigned int ilen);
131 /* The following two do NOTHING, but are kept for backward compatibility */
132 long (*ctrl)(void);
133 long (*callback_ctrl)(void);
134} /* COMP_METHOD */;
135
136struct comp_ctx_st {
137 COMP_METHOD *meth;
138 unsigned long compress_in;
139 unsigned long compress_out;
140 unsigned long expand_in;
141 unsigned long expand_out;
142
143 CRYPTO_EX_DATA ex_data;
144} /* COMP_CTX */;
145
146__END_HIDDEN_DECLS
147
148#endif /* !HEADER_COMP_LOCAL_H */