summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/comp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/comp')
-rw-r--r--src/lib/libcrypto/comp/Makefile.ssl46
-rw-r--r--src/lib/libcrypto/comp/c_rle.c1
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c141
-rw-r--r--src/lib/libcrypto/comp/comp.h4
-rw-r--r--src/lib/libcrypto/comp/comp_err.c4
5 files changed, 167 insertions, 29 deletions
diff --git a/src/lib/libcrypto/comp/Makefile.ssl b/src/lib/libcrypto/comp/Makefile.ssl
index b696ac75fe..5dadb65cd4 100644
--- a/src/lib/libcrypto/comp/Makefile.ssl
+++ b/src/lib/libcrypto/comp/Makefile.ssl
@@ -5,13 +5,14 @@
5DIR= comp 5DIR= comp
6TOP= ../.. 6TOP= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX= 10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl 11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
14MAKEDEPEND= $(TOP)/util/domd $(TOP) 14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
15MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
16AR= ar r 17AR= ar r
17 18
@@ -22,10 +23,10 @@ TEST=
22APPS= 23APPS=
23 24
24LIB=$(TOP)/libcrypto.a 25LIB=$(TOP)/libcrypto.a
25LIBSRC= comp_lib.c \ 26LIBSRC= comp_lib.c comp_err.c \
26 c_rle.c c_zlib.c 27 c_rle.c c_zlib.c
27 28
28LIBOBJ= comp_lib.o \ 29LIBOBJ= comp_lib.o comp_err.o \
29 c_rle.o c_zlib.o 30 c_rle.o c_zlib.o
30 31
31SRC= $(LIBSRC) 32SRC= $(LIBSRC)
@@ -42,8 +43,7 @@ all: lib
42 43
43lib: $(LIBOBJ) 44lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ) 45 $(AR) $(LIB) $(LIBOBJ)
45 @echo You may get an error following this line. Please ignore. 46 $(RANLIB) $(LIB) || echo Never mind.
46 - $(RANLIB) $(LIB)
47 @touch lib 47 @touch lib
48 48
49files: 49files:
@@ -84,19 +84,31 @@ clean:
84 84
85c_rle.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 85c_rle.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
86c_rle.o: ../../include/openssl/bn.h ../../include/openssl/comp.h 86c_rle.o: ../../include/openssl/bn.h ../../include/openssl/comp.h
87c_rle.o: ../../include/openssl/crypto.h ../../include/openssl/obj_mac.h 87c_rle.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
88c_rle.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 88c_rle.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
89c_rle.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 89c_rle.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
90c_rle.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 90c_rle.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
91c_rle.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h c_rle.c
91c_zlib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 92c_zlib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
92c_zlib.o: ../../include/openssl/bn.h ../../include/openssl/comp.h 93c_zlib.o: ../../include/openssl/bn.h ../../include/openssl/comp.h
93c_zlib.o: ../../include/openssl/crypto.h ../../include/openssl/obj_mac.h 94c_zlib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
94c_zlib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 95c_zlib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
95c_zlib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 96c_zlib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
97c_zlib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
96c_zlib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 98c_zlib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
99c_zlib.o: c_zlib.c
100comp_err.o: ../../include/openssl/bio.h ../../include/openssl/comp.h
101comp_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
102comp_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
103comp_err.o: ../../include/openssl/opensslconf.h
104comp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
105comp_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
106comp_err.o: comp_err.c
97comp_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 107comp_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
98comp_lib.o: ../../include/openssl/bn.h ../../include/openssl/comp.h 108comp_lib.o: ../../include/openssl/bn.h ../../include/openssl/comp.h
99comp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/obj_mac.h 109comp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
100comp_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 110comp_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
101comp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 111comp_lib.o: ../../include/openssl/opensslconf.h
102comp_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 112comp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
113comp_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
114comp_lib.o: ../../include/openssl/symhacks.h comp_lib.c
diff --git a/src/lib/libcrypto/comp/c_rle.c b/src/lib/libcrypto/comp/c_rle.c
index 1a819e3737..efd366fa22 100644
--- a/src/lib/libcrypto/comp/c_rle.c
+++ b/src/lib/libcrypto/comp/c_rle.c
@@ -17,6 +17,7 @@ static COMP_METHOD rle_method={
17 rle_compress_block, 17 rle_compress_block,
18 rle_expand_block, 18 rle_expand_block,
19 NULL, 19 NULL,
20 NULL,
20 }; 21 };
21 22
22COMP_METHOD *COMP_rle(void) 23COMP_METHOD *COMP_rle(void)
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
index 6684ab4841..cd2f8a491b 100644
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ b/src/lib/libcrypto/comp/c_zlib.c
@@ -6,11 +6,10 @@
6 6
7COMP_METHOD *COMP_zlib(void ); 7COMP_METHOD *COMP_zlib(void );
8 8
9#ifndef ZLIB 9static COMP_METHOD zlib_method_nozlib={
10
11static COMP_METHOD zlib_method={
12 NID_undef, 10 NID_undef,
13 "(null)", 11 "(undef)",
12 NULL,
14 NULL, 13 NULL,
15 NULL, 14 NULL,
16 NULL, 15 NULL,
@@ -18,6 +17,8 @@ static COMP_METHOD zlib_method={
18 NULL, 17 NULL,
19 }; 18 };
20 19
20#ifndef ZLIB
21#undef ZLIB_SHARED
21#else 22#else
22 23
23#include <zlib.h> 24#include <zlib.h>
@@ -38,8 +39,56 @@ static COMP_METHOD zlib_method={
38 zlib_compress_block, 39 zlib_compress_block,
39 zlib_expand_block, 40 zlib_expand_block,
40 NULL, 41 NULL,
42 NULL,
41 }; 43 };
42 44
45/*
46 * When OpenSSL is built on Windows, we do not want to require that
47 * the ZLIB.DLL be available in order for the OpenSSL DLLs to
48 * work. Therefore, all ZLIB routines are loaded at run time
49 * and we do not link to a .LIB file.
50 */
51#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
52# include <windows.h>
53
54# define Z_CALLCONV _stdcall
55# define ZLIB_SHARED
56#else
57# define Z_CALLCONV
58#endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */
59
60#ifdef ZLIB_SHARED
61#include <openssl/dso.h>
62
63/* Prototypes for built in stubs */
64static int stub_compress(Bytef *dest,uLongf *destLen,
65 const Bytef *source, uLong sourceLen);
66static int stub_inflateEnd(z_streamp strm);
67static int stub_inflate(z_streamp strm, int flush);
68static int stub_inflateInit_(z_streamp strm, const char * version,
69 int stream_size);
70
71/* Function pointers */
72typedef int (Z_CALLCONV *compress_ft)(Bytef *dest,uLongf *destLen,
73 const Bytef *source, uLong sourceLen);
74typedef int (Z_CALLCONV *inflateEnd_ft)(z_streamp strm);
75typedef int (Z_CALLCONV *inflate_ft)(z_streamp strm, int flush);
76typedef int (Z_CALLCONV *inflateInit__ft)(z_streamp strm,
77 const char * version, int stream_size);
78static compress_ft p_compress=NULL;
79static inflateEnd_ft p_inflateEnd=NULL;
80static inflate_ft p_inflate=NULL;
81static inflateInit__ft p_inflateInit_=NULL;
82
83static int zlib_loaded = 0; /* only attempt to init func pts once */
84static DSO *zlib_dso = NULL;
85
86#define compress stub_compress
87#define inflateEnd stub_inflateEnd
88#define inflate stub_inflate
89#define inflateInit_ stub_inflateInit_
90#endif /* ZLIB_SHARED */
91
43static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, 92static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
44 unsigned int olen, unsigned char *in, unsigned int ilen) 93 unsigned int olen, unsigned char *in, unsigned int ilen)
45 { 94 {
@@ -66,7 +115,10 @@ static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
66 memcpy(&(out[1]),in,ilen); 115 memcpy(&(out[1]),in,ilen);
67 l=ilen+1; 116 l=ilen+1;
68 } 117 }
69fprintf(stderr,"compress(%4d)->%4d %s\n",ilen,(int)l,(clear)?"clear":"zlib"); 118#ifdef DEBUG_ZLIB
119 fprintf(stderr,"compress(%4d)->%4d %s\n",
120 ilen,(int)l,(clear)?"clear":"zlib");
121#endif
70 return((int)l); 122 return((int)l);
71 } 123 }
72 124
@@ -88,7 +140,10 @@ static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
88 memcpy(out,&(in[1]),ilen-1); 140 memcpy(out,&(in[1]),ilen-1);
89 l=ilen-1; 141 l=ilen-1;
90 } 142 }
91 fprintf(stderr,"expand (%4d)->%4d %s\n",ilen,(int)l,in[0]?"zlib":"clear"); 143#ifdef DEBUG_ZLIB
144 fprintf(stderr,"expand (%4d)->%4d %s\n",
145 ilen,(int)l,in[0]?"zlib":"clear");
146#endif
92 return((int)l); 147 return((int)l);
93 } 148 }
94 149
@@ -128,6 +183,78 @@ static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
128 183
129COMP_METHOD *COMP_zlib(void) 184COMP_METHOD *COMP_zlib(void)
130 { 185 {
131 return(&zlib_method); 186 COMP_METHOD *meth = &zlib_method_nozlib;
187
188#ifdef ZLIB_SHARED
189 if (!zlib_loaded)
190 {
191#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
192 zlib_dso = DSO_load(NULL, "ZLIB", NULL, 0);
193#else
194 zlib_dso = DSO_load(NULL, "z", NULL, 0);
195#endif
196 if (zlib_dso != NULL)
197 {
198 p_compress
199 = (compress_ft) DSO_bind_func(zlib_dso,
200 "compress");
201 p_inflateEnd
202 = (inflateEnd_ft) DSO_bind_func(zlib_dso,
203 "inflateEnd");
204 p_inflate
205 = (inflate_ft) DSO_bind_func(zlib_dso,
206 "inflate");
207 p_inflateInit_
208 = (inflateInit__ft) DSO_bind_func(zlib_dso,
209 "inflateInit_");
210 zlib_loaded++;
211 meth = &zlib_method;
212 }
213 }
214
215#elif defined(ZLIB)
216 meth = &zlib_method;
217#endif
218
219 return(meth);
220 }
221
222#ifdef ZLIB_SHARED
223/* Stubs for each function to be dynamicly loaded */
224static int
225stub_compress(Bytef *dest,uLongf *destLen,const Bytef *source, uLong sourceLen)
226 {
227 if (p_compress)
228 return(p_compress(dest,destLen,source,sourceLen));
229 else
230 return(Z_MEM_ERROR);
231 }
232
233static int
234stub_inflateEnd(z_streamp strm)
235 {
236 if ( p_inflateEnd )
237 return(p_inflateEnd(strm));
238 else
239 return(Z_MEM_ERROR);
240 }
241
242static int
243stub_inflate(z_streamp strm, int flush)
244 {
245 if ( p_inflate )
246 return(p_inflate(strm,flush));
247 else
248 return(Z_MEM_ERROR);
249 }
250
251static int
252stub_inflateInit_(z_streamp strm, const char * version, int stream_size)
253 {
254 if ( p_inflateInit_ )
255 return(p_inflateInit_(strm,version,stream_size));
256 else
257 return(Z_MEM_ERROR);
132 } 258 }
133 259
260#endif /* ZLIB_SHARED */
diff --git a/src/lib/libcrypto/comp/comp.h b/src/lib/libcrypto/comp/comp.h
index 0922609542..ab48b78ae9 100644
--- a/src/lib/libcrypto/comp/comp.h
+++ b/src/lib/libcrypto/comp/comp.h
@@ -39,14 +39,13 @@ int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
39int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, 39int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
40 unsigned char *in, int ilen); 40 unsigned char *in, int ilen);
41COMP_METHOD *COMP_rle(void ); 41COMP_METHOD *COMP_rle(void );
42#ifdef ZLIB
43COMP_METHOD *COMP_zlib(void ); 42COMP_METHOD *COMP_zlib(void );
44#endif
45 43
46/* BEGIN ERROR CODES */ 44/* BEGIN ERROR CODES */
47/* The following lines are auto generated by the script mkerr.pl. Any changes 45/* The following lines are auto generated by the script mkerr.pl. Any changes
48 * made after this point may be overwritten when the script is next run. 46 * made after this point may be overwritten when the script is next run.
49 */ 47 */
48void ERR_load_COMP_strings(void);
50 49
51/* Error codes for the COMP functions. */ 50/* Error codes for the COMP functions. */
52 51
@@ -58,4 +57,3 @@ COMP_METHOD *COMP_zlib(void );
58} 57}
59#endif 58#endif
60#endif 59#endif
61
diff --git a/src/lib/libcrypto/comp/comp_err.c b/src/lib/libcrypto/comp/comp_err.c
index c10282a73c..1652b8c2c4 100644
--- a/src/lib/libcrypto/comp/comp_err.c
+++ b/src/lib/libcrypto/comp/comp_err.c
@@ -63,7 +63,7 @@
63#include <openssl/comp.h> 63#include <openssl/comp.h>
64 64
65/* BEGIN ERROR CODES */ 65/* BEGIN ERROR CODES */
66#ifndef NO_ERR 66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA COMP_str_functs[]= 67static ERR_STRING_DATA COMP_str_functs[]=
68 { 68 {
69{0,NULL} 69{0,NULL}
@@ -83,7 +83,7 @@ void ERR_load_COMP_strings(void)
83 if (init) 83 if (init)
84 { 84 {
85 init=0; 85 init=0;
86#ifndef NO_ERR 86#ifndef OPENSSL_NO_ERR
87 ERR_load_strings(ERR_LIB_COMP,COMP_str_functs); 87 ERR_load_strings(ERR_LIB_COMP,COMP_str_functs);
88 ERR_load_strings(ERR_LIB_COMP,COMP_str_reasons); 88 ERR_load_strings(ERR_LIB_COMP,COMP_str_reasons);
89#endif 89#endif