diff options
Diffstat (limited to 'crypto/comp')
-rw-r--r-- | crypto/comp/Makefile.ssl | 87 | ||||
-rw-r--r-- | crypto/comp/c_rle.c | 69 | ||||
-rw-r--r-- | crypto/comp/c_zlib.c | 144 | ||||
-rw-r--r-- | crypto/comp/comp.err | 0 | ||||
-rw-r--r-- | crypto/comp/comp.h | 64 | ||||
-rw-r--r-- | crypto/comp/comp_err.c | 77 | ||||
-rw-r--r-- | crypto/comp/comp_lib.c | 85 |
7 files changed, 526 insertions, 0 deletions
diff --git a/crypto/comp/Makefile.ssl b/crypto/comp/Makefile.ssl new file mode 100644 index 0000000000..8673626c94 --- /dev/null +++ b/crypto/comp/Makefile.ssl @@ -0,0 +1,87 @@ +# +# SSLeay/crypto/comp/Makefile +# + +DIR= comp +TOP= ../.. +CC= cc +INCLUDES= -I.. -I../../include +CFLAG=-g +INSTALLTOP=/usr/local/ssl +MAKE= make -f Makefile.ssl +MAKEDEPEND= makedepend -f Makefile.ssl +MAKEFILE= Makefile.ssl +AR= ar r + +CFLAGS= $(INCLUDES) $(CFLAG) + +ERR=comp +ERRC=comp_err +GENERAL=Makefile +TEST= +APPS= + +LIB=$(TOP)/libcrypto.a +LIBSRC= comp_lib.c \ + c_rle.c c_zlib.c + +LIBOBJ= comp_lib.o \ + c_rle.o c_zlib.o + +SRC= $(LIBSRC) + +EXHEADER= comp.h +HEADER= $(EXHEADER) + +ALL= $(GENERAL) $(SRC) $(HEADER) + +top: + (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) + +all: lib + +lib: $(LIBOBJ) + $(AR) $(LIB) $(LIBOBJ) + sh $(TOP)/util/ranlib.sh $(LIB) + @touch lib + +files: + perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + +links: + /bin/rm -f Makefile + $(TOP)/util/point.sh Makefile.ssl Makefile ; + $(TOP)/util/mklink.sh ../../include $(EXHEADER) + $(TOP)/util/mklink.sh ../../test $(TEST) + $(TOP)/util/mklink.sh ../../apps $(APPS) + +install: + @for i in $(EXHEADER) ; \ + do \ + (cp $$i $(INSTALLTOP)/include/$$i; \ + chmod 644 $(INSTALLTOP)/include/$$i ); \ + done; + +tags: + ctags $(SRC) + +tests: + +lint: + lint -DLINT $(INCLUDES) $(SRC)>fluff + +depend: + $(MAKEDEPEND) $(INCLUDES) $(LIBSRC) + +dclean: + perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + +clean: + /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + +errors: + perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h + perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + +# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/crypto/comp/c_rle.c b/crypto/comp/c_rle.c new file mode 100644 index 0000000000..b8b9b3e1bc --- /dev/null +++ b/crypto/comp/c_rle.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "objects.h" +#include "comp.h" + +static int rle_compress_block(COMP_CTX *ctx, unsigned char *out, + unsigned int olen, unsigned char *in, unsigned int ilen); +static int rle_expand_block(COMP_CTX *ctx, unsigned char *out, + unsigned int olen, unsigned char *in, unsigned int ilen); + +static COMP_METHOD rle_method={ + NID_rle_compression, + LN_rle_compression, + NULL, + NULL, + rle_compress_block, + rle_expand_block, + NULL, + }; + +COMP_METHOD *COMP_rle() + { + return(&rle_method); + } + +static int rle_compress_block(ctx,out,olen,in,ilen) +COMP_CTX *ctx; +unsigned char *out; +unsigned int olen; +unsigned char *in; +unsigned int ilen; + { + /* int i; */ + + if (olen < (ilen+1)) + { + /* ZZZZZZZZZZZZZZZZZZZZZZ */ + return(-1); + } + + *(out++)=0; + memcpy(out,in,ilen); + return(ilen+1); + } + +static int rle_expand_block(ctx,out,olen,in,ilen) +COMP_CTX *ctx; +unsigned char *out; +unsigned int olen; +unsigned char *in; +unsigned int ilen; + { + int i; + + if (olen < (ilen-1)) + { + /* ZZZZZZZZZZZZZZZZZZZZZZ */ + return(-1); + } + + i= *(in++); + if (i == 0) + { + memcpy(out,in,ilen-1); + } + return(ilen-1); + } + diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c new file mode 100644 index 0000000000..35ab0c63dc --- /dev/null +++ b/crypto/comp/c_zlib.c @@ -0,0 +1,144 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "objects.h" +#include "comp.h" + +COMP_METHOD *COMP_zlib(void ); + +#ifndef ZLIB + +static COMP_METHOD zlib_method={ + NID_undef, + "(null)", + NULL, + NULL, + NULL, + NULL, + NULL, + }; + +#else + +#include <zlib.h> + +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_method={ + NID_zlib_compression, + LN_zlib_compression, + NULL, + NULL, + zlib_compress_block, + zlib_expand_block, + NULL, + }; + +static int zlib_compress_block(ctx,out,olen,in,ilen) +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; + } +fprintf(stderr,"compress(%4d)->%4d %s\n",ilen,(int)l,(clear)?"clear":"zlib"); + return((int)l); + } + +static int zlib_expand_block(ctx,out,olen,in,ilen) +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; + } + fprintf(stderr,"expand (%4d)->%4d %s\n",ilen,(int)l,in[0]?"zlib":"clear"); + return((int)l); + } + +static int zz_uncompress (dest, destLen, source, sourceLen) + 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); + 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 + +COMP_METHOD *COMP_zlib() + { + return(&zlib_method); + } + diff --git a/crypto/comp/comp.err b/crypto/comp/comp.err new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/crypto/comp/comp.err diff --git a/crypto/comp/comp.h b/crypto/comp/comp.h new file mode 100644 index 0000000000..00af0622b9 --- /dev/null +++ b/crypto/comp/comp.h @@ -0,0 +1,64 @@ + +#ifndef HEADER_COMP_H +#define HEADER_COMP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "crypto.h" + +typedef struct comp_method_st + { + int type; /* NID for compression library */ + char *name; /* A text string to identify the library */ + int (*init)(); + void (*finish)(); + int (*compress)(); + int (*expand)(); + long (*ctrl)(); + } COMP_METHOD; + +typedef struct comp_ctx_st + { + COMP_METHOD *meth; + unsigned long compress_in; + unsigned long compress_out; + unsigned long expand_in; + unsigned long expand_out; + + CRYPTO_EX_DATA ex_data; + } COMP_CTX; + +#ifndef NOPROTO + +COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); +void COMP_CTX_free(COMP_CTX *ctx); +int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, + unsigned char *in, int ilen); +int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, + unsigned char *in, int ilen); +COMP_METHOD *COMP_rle(void ); +#ifdef ZLIB +COMP_METHOD *COMP_zlib(void ); +#endif + +#else + +COMP_CTX *COMP_CTX_new(); +void COMP_CTX_free(); +int COMP_compress_block(); +int COMP_expand_block(); +COMP_METHOD *COMP_rle(); +#ifdef ZLIB +COMP_METHOD *COMP_zlib(); +#endif + +#endif +/* BEGIN ERROR CODES */ + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/crypto/comp/comp_err.c b/crypto/comp/comp_err.c new file mode 100644 index 0000000000..7b68fc1b9d --- /dev/null +++ b/crypto/comp/comp_err.c @@ -0,0 +1,77 @@ +/* lib//_err.c */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +#include <stdio.h> +#include "err.h" +#include "comp.h" + +/* BEGIN ERROR CODES */ +#ifndef NO_ERR +#endif + +void ERR_load__strings() + { + static int init=1; + + if (init) + { + init=0; +#ifndef NO_ERR +#endif + + } + } diff --git a/crypto/comp/comp_lib.c b/crypto/comp/comp_lib.c new file mode 100644 index 0000000000..8ce06951af --- /dev/null +++ b/crypto/comp/comp_lib.c @@ -0,0 +1,85 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "objects.h" +#include "comp.h" + +COMP_CTX *COMP_CTX_new(meth) +COMP_METHOD *meth; + { + COMP_CTX *ret; + + if ((ret=(COMP_CTX *)Malloc(sizeof(COMP_CTX))) == NULL) + { + /* ZZZZZZZZZZZZZZZZ */ + return(NULL); + } + memset(ret,0,sizeof(COMP_CTX)); + ret->meth=meth; + if ((ret->meth->init != NULL) && !ret->meth->init(ret)) + { + Free(ret); + ret=NULL; + } +#if 0 + else + CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data); +#endif + return(ret); + } + +void COMP_CTX_free(ctx) +COMP_CTX *ctx; + { + /* CRYPTO_free_ex_data(rsa_meth,(char *)ctx,&ctx->ex_data); */ + + if (ctx->meth->finish != NULL) + ctx->meth->finish(ctx); + + Free(ctx); + } + +int COMP_compress_block(ctx,out,olen,in,ilen) +COMP_CTX *ctx; +unsigned char *out; +int olen; +unsigned char *in; +int ilen; + { + int ret; + if (ctx->meth->compress == NULL) + { + /* ZZZZZZZZZZZZZZZZZ */ + return(-1); + } + ret=ctx->meth->compress(ctx,out,olen,in,ilen); + if (ret > 0) + { + ctx->compress_in+=ilen; + ctx->compress_out+=ret; + } + return(ret); + } + +int COMP_expand_block(ctx,out,olen,in,ilen) +COMP_CTX *ctx; +unsigned char *out; +int olen; +unsigned char *in; +int ilen; + { + int ret; + + if (ctx->meth->expand == NULL) + { + /* ZZZZZZZZZZZZZZZZZ */ + return(-1); + } + ret=ctx->meth->expand(ctx,out,olen,in,ilen); + if (ret > 0) + { + ctx->expand_in+=ilen; + ctx->expand_out+=ret; + } + return(ret); + } |