summaryrefslogtreecommitdiff
path: root/lib/libcrypto/comp/c_zlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libcrypto/comp/c_zlib.c')
-rw-r--r--lib/libcrypto/comp/c_zlib.c201
1 files changed, 3 insertions, 198 deletions
diff --git a/lib/libcrypto/comp/c_zlib.c b/lib/libcrypto/comp/c_zlib.c
index 11b95fb7993..4951ade8103 100644
--- a/lib/libcrypto/comp/c_zlib.c
+++ b/lib/libcrypto/comp/c_zlib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_zlib.c,v 1.16 2014/06/12 15:49:28 deraadt Exp $ */
+/* $OpenBSD: c_zlib.c,v 1.17 2014/11/03 16:58:28 tedu Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -13,9 +13,7 @@ static COMP_METHOD zlib_method_nozlib = {
.name = "(undef)"
};
-#ifndef ZLIB
-#undef ZLIB_SHARED
-#else
+#ifdef ZLIB
#include <zlib.h>
@@ -40,23 +38,6 @@ zlib_zfree(void* opaque, void* address)
free(address);
}
-#if 0
-static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
- unsigned int olen, unsigned char *in, unsigned int ilen);
-static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
- unsigned int olen, unsigned char *in, unsigned int ilen);
-
-static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
- uLong sourceLen);
-
-static COMP_METHOD zlib_stateless_method = {
- .type = NID_zlib_compression,
- .name = LN_zlib_compression,
- .compress = zlib_compress_block,
- .expand = zlib_expand_block
-};
-#endif
-
static COMP_METHOD zlib_stateful_method = {
.type = NID_zlib_compression,
.name = LN_zlib_compression,
@@ -66,43 +47,6 @@ static COMP_METHOD zlib_stateful_method = {
.expand = zlib_stateful_expand_block
};
-#ifdef ZLIB_SHARED
-#include <openssl/dso.h>
-
-/* Function pointers */
-typedef int (*compress_ft)(Bytef *dest, uLongf *destLen, const Bytef *source,
- uLong sourceLen);
-typedef int (*inflateEnd_ft)(z_streamp strm);
-typedef int (*inflate_ft)(z_streamp strm, int flush);
-typedef int (*inflateInit__ft)(z_streamp strm, const char * version,
- int stream_size);
-typedef int (*deflateEnd_ft)(z_streamp strm);
-typedef int (*deflate_ft)(z_streamp strm, int flush);
-typedef int (*deflateInit__ft)(z_streamp strm, int level, const char * version,
- int stream_size);
-typedef const char * (*zError__ft)(int err);
-static compress_ft p_compress = NULL;
-static inflateEnd_ft p_inflateEnd = NULL;
-static inflate_ft p_inflate = NULL;
-static inflateInit__ft p_inflateInit_ = NULL;
-static deflateEnd_ft p_deflateEnd = NULL;
-static deflate_ft p_deflate = NULL;
-static deflateInit__ft p_deflateInit_ = NULL;
-static zError__ft p_zError = NULL;
-
-static int zlib_loaded = 0; /* only attempt to init func pts once */
-static DSO *zlib_dso = NULL;
-
-#define compress p_compress
-#define inflateEnd p_inflateEnd
-#define inflate p_inflate
-#define inflateInit_ p_inflateInit_
-#define deflateEnd p_deflateEnd
-#define deflate p_deflate
-#define deflateInit_ p_deflateInit_
-#define zError p_zError
-#endif /* ZLIB_SHARED */
-
struct zlib_state {
z_stream istream;
z_stream ostream;
@@ -225,102 +169,6 @@ zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
return olen - state->istream.avail_out;
}
-#if 0
-static int
-zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
- unsigned int olen, unsigned char *in, unsigned int ilen)
-{
- unsigned long l;
- int i;
- int clear = 1;
-
- if (ilen > 128) {
- out[0] = 1;
- l = olen - 1;
- i = compress(&(out[1]), &l, in, (unsigned long)ilen);
- if (i != Z_OK)
- return (-1);
- if (ilen > l) {
- clear = 0;
- l++;
- }
- }
- if (clear) {
- out[0] = 0;
- memcpy(&(out[1]), in, ilen);
- l = ilen + 1;
- }
-
-#ifdef DEBUG_ZLIB
- fprintf(stderr, "compress(%4d)->%4d %s\n",
- ilen,(int)l, (clear)?"clear":"zlib");
-#endif
-
- return ((int)l);
-}
-
-static int
-zlib_expand_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
- unsigned char *in, unsigned int ilen)
-{
- unsigned long l;
- int i;
-
- if (in[0]) {
- l = olen;
- i = zz_uncompress(out, &l, &(in[1]), (unsigned long)ilen - 1);
- if (i != Z_OK)
- return (-1);
- } else {
- memcpy(out, &(in[1]), ilen - 1);
- l = ilen - 1;
- }
-
-#ifdef DEBUG_ZLIB
- fprintf(stderr, "expand (%4d)->%4d %s\n",
- ilen,(int)l, in[0]?"zlib":"clear");
-#endif
-
- return ((int)l);
-}
-
-static int
-zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
- uLong sourceLen)
-{
- z_stream stream;
- int err;
-
- stream.next_in = (Bytef*)source;
- stream.avail_in = (uInt)sourceLen;
- /* Check for source > 64K on 16-bit machine: */
- if ((uLong)stream.avail_in != sourceLen)
- return Z_BUF_ERROR;
-
- stream.next_out = dest;
- stream.avail_out = (uInt)*destLen;
- if ((uLong)stream.avail_out != *destLen)
- return Z_BUF_ERROR;
-
- stream.zalloc = (alloc_func)0;
- stream.zfree = (free_func)0;
-
- err = inflateInit_(&stream, ZLIB_VERSION, sizeof(z_stream));
- if (err != Z_OK)
- return err;
-
- err = inflate(&stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- inflateEnd(&stream);
- return err;
- }
- *destLen = stream.total_out;
-
- err = inflateEnd(&stream);
- return err;
-}
-#endif
-
#endif
COMP_METHOD *
@@ -328,39 +176,7 @@ COMP_zlib(void)
{
COMP_METHOD *meth = &zlib_method_nozlib;
-#ifdef ZLIB_SHARED
- if (!zlib_loaded) {
- zlib_dso = DSO_load(NULL, "z", NULL, 0);
- if (zlib_dso != NULL) {
- p_compress = (compress_ft)DSO_bind_func(
- zlib_dso, "compress");
- p_inflateEnd = (inflateEnd_ft)DSO_bind_func(
- zlib_dso, "inflateEnd");
- p_inflate = (inflate_ft)DSO_bind_func(
- zlib_dso, "inflate");
- p_inflateInit_ = (inflateInit__ft)DSO_bind_func(
- zlib_dso, "inflateInit_");
- p_deflateEnd = (deflateEnd_ft)DSO_bind_func(
- zlib_dso, "deflateEnd");
- p_deflate = (deflate_ft)DSO_bind_func(
- zlib_dso, "deflate");
- p_deflateInit_ = (deflateInit__ft)DSO_bind_func(
- zlib_dso, "deflateInit_");
- p_zError = (zError__ft)DSO_bind_func(
- zlib_dso, "zError");
-
- if (p_compress && p_inflateEnd && p_inflate &&
- p_inflateInit_ && p_deflateEnd && p_deflate &&
- p_deflateInit_ && p_zError)
- zlib_loaded++;
- }
- }
-
-#endif
-#ifdef ZLIB_SHARED
- if (zlib_loaded)
-#endif
-#if defined(ZLIB) || defined(ZLIB_SHARED)
+#ifdef ZLIB
{
/* init zlib_stateful_ex_idx here so that in a multi-process
* application it's enough to intialize openssl before forking
@@ -388,10 +204,6 @@ err:
void
COMP_zlib_cleanup(void)
{
-#ifdef ZLIB_SHARED
- if (zlib_dso)
- DSO_free(zlib_dso);
-#endif
}
#ifdef ZLIB
@@ -443,13 +255,6 @@ bio_zlib_new(BIO *bi)
{
BIO_ZLIB_CTX *ctx;
-#ifdef ZLIB_SHARED
- (void)COMP_zlib();
- if (!zlib_loaded) {
- COMPerr(COMP_F_BIO_ZLIB_NEW, COMP_R_ZLIB_NOT_SUPPORTED);
- return 0;
- }
-#endif
ctx = malloc(sizeof(BIO_ZLIB_CTX));
if (!ctx) {
COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE);