summaryrefslogtreecommitdiff
path: root/lib/libcrypto/lhash
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>1999-09-29 04:37:45 +0000
committerBob Beck <beck@cvs.openbsd.org>1999-09-29 04:37:45 +0000
commitca679cff5e2a72ad205119c981e695c8cc640970 (patch)
tree691368331190f762b9f484d059ec119620396521 /lib/libcrypto/lhash
parent30902ef04e4a800063b5f4afdbf1732ad34aa6b3 (diff)
OpenSSL 0.9.4 merge
Diffstat (limited to 'lib/libcrypto/lhash')
-rw-r--r--lib/libcrypto/lhash/Makefile.ssl38
-rw-r--r--lib/libcrypto/lhash/lh_stats.c38
-rw-r--r--lib/libcrypto/lhash/lh_test.c2
-rw-r--r--lib/libcrypto/lhash/lhash.c97
-rw-r--r--lib/libcrypto/lhash/lhash.h33
-rw-r--r--lib/libcrypto/lhash/num.pl2
6 files changed, 88 insertions, 122 deletions
diff --git a/lib/libcrypto/lhash/Makefile.ssl b/lib/libcrypto/lhash/Makefile.ssl
index cb08547b4fc..cc9ff46b048 100644
--- a/lib/libcrypto/lhash/Makefile.ssl
+++ b/lib/libcrypto/lhash/Makefile.ssl
@@ -7,9 +7,11 @@ TOP= ../..
CC= cc
INCLUDES=
CFLAG=-g
+INSTALL_PREFIX=
+OPENSSLDIR= /usr/local/ssl
INSTALLTOP=/usr/local/ssl
MAKE= make -f Makefile.ssl
-MAKEDEPEND= makedepend -f Makefile.ssl
+MAKEDEPEND= $(TOP)/util/domd $(TOP)
MAKEFILE= Makefile.ssl
AR= ar r
@@ -37,24 +39,23 @@ all: lib
lib: $(LIBOBJ)
$(AR) $(LIB) $(LIBOBJ)
- sh $(TOP)/util/ranlib.sh $(LIB)
+ $(RANLIB) $(LIB)
@touch lib
files:
- perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
+ $(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)
+ @$(TOP)/util/point.sh Makefile.ssl Makefile
+ @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
+ @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
+ @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
install:
@for i in $(EXHEADER) ; \
do \
- (cp $$i $(INSTALLTOP)/include/$$i; \
- chmod 644 $(INSTALLTOP)/include/$$i ); \
+ (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
+ chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
done;
tags:
@@ -66,15 +67,22 @@ lint:
lint -DLINT $(INCLUDES) $(SRC)>fluff
depend:
- $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC)
+ $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
dclean:
- perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
+ $(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:
+ rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
# DO NOT DELETE THIS LINE -- make depend depends on it.
+
+lh_stats.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
+lh_stats.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
+lh_stats.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
+lh_stats.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+lh_stats.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
+lh_stats.o: ../cryptlib.h
+lhash.o: ../../include/openssl/crypto.h ../../include/openssl/lhash.h
+lhash.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
diff --git a/lib/libcrypto/lhash/lh_stats.c b/lib/libcrypto/lhash/lh_stats.c
index 23fe82f7778..80b931c12b7 100644
--- a/lib/libcrypto/lhash/lh_stats.c
+++ b/lib/libcrypto/lhash/lh_stats.c
@@ -63,13 +63,11 @@
* and things should work as expected */
#include "cryptlib.h"
-#include "lhash.h"
+#include <openssl/lhash.h>
#ifndef HEADER_BIO_H
-void lh_stats(lh, out)
-LHASH *lh;
-FILE *out;
+void lh_stats(LHASH *lh, FILE *out)
{
fprintf(out,"num_items = %lu\n",lh->num_items);
fprintf(out,"num_nodes = %u\n",lh->num_nodes);
@@ -95,9 +93,7 @@ FILE *out;
#endif
}
-void lh_node_stats(lh, out)
-LHASH *lh;
-FILE *out;
+void lh_node_stats(LHASH *lh, FILE *out)
{
LHASH_NODE *n;
unsigned int i,num;
@@ -110,9 +106,7 @@ FILE *out;
}
}
-void lh_node_usage_stats(lh, out)
-LHASH *lh;
-FILE *out;
+void lh_node_usage_stats(LHASH *lh, FILE *out)
{
LHASH_NODE *n;
unsigned long num;
@@ -142,9 +136,7 @@ FILE *out;
#else
#ifndef NO_FP_API
-void lh_stats(lh,fp)
-LHASH *lh;
-FILE *fp;
+void lh_stats(LHASH *lh, FILE *fp)
{
BIO *bp;
@@ -156,9 +148,7 @@ FILE *fp;
end:;
}
-void lh_node_stats(lh,fp)
-LHASH *lh;
-FILE *fp;
+void lh_node_stats(LHASH *lh, FILE *fp)
{
BIO *bp;
@@ -170,9 +160,7 @@ FILE *fp;
end:;
}
-void lh_node_usage_stats(lh,fp)
-LHASH *lh;
-FILE *fp;
+void lh_node_usage_stats(LHASH *lh, FILE *fp)
{
BIO *bp;
@@ -186,9 +174,7 @@ end:;
#endif
-void lh_stats_bio(lh, out)
-LHASH *lh;
-BIO *out;
+void lh_stats_bio(LHASH *lh, BIO *out)
{
char buf[128];
@@ -236,9 +222,7 @@ BIO *out;
#endif
}
-void lh_node_stats_bio(lh, out)
-LHASH *lh;
-BIO *out;
+void lh_node_stats_bio(LHASH *lh, BIO *out)
{
LHASH_NODE *n;
unsigned int i,num;
@@ -253,9 +237,7 @@ BIO *out;
}
}
-void lh_node_usage_stats_bio(lh, out)
-LHASH *lh;
-BIO *out;
+void lh_node_usage_stats_bio(LHASH *lh, BIO *out)
{
LHASH_NODE *n;
unsigned long num;
diff --git a/lib/libcrypto/lhash/lh_test.c b/lib/libcrypto/lhash/lh_test.c
index 294b42bc829..08138b52c31 100644
--- a/lib/libcrypto/lhash/lh_test.c
+++ b/lib/libcrypto/lhash/lh_test.c
@@ -59,7 +59,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "lhash.h"
+#include <openssl/lhash.h>
main()
{
diff --git a/lib/libcrypto/lhash/lhash.c b/lib/libcrypto/lhash/lhash.c
index 6dfb5c9ccc8..801322beb64 100644
--- a/lib/libcrypto/lhash/lhash.c
+++ b/lib/libcrypto/lhash/lhash.c
@@ -56,11 +56,14 @@
* [including the GNU Public Licence.]
*/
-char *lh_version="lhash part of SSLeay 0.9.0b 29-Jun-1998";
-
/* Code for dynamic hash table routines
* Author - Eric Young v 2.0
*
+ * 2.2 eay - added #include "crypto.h" so the memory leak checking code is
+ * present. eay 18-Jun-98
+ *
+ * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98
+ *
* 2.0 eay - Fixed a bug that occured when using lh_delete
* from inside lh_doall(). As entries were deleted,
* the 'table' was 'contract()ed', making some entries
@@ -94,14 +97,16 @@ char *lh_version="lhash part of SSLeay 0.9.0b 29-Jun-1998";
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include "lhash.h"
+#include <openssl/crypto.h>
+#include <openssl/lhash.h>
+
+const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
#undef MIN_NODES
#define MIN_NODES 16
#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */
#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */
-#ifndef NOPROTO
#define P_CP char *
#define P_CPP char *,char *
@@ -109,26 +114,14 @@ static void expand(LHASH *lh);
static void contract(LHASH *lh);
static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash);
-#else
-
-#define P_CP
-#define P_CPP
-static void expand();
-static void contract();
-static LHASH_NODE **getrn();
-
-#endif
-
-LHASH *lh_new(h, c)
-unsigned long (*h)();
-int (*c)();
+LHASH *lh_new(unsigned long (*h)(), int (*c)())
{
LHASH *ret;
int i;
- if ((ret=(LHASH *)malloc(sizeof(LHASH))) == NULL)
+ if ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL)
goto err0;
- if ((ret->b=(LHASH_NODE **)malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
+ if ((ret->b=(LHASH_NODE **)Malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
goto err1;
for (i=0; i<MIN_NODES; i++)
ret->b[i]=NULL;
@@ -156,41 +149,43 @@ int (*c)();
ret->num_retrieve_miss=0;
ret->num_hash_comps=0;
+ ret->error=0;
return(ret);
err1:
- free((char *)ret);
+ Free((char *)ret);
err0:
return(NULL);
}
-void lh_free(lh)
-LHASH *lh;
+void lh_free(LHASH *lh)
{
unsigned int i;
LHASH_NODE *n,*nn;
+ if(lh == NULL)
+ return;
+
for (i=0; i<lh->num_nodes; i++)
{
n=lh->b[i];
while (n != NULL)
{
nn=n->next;
- free(n);
+ Free(n);
n=nn;
}
}
- free((char *)lh->b);
- free((char *)lh);
+ Free((char *)lh->b);
+ Free((char *)lh);
}
-char *lh_insert(lh, data)
-LHASH *lh;
-char *data;
+char *lh_insert(LHASH *lh, char *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
char *ret;
+ lh->error=0;
if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
expand(lh);
@@ -198,8 +193,11 @@ char *data;
if (*rn == NULL)
{
- if ((nn=(LHASH_NODE *)malloc(sizeof(LHASH_NODE))) == NULL)
+ if ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL)
+ {
+ lh->error++;
return(NULL);
+ }
nn->data=data;
nn->next=NULL;
#ifndef NO_HASH_COMP
@@ -219,14 +217,13 @@ char *data;
return(ret);
}
-char *lh_delete(lh, data)
-LHASH *lh;
-char *data;
+char *lh_delete(LHASH *lh, char *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
char *ret;
+ lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
@@ -239,7 +236,7 @@ char *data;
nn= *rn;
*rn=nn->next;
ret=nn->data;
- free((char *)nn);
+ Free((char *)nn);
lh->num_delete++;
}
@@ -251,14 +248,13 @@ char *data;
return(ret);
}
-char *lh_retrieve(lh, data)
-LHASH *lh;
-char *data;
+char *lh_retrieve(LHASH *lh, char *data)
{
unsigned long hash;
LHASH_NODE **rn;
char *ret;
+ lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
@@ -274,17 +270,12 @@ char *data;
return(ret);
}
-void lh_doall(lh, func)
-LHASH *lh;
-void (*func)();
+void lh_doall(LHASH *lh, void (*func)())
{
lh_doall_arg(lh,func,NULL);
}
-void lh_doall_arg(lh, func, arg)
-LHASH *lh;
-void (*func)();
-char *arg;
+void lh_doall_arg(LHASH *lh, void (*func)(), char *arg)
{
int i;
LHASH_NODE *a,*n;
@@ -305,8 +296,7 @@ char *arg;
}
}
-static void expand(lh)
-LHASH *lh;
+static void expand(LHASH *lh)
{
LHASH_NODE **n,**n1,**n2,*np;
unsigned int p,i,j;
@@ -342,11 +332,12 @@ LHASH *lh;
if ((lh->p) >= lh->pmax)
{
j=(int)lh->num_alloc_nodes*2;
- n=(LHASH_NODE **)realloc((char *)lh->b,
+ n=(LHASH_NODE **)Realloc((char *)lh->b,
(unsigned int)sizeof(LHASH_NODE *)*j);
if (n == NULL)
{
/* fputs("realloc error in lhash",stderr); */
+ lh->error++;
lh->p=0;
return;
}
@@ -361,8 +352,7 @@ LHASH *lh;
}
}
-static void contract(lh)
-LHASH *lh;
+static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
@@ -370,11 +360,12 @@ LHASH *lh;
lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
if (lh->p == 0)
{
- n=(LHASH_NODE **)realloc((char *)lh->b,
+ n=(LHASH_NODE **)Realloc((char *)lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
/* fputs("realloc error in lhash",stderr); */
+ lh->error++;
return;
}
lh->num_contract_reallocs++;
@@ -400,10 +391,7 @@ LHASH *lh;
}
}
-static LHASH_NODE **getrn(lh, data, rhash)
-LHASH *lh;
-char *data;
-unsigned long *rhash;
+static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash)
{
LHASH_NODE **ret,*n1;
unsigned long hash,nn;
@@ -457,8 +445,7 @@ char *str;
* no collisions on /usr/dict/words and it distributes on %2^n quite
* well, not as good as MD5, but still good.
*/
-unsigned long lh_strhash(c)
-char *c;
+unsigned long lh_strhash(const char *c)
{
unsigned long ret=0;
long n;
diff --git a/lib/libcrypto/lhash/lhash.h b/lib/libcrypto/lhash/lhash.h
index 70cbc6dfe70..6e5a1fe7085 100644
--- a/lib/libcrypto/lhash/lhash.h
+++ b/lib/libcrypto/lhash/lhash.h
@@ -67,6 +67,10 @@
extern "C" {
#endif
+#ifndef NO_FP_API
+#include <stdio.h>
+#endif
+
typedef struct lhash_node_st
{
char *data;
@@ -102,11 +106,16 @@ typedef struct lhash_st
unsigned long num_retrieve;
unsigned long num_retrieve_miss;
unsigned long num_hash_comps;
+
+ int error;
} LHASH;
#define LH_LOAD_MULT 256
-#ifndef NOPROTO
+/* Indicates a malloc() error in the last call, this is only bad
+ * in lh_insert(). */
+#define lh_error(lh) ((lh)->error)
+
LHASH *lh_new(unsigned long (*h)(), int (*c)());
void lh_free(LHASH *lh);
char *lh_insert(LHASH *lh, char *data);
@@ -114,7 +123,7 @@ char *lh_delete(LHASH *lh, char *data);
char *lh_retrieve(LHASH *lh, char *data);
void lh_doall(LHASH *lh, void (*func)(/* char *b */));
void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg);
-unsigned long lh_strhash(char *c);
+unsigned long lh_strhash(const char *c);
#ifndef NO_FP_API
void lh_stats(LHASH *lh, FILE *out);
@@ -127,26 +136,6 @@ void lh_stats_bio(LHASH *lh, BIO *out);
void lh_node_stats_bio(LHASH *lh, BIO *out);
void lh_node_usage_stats_bio(LHASH *lh, BIO *out);
#endif
-#else
-LHASH *lh_new();
-void lh_free();
-char *lh_insert();
-char *lh_delete();
-char *lh_retrieve();
-void lh_doall();
-void lh_doall_arg();
-unsigned long lh_strhash();
-
-#ifndef NO_FP_API
-void lh_stats();
-void lh_node_stats();
-void lh_node_usage_stats();
-#endif
-void lh_stats_bio();
-void lh_node_stats_bio();
-void lh_node_usage_stats_bio();
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/lib/libcrypto/lhash/num.pl b/lib/libcrypto/lhash/num.pl
index 4d937c1f903..30fedf9cd5a 100644
--- a/lib/libcrypto/lhash/num.pl
+++ b/lib/libcrypto/lhash/num.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/local/bin/perl
#node 10 -> 4