summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/lhash
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>1999-10-10 21:32:03 +0000
committercvs2svn <admin@example.com>1999-10-10 21:32:03 +0000
commit14e61fef302fbc25ab63e38bd35445637ca68139 (patch)
treedae5e50679bccd1ed8d7d4041fbb9f3d96bbc98c /src/lib/libcrypto/lhash
parent3ef9529fbf0c1f8f1c9da1172e92ad3370d5fcfe (diff)
downloadopenbsd-OPENBSD_2_6_BASE.tar.gz
openbsd-OPENBSD_2_6_BASE.tar.bz2
openbsd-OPENBSD_2_6_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_2_6_BASE'.OPENBSD_2_6_BASE
Diffstat (limited to 'src/lib/libcrypto/lhash')
-rw-r--r--src/lib/libcrypto/lhash/lh_stats.c271
-rw-r--r--src/lib/libcrypto/lhash/lhash.c476
-rw-r--r--src/lib/libcrypto/lhash/lhash.h144
3 files changed, 0 insertions, 891 deletions
diff --git a/src/lib/libcrypto/lhash/lh_stats.c b/src/lib/libcrypto/lhash/lh_stats.c
deleted file mode 100644
index 80b931c12b..0000000000
--- a/src/lib/libcrypto/lhash/lh_stats.c
+++ /dev/null
@@ -1,271 +0,0 @@
1/* crypto/lhash/lh_stats.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62/* If you wish to build this outside of SSLeay, remove the following lines
63 * and things should work as expected */
64#include "cryptlib.h"
65
66#include <openssl/lhash.h>
67
68#ifndef HEADER_BIO_H
69
70void lh_stats(LHASH *lh, FILE *out)
71 {
72 fprintf(out,"num_items = %lu\n",lh->num_items);
73 fprintf(out,"num_nodes = %u\n",lh->num_nodes);
74 fprintf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
75 fprintf(out,"num_expands = %lu\n",lh->num_expands);
76 fprintf(out,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs);
77 fprintf(out,"num_contracts = %lu\n",lh->num_contracts);
78 fprintf(out,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs);
79 fprintf(out,"num_hash_calls = %lu\n",lh->num_hash_calls);
80 fprintf(out,"num_comp_calls = %lu\n",lh->num_comp_calls);
81 fprintf(out,"num_insert = %lu\n",lh->num_insert);
82 fprintf(out,"num_replace = %lu\n",lh->num_replace);
83 fprintf(out,"num_delete = %lu\n",lh->num_delete);
84 fprintf(out,"num_no_delete = %lu\n",lh->num_no_delete);
85 fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve);
86 fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
87 fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps);
88#ifdef DEBUG
89 fprintf(out,"p = %u\n",lh->p);
90 fprintf(out,"pmax = %u\n",lh->pmax);
91 fprintf(out,"up_load = %lu\n",lh->up_load);
92 fprintf(out,"down_load = %lu\n",lh->down_load);
93#endif
94 }
95
96void lh_node_stats(LHASH *lh, FILE *out)
97 {
98 LHASH_NODE *n;
99 unsigned int i,num;
100
101 for (i=0; i<lh->num_nodes; i++)
102 {
103 for (n=lh->b[i],num=0; n != NULL; n=n->next)
104 num++;
105 fprintf(out,"node %6u -> %3u\n",i,num);
106 }
107 }
108
109void lh_node_usage_stats(LHASH *lh, FILE *out)
110 {
111 LHASH_NODE *n;
112 unsigned long num;
113 unsigned int i;
114 unsigned long total=0,n_used=0;
115
116 for (i=0; i<lh->num_nodes; i++)
117 {
118 for (n=lh->b[i],num=0; n != NULL; n=n->next)
119 num++;
120 if (num != 0)
121 {
122 n_used++;
123 total+=num;
124 }
125 }
126 fprintf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
127 fprintf(out,"%lu items\n",total);
128 if (n_used == 0) return;
129 fprintf(out,"load %d.%02d actual load %d.%02d\n",
130 (int)(total/lh->num_nodes),
131 (int)((total%lh->num_nodes)*100/lh->num_nodes),
132 (int)(total/n_used),
133 (int)((total%n_used)*100/n_used));
134 }
135
136#else
137
138#ifndef NO_FP_API
139void lh_stats(LHASH *lh, FILE *fp)
140 {
141 BIO *bp;
142
143 bp=BIO_new(BIO_s_file());
144 if (bp == NULL) goto end;
145 BIO_set_fp(bp,fp,BIO_NOCLOSE);
146 lh_stats_bio(lh,bp);
147 BIO_free(bp);
148end:;
149 }
150
151void lh_node_stats(LHASH *lh, FILE *fp)
152 {
153 BIO *bp;
154
155 bp=BIO_new(BIO_s_file());
156 if (bp == NULL) goto end;
157 BIO_set_fp(bp,fp,BIO_NOCLOSE);
158 lh_node_stats_bio(lh,bp);
159 BIO_free(bp);
160end:;
161 }
162
163void lh_node_usage_stats(LHASH *lh, FILE *fp)
164 {
165 BIO *bp;
166
167 bp=BIO_new(BIO_s_file());
168 if (bp == NULL) goto end;
169 BIO_set_fp(bp,fp,BIO_NOCLOSE);
170 lh_node_usage_stats_bio(lh,bp);
171 BIO_free(bp);
172end:;
173 }
174
175#endif
176
177void lh_stats_bio(LHASH *lh, BIO *out)
178 {
179 char buf[128];
180
181 sprintf(buf,"num_items = %lu\n",lh->num_items);
182 BIO_puts(out,buf);
183 sprintf(buf,"num_nodes = %u\n",lh->num_nodes);
184 BIO_puts(out,buf);
185 sprintf(buf,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
186 BIO_puts(out,buf);
187 sprintf(buf,"num_expands = %lu\n",lh->num_expands);
188 BIO_puts(out,buf);
189 sprintf(buf,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs);
190 BIO_puts(out,buf);
191 sprintf(buf,"num_contracts = %lu\n",lh->num_contracts);
192 BIO_puts(out,buf);
193 sprintf(buf,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs);
194 BIO_puts(out,buf);
195 sprintf(buf,"num_hash_calls = %lu\n",lh->num_hash_calls);
196 BIO_puts(out,buf);
197 sprintf(buf,"num_comp_calls = %lu\n",lh->num_comp_calls);
198 BIO_puts(out,buf);
199 sprintf(buf,"num_insert = %lu\n",lh->num_insert);
200 BIO_puts(out,buf);
201 sprintf(buf,"num_replace = %lu\n",lh->num_replace);
202 BIO_puts(out,buf);
203 sprintf(buf,"num_delete = %lu\n",lh->num_delete);
204 BIO_puts(out,buf);
205 sprintf(buf,"num_no_delete = %lu\n",lh->num_no_delete);
206 BIO_puts(out,buf);
207 sprintf(buf,"num_retrieve = %lu\n",lh->num_retrieve);
208 BIO_puts(out,buf);
209 sprintf(buf,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
210 BIO_puts(out,buf);
211 sprintf(buf,"num_hash_comps = %lu\n",lh->num_hash_comps);
212 BIO_puts(out,buf);
213#ifdef DEBUG
214 sprintf(buf,"p = %u\n",lh->p);
215 BIO_puts(out,buf);
216 sprintf(buf,"pmax = %u\n",lh->pmax);
217 BIO_puts(out,buf);
218 sprintf(buf,"up_load = %lu\n",lh->up_load);
219 BIO_puts(out,buf);
220 sprintf(buf,"down_load = %lu\n",lh->down_load);
221 BIO_puts(out,buf);
222#endif
223 }
224
225void lh_node_stats_bio(LHASH *lh, BIO *out)
226 {
227 LHASH_NODE *n;
228 unsigned int i,num;
229 char buf[128];
230
231 for (i=0; i<lh->num_nodes; i++)
232 {
233 for (n=lh->b[i],num=0; n != NULL; n=n->next)
234 num++;
235 sprintf(buf,"node %6u -> %3u\n",i,num);
236 BIO_puts(out,buf);
237 }
238 }
239
240void lh_node_usage_stats_bio(LHASH *lh, BIO *out)
241 {
242 LHASH_NODE *n;
243 unsigned long num;
244 unsigned int i;
245 unsigned long total=0,n_used=0;
246 char buf[128];
247
248 for (i=0; i<lh->num_nodes; i++)
249 {
250 for (n=lh->b[i],num=0; n != NULL; n=n->next)
251 num++;
252 if (num != 0)
253 {
254 n_used++;
255 total+=num;
256 }
257 }
258 sprintf(buf,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
259 BIO_puts(out,buf);
260 sprintf(buf,"%lu items\n",total);
261 BIO_puts(out,buf);
262 if (n_used == 0) return;
263 sprintf(buf,"load %d.%02d actual load %d.%02d\n",
264 (int)(total/lh->num_nodes),
265 (int)((total%lh->num_nodes)*100/lh->num_nodes),
266 (int)(total/n_used),
267 (int)((total%n_used)*100/n_used));
268 BIO_puts(out,buf);
269 }
270
271#endif
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c
deleted file mode 100644
index 801322beb6..0000000000
--- a/src/lib/libcrypto/lhash/lhash.c
+++ /dev/null
@@ -1,476 +0,0 @@
1/* crypto/lhash/lhash.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Code for dynamic hash table routines
60 * Author - Eric Young v 2.0
61 *
62 * 2.2 eay - added #include "crypto.h" so the memory leak checking code is
63 * present. eay 18-Jun-98
64 *
65 * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98
66 *
67 * 2.0 eay - Fixed a bug that occured when using lh_delete
68 * from inside lh_doall(). As entries were deleted,
69 * the 'table' was 'contract()ed', making some entries
70 * jump from the end of the table to the start, there by
71 * skiping the lh_doall() processing. eay - 4/12/95
72 *
73 * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs
74 * were not being free()ed. 21/11/95
75 *
76 * 1.8 eay - Put the stats routines into a separate file, lh_stats.c
77 * 19/09/95
78 *
79 * 1.7 eay - Removed the fputs() for realloc failures - the code
80 * should silently tolerate them. I have also fixed things
81 * lint complained about 04/05/95
82 *
83 * 1.6 eay - Fixed an invalid pointers in contract/expand 27/07/92
84 *
85 * 1.5 eay - Fixed a misuse of realloc in expand 02/03/1992
86 *
87 * 1.4 eay - Fixed lh_doall so the function can call lh_delete 28/05/91
88 *
89 * 1.3 eay - Fixed a few lint problems 19/3/1991
90 *
91 * 1.2 eay - Fixed lh_doall problem 13/3/1991
92 *
93 * 1.1 eay - Added lh_doall
94 *
95 * 1.0 eay - First version
96 */
97#include <stdio.h>
98#include <string.h>
99#include <stdlib.h>
100#include <openssl/crypto.h>
101#include <openssl/lhash.h>
102
103const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
104
105#undef MIN_NODES
106#define MIN_NODES 16
107#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */
108#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */
109
110
111#define P_CP char *
112#define P_CPP char *,char *
113static void expand(LHASH *lh);
114static void contract(LHASH *lh);
115static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash);
116
117LHASH *lh_new(unsigned long (*h)(), int (*c)())
118 {
119 LHASH *ret;
120 int i;
121
122 if ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL)
123 goto err0;
124 if ((ret->b=(LHASH_NODE **)Malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
125 goto err1;
126 for (i=0; i<MIN_NODES; i++)
127 ret->b[i]=NULL;
128 ret->comp=((c == NULL)?(int (*)())strcmp:c);
129 ret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h);
130 ret->num_nodes=MIN_NODES/2;
131 ret->num_alloc_nodes=MIN_NODES;
132 ret->p=0;
133 ret->pmax=MIN_NODES/2;
134 ret->up_load=UP_LOAD;
135 ret->down_load=DOWN_LOAD;
136 ret->num_items=0;
137
138 ret->num_expands=0;
139 ret->num_expand_reallocs=0;
140 ret->num_contracts=0;
141 ret->num_contract_reallocs=0;
142 ret->num_hash_calls=0;
143 ret->num_comp_calls=0;
144 ret->num_insert=0;
145 ret->num_replace=0;
146 ret->num_delete=0;
147 ret->num_no_delete=0;
148 ret->num_retrieve=0;
149 ret->num_retrieve_miss=0;
150 ret->num_hash_comps=0;
151
152 ret->error=0;
153 return(ret);
154err1:
155 Free((char *)ret);
156err0:
157 return(NULL);
158 }
159
160void lh_free(LHASH *lh)
161 {
162 unsigned int i;
163 LHASH_NODE *n,*nn;
164
165 if(lh == NULL)
166 return;
167
168 for (i=0; i<lh->num_nodes; i++)
169 {
170 n=lh->b[i];
171 while (n != NULL)
172 {
173 nn=n->next;
174 Free(n);
175 n=nn;
176 }
177 }
178 Free((char *)lh->b);
179 Free((char *)lh);
180 }
181
182char *lh_insert(LHASH *lh, char *data)
183 {
184 unsigned long hash;
185 LHASH_NODE *nn,**rn;
186 char *ret;
187
188 lh->error=0;
189 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
190 expand(lh);
191
192 rn=getrn(lh,data,&hash);
193
194 if (*rn == NULL)
195 {
196 if ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL)
197 {
198 lh->error++;
199 return(NULL);
200 }
201 nn->data=data;
202 nn->next=NULL;
203#ifndef NO_HASH_COMP
204 nn->hash=hash;
205#endif
206 *rn=nn;
207 ret=NULL;
208 lh->num_insert++;
209 lh->num_items++;
210 }
211 else /* replace same key */
212 {
213 ret= (*rn)->data;
214 (*rn)->data=data;
215 lh->num_replace++;
216 }
217 return(ret);
218 }
219
220char *lh_delete(LHASH *lh, char *data)
221 {
222 unsigned long hash;
223 LHASH_NODE *nn,**rn;
224 char *ret;
225
226 lh->error=0;
227 rn=getrn(lh,data,&hash);
228
229 if (*rn == NULL)
230 {
231 lh->num_no_delete++;
232 return(NULL);
233 }
234 else
235 {
236 nn= *rn;
237 *rn=nn->next;
238 ret=nn->data;
239 Free((char *)nn);
240 lh->num_delete++;
241 }
242
243 lh->num_items--;
244 if ((lh->num_nodes > MIN_NODES) &&
245 (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
246 contract(lh);
247
248 return(ret);
249 }
250
251char *lh_retrieve(LHASH *lh, char *data)
252 {
253 unsigned long hash;
254 LHASH_NODE **rn;
255 char *ret;
256
257 lh->error=0;
258 rn=getrn(lh,data,&hash);
259
260 if (*rn == NULL)
261 {
262 lh->num_retrieve_miss++;
263 return(NULL);
264 }
265 else
266 {
267 ret= (*rn)->data;
268 lh->num_retrieve++;
269 }
270 return(ret);
271 }
272
273void lh_doall(LHASH *lh, void (*func)())
274 {
275 lh_doall_arg(lh,func,NULL);
276 }
277
278void lh_doall_arg(LHASH *lh, void (*func)(), char *arg)
279 {
280 int i;
281 LHASH_NODE *a,*n;
282
283 /* reverse the order so we search from 'top to bottom'
284 * We were having memory leaks otherwise */
285 for (i=lh->num_nodes-1; i>=0; i--)
286 {
287 a=lh->b[i];
288 while (a != NULL)
289 {
290 /* 28/05/91 - eay - n added so items can be deleted
291 * via lh_doall */
292 n=a->next;
293 func(a->data,arg);
294 a=n;
295 }
296 }
297 }
298
299static void expand(LHASH *lh)
300 {
301 LHASH_NODE **n,**n1,**n2,*np;
302 unsigned int p,i,j;
303 unsigned long hash,nni;
304
305 lh->num_nodes++;
306 lh->num_expands++;
307 p=(int)lh->p++;
308 n1= &(lh->b[p]);
309 n2= &(lh->b[p+(int)lh->pmax]);
310 *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
311 nni=lh->num_alloc_nodes;
312
313 for (np= *n1; np != NULL; )
314 {
315#ifndef NO_HASH_COMP
316 hash=np->hash;
317#else
318 hash=(*(lh->hash))(np->data);
319 lh->num_hash_calls++;
320#endif
321 if ((hash%nni) != p)
322 { /* move it */
323 *n1= (*n1)->next;
324 np->next= *n2;
325 *n2=np;
326 }
327 else
328 n1= &((*n1)->next);
329 np= *n1;
330 }
331
332 if ((lh->p) >= lh->pmax)
333 {
334 j=(int)lh->num_alloc_nodes*2;
335 n=(LHASH_NODE **)Realloc((char *)lh->b,
336 (unsigned int)sizeof(LHASH_NODE *)*j);
337 if (n == NULL)
338 {
339/* fputs("realloc error in lhash",stderr); */
340 lh->error++;
341 lh->p=0;
342 return;
343 }
344 /* else */
345 for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
346 n[i]=NULL; /* 02/03/92 eay */
347 lh->pmax=lh->num_alloc_nodes;
348 lh->num_alloc_nodes=j;
349 lh->num_expand_reallocs++;
350 lh->p=0;
351 lh->b=n;
352 }
353 }
354
355static void contract(LHASH *lh)
356 {
357 LHASH_NODE **n,*n1,*np;
358
359 np=lh->b[lh->p+lh->pmax-1];
360 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
361 if (lh->p == 0)
362 {
363 n=(LHASH_NODE **)Realloc((char *)lh->b,
364 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
365 if (n == NULL)
366 {
367/* fputs("realloc error in lhash",stderr); */
368 lh->error++;
369 return;
370 }
371 lh->num_contract_reallocs++;
372 lh->num_alloc_nodes/=2;
373 lh->pmax/=2;
374 lh->p=lh->pmax-1;
375 lh->b=n;
376 }
377 else
378 lh->p--;
379
380 lh->num_nodes--;
381 lh->num_contracts++;
382
383 n1=lh->b[(int)lh->p];
384 if (n1 == NULL)
385 lh->b[(int)lh->p]=np;
386 else
387 {
388 while (n1->next != NULL)
389 n1=n1->next;
390 n1->next=np;
391 }
392 }
393
394static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash)
395 {
396 LHASH_NODE **ret,*n1;
397 unsigned long hash,nn;
398 int (*cf)();
399
400 hash=(*(lh->hash))(data);
401 lh->num_hash_calls++;
402 *rhash=hash;
403
404 nn=hash%lh->pmax;
405 if (nn < lh->p)
406 nn=hash%lh->num_alloc_nodes;
407
408 cf=lh->comp;
409 ret= &(lh->b[(int)nn]);
410 for (n1= *ret; n1 != NULL; n1=n1->next)
411 {
412#ifndef NO_HASH_COMP
413 lh->num_hash_comps++;
414 if (n1->hash != hash)
415 {
416 ret= &(n1->next);
417 continue;
418 }
419#endif
420 lh->num_comp_calls++;
421 if ((*cf)(n1->data,data) == 0)
422 break;
423 ret= &(n1->next);
424 }
425 return(ret);
426 }
427
428/*
429static unsigned long lh_strhash(str)
430char *str;
431 {
432 int i,l;
433 unsigned long ret=0;
434 unsigned short *s;
435
436 if (str == NULL) return(0);
437 l=(strlen(str)+1)/2;
438 s=(unsigned short *)str;
439 for (i=0; i<l; i++)
440 ret^=(s[i]<<(i&0x0f));
441 return(ret);
442 } */
443
444/* The following hash seems to work very well on normal text strings
445 * no collisions on /usr/dict/words and it distributes on %2^n quite
446 * well, not as good as MD5, but still good.
447 */
448unsigned long lh_strhash(const char *c)
449 {
450 unsigned long ret=0;
451 long n;
452 unsigned long v;
453 int r;
454
455 if ((c == NULL) || (*c == '\0'))
456 return(ret);
457/*
458 unsigned char b[16];
459 MD5(c,strlen(c),b);
460 return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24));
461*/
462
463 n=0x100;
464 while (*c)
465 {
466 v=n|(*c);
467 n+=0x100;
468 r= (int)((v>>2)^v)&0x0f;
469 ret=(ret<<r)|(ret>>(32-r));
470 ret&=0xFFFFFFFFL;
471 ret^=v*v;
472 c++;
473 }
474 return((ret>>16)^ret);
475 }
476
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h
deleted file mode 100644
index 6e5a1fe708..0000000000
--- a/src/lib/libcrypto/lhash/lhash.h
+++ /dev/null
@@ -1,144 +0,0 @@
1/* crypto/lhash/lhash.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Header for dynamic hash table routines
60 * Author - Eric Young
61 */
62
63#ifndef HEADER_LHASH_H
64#define HEADER_LHASH_H
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70#ifndef NO_FP_API
71#include <stdio.h>
72#endif
73
74typedef struct lhash_node_st
75 {
76 char *data;
77 struct lhash_node_st *next;
78#ifndef NO_HASH_COMP
79 unsigned long hash;
80#endif
81 } LHASH_NODE;
82
83typedef struct lhash_st
84 {
85 LHASH_NODE **b;
86 int (*comp)();
87 unsigned long (*hash)();
88 unsigned int num_nodes;
89 unsigned int num_alloc_nodes;
90 unsigned int p;
91 unsigned int pmax;
92 unsigned long up_load; /* load times 256 */
93 unsigned long down_load; /* load times 256 */
94 unsigned long num_items;
95
96 unsigned long num_expands;
97 unsigned long num_expand_reallocs;
98 unsigned long num_contracts;
99 unsigned long num_contract_reallocs;
100 unsigned long num_hash_calls;
101 unsigned long num_comp_calls;
102 unsigned long num_insert;
103 unsigned long num_replace;
104 unsigned long num_delete;
105 unsigned long num_no_delete;
106 unsigned long num_retrieve;
107 unsigned long num_retrieve_miss;
108 unsigned long num_hash_comps;
109
110 int error;
111 } LHASH;
112
113#define LH_LOAD_MULT 256
114
115/* Indicates a malloc() error in the last call, this is only bad
116 * in lh_insert(). */
117#define lh_error(lh) ((lh)->error)
118
119LHASH *lh_new(unsigned long (*h)(), int (*c)());
120void lh_free(LHASH *lh);
121char *lh_insert(LHASH *lh, char *data);
122char *lh_delete(LHASH *lh, char *data);
123char *lh_retrieve(LHASH *lh, char *data);
124void lh_doall(LHASH *lh, void (*func)(/* char *b */));
125void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg);
126unsigned long lh_strhash(const char *c);
127
128#ifndef NO_FP_API
129void lh_stats(LHASH *lh, FILE *out);
130void lh_node_stats(LHASH *lh, FILE *out);
131void lh_node_usage_stats(LHASH *lh, FILE *out);
132#endif
133
134#ifdef HEADER_BIO_H
135void lh_stats_bio(LHASH *lh, BIO *out);
136void lh_node_stats_bio(LHASH *lh, BIO *out);
137void lh_node_usage_stats_bio(LHASH *lh, BIO *out);
138#endif
139#ifdef __cplusplus
140}
141#endif
142
143#endif
144