diff options
author | jsing <> | 2014-04-20 13:42:57 +0000 |
---|---|---|
committer | jsing <> | 2014-04-20 13:42:57 +0000 |
commit | 12319f218fe1b30a6fd6cbbf44f8e9b094dfb9bf (patch) | |
tree | 235585e66e316e857bbc21359569975913ce61f9 /src/lib/libcrypto/lhash | |
parent | 71d6ded93deb4d1edc464874b5359ece0ef857d2 (diff) | |
download | openbsd-12319f218fe1b30a6fd6cbbf44f8e9b094dfb9bf.tar.gz openbsd-12319f218fe1b30a6fd6cbbf44f8e9b094dfb9bf.tar.bz2 openbsd-12319f218fe1b30a6fd6cbbf44f8e9b094dfb9bf.zip |
KNF.
Diffstat (limited to 'src/lib/libcrypto/lhash')
-rw-r--r-- | src/lib/libcrypto/lhash/lh_stats.c | 263 | ||||
-rw-r--r-- | src/lib/libcrypto/lhash/lh_test.c | 44 | ||||
-rw-r--r-- | src/lib/libcrypto/lhash/lhash.c | 459 | ||||
-rw-r--r-- | src/lib/libcrypto/lhash/lhash.h | 25 |
4 files changed, 393 insertions, 398 deletions
diff --git a/src/lib/libcrypto/lhash/lh_stats.c b/src/lib/libcrypto/lhash/lh_stats.c index 815615e338..34c7d77cb1 100644 --- a/src/lib/libcrypto/lhash/lh_stats.c +++ b/src/lib/libcrypto/lhash/lh_stats.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -70,179 +70,188 @@ | |||
70 | 70 | ||
71 | #ifdef OPENSSL_NO_BIO | 71 | #ifdef OPENSSL_NO_BIO |
72 | 72 | ||
73 | void lh_stats(LHASH *lh, FILE *out) | 73 | void |
74 | { | 74 | lh_stats(LHASH *lh, FILE *out) |
75 | fprintf(out,"num_items = %lu\n",lh->num_items); | 75 | { |
76 | fprintf(out,"num_nodes = %u\n",lh->num_nodes); | 76 | fprintf(out, "num_items = %lu\n", lh->num_items); |
77 | fprintf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes); | 77 | fprintf(out, "num_nodes = %u\n", lh->num_nodes); |
78 | fprintf(out,"num_expands = %lu\n",lh->num_expands); | 78 | fprintf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes); |
79 | fprintf(out,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs); | 79 | fprintf(out, "num_expands = %lu\n", lh->num_expands); |
80 | fprintf(out,"num_contracts = %lu\n",lh->num_contracts); | 80 | fprintf(out, "num_expand_reallocs = %lu\n", lh->num_expand_reallocs); |
81 | fprintf(out,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs); | 81 | fprintf(out, "num_contracts = %lu\n", lh->num_contracts); |
82 | fprintf(out,"num_hash_calls = %lu\n",lh->num_hash_calls); | 82 | fprintf(out, "num_contract_reallocs = %lu\n", |
83 | fprintf(out,"num_comp_calls = %lu\n",lh->num_comp_calls); | 83 | lh->num_contract_reallocs); |
84 | fprintf(out,"num_insert = %lu\n",lh->num_insert); | 84 | fprintf(out, "num_hash_calls = %lu\n", lh->num_hash_calls); |
85 | fprintf(out,"num_replace = %lu\n",lh->num_replace); | 85 | fprintf(out, "num_comp_calls = %lu\n", lh->num_comp_calls); |
86 | fprintf(out,"num_delete = %lu\n",lh->num_delete); | 86 | fprintf(out, "num_insert = %lu\n", lh->num_insert); |
87 | fprintf(out,"num_no_delete = %lu\n",lh->num_no_delete); | 87 | fprintf(out, "num_replace = %lu\n", lh->num_replace); |
88 | fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve); | 88 | fprintf(out, "num_delete = %lu\n", lh->num_delete); |
89 | fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss); | 89 | fprintf(out, "num_no_delete = %lu\n", lh->num_no_delete); |
90 | fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps); | 90 | fprintf(out, "num_retrieve = %lu\n", lh->num_retrieve); |
91 | fprintf(out, "num_retrieve_miss = %lu\n", lh->num_retrieve_miss); | ||
92 | fprintf(out, "num_hash_comps = %lu\n", lh->num_hash_comps); | ||
91 | #if 0 | 93 | #if 0 |
92 | fprintf(out,"p = %u\n",lh->p); | 94 | fprintf(out, "p = %u\n", lh->p); |
93 | fprintf(out,"pmax = %u\n",lh->pmax); | 95 | fprintf(out, "pmax = %u\n", lh->pmax); |
94 | fprintf(out,"up_load = %lu\n",lh->up_load); | 96 | fprintf(out, "up_load = %lu\n", lh->up_load); |
95 | fprintf(out,"down_load = %lu\n",lh->down_load); | 97 | fprintf(out, "down_load = %lu\n", lh->down_load); |
96 | #endif | 98 | #endif |
97 | } | 99 | } |
98 | 100 | ||
99 | void lh_node_stats(LHASH *lh, FILE *out) | 101 | void |
100 | { | 102 | lh_node_stats(LHASH *lh, FILE *out) |
103 | { | ||
101 | LHASH_NODE *n; | 104 | LHASH_NODE *n; |
102 | unsigned int i,num; | 105 | unsigned int i, num; |
103 | 106 | ||
104 | for (i=0; i<lh->num_nodes; i++) | 107 | for (i = 0; i < lh->num_nodes; i++) { |
105 | { | 108 | for (n = lh->b[i], num = 0; n != NULL; n = n->next) |
106 | for (n=lh->b[i],num=0; n != NULL; n=n->next) | ||
107 | num++; | 109 | num++; |
108 | fprintf(out,"node %6u -> %3u\n",i,num); | 110 | fprintf(out, "node %6u -> %3u\n", i, num); |
109 | } | ||
110 | } | 111 | } |
112 | } | ||
111 | 113 | ||
112 | void lh_node_usage_stats(LHASH *lh, FILE *out) | 114 | void |
113 | { | 115 | lh_node_usage_stats(LHASH *lh, FILE *out) |
116 | { | ||
114 | LHASH_NODE *n; | 117 | LHASH_NODE *n; |
115 | unsigned long num; | 118 | unsigned long num; |
116 | unsigned int i; | 119 | unsigned int i; |
117 | unsigned long total=0,n_used=0; | 120 | unsigned long total = 0, n_used = 0; |
118 | 121 | ||
119 | for (i=0; i<lh->num_nodes; i++) | 122 | for (i = 0; i < lh->num_nodes; i++) { |
120 | { | 123 | for (n = lh->b[i], num = 0; n != NULL; n = n->next) |
121 | for (n=lh->b[i],num=0; n != NULL; n=n->next) | ||
122 | num++; | 124 | num++; |
123 | if (num != 0) | 125 | if (num != 0) { |
124 | { | ||
125 | n_used++; | 126 | n_used++; |
126 | total+=num; | 127 | total += num; |
127 | } | ||
128 | } | 128 | } |
129 | fprintf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes); | ||
130 | fprintf(out,"%lu items\n",total); | ||
131 | if (n_used == 0) return; | ||
132 | fprintf(out,"load %d.%02d actual load %d.%02d\n", | ||
133 | (int)(total/lh->num_nodes), | ||
134 | (int)((total%lh->num_nodes)*100/lh->num_nodes), | ||
135 | (int)(total/n_used), | ||
136 | (int)((total%n_used)*100/n_used)); | ||
137 | } | 129 | } |
130 | fprintf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes); | ||
131 | fprintf(out, "%lu items\n", total); | ||
132 | if (n_used == 0) | ||
133 | return; | ||
134 | fprintf(out, "load %d.%02d actual load %d.%02d\n", | ||
135 | (int)(total / lh->num_nodes), | ||
136 | (int)((total % lh->num_nodes) * 100 / lh->num_nodes), | ||
137 | (int)(total / n_used), | ||
138 | (int)((total % n_used) * 100 / n_used)); | ||
139 | } | ||
138 | 140 | ||
139 | #else | 141 | #else |
140 | 142 | ||
141 | #ifndef OPENSSL_NO_FP_API | 143 | #ifndef OPENSSL_NO_FP_API |
142 | void lh_stats(const _LHASH *lh, FILE *fp) | 144 | void |
143 | { | 145 | lh_stats(const _LHASH *lh, FILE *fp) |
146 | { | ||
144 | BIO *bp; | 147 | BIO *bp; |
145 | 148 | ||
146 | bp=BIO_new(BIO_s_file()); | 149 | bp = BIO_new(BIO_s_file()); |
147 | if (bp == NULL) goto end; | 150 | if (bp == NULL) |
148 | BIO_set_fp(bp,fp,BIO_NOCLOSE); | 151 | goto end; |
149 | lh_stats_bio(lh,bp); | 152 | BIO_set_fp(bp, fp, BIO_NOCLOSE); |
153 | lh_stats_bio(lh, bp); | ||
150 | BIO_free(bp); | 154 | BIO_free(bp); |
151 | end:; | 155 | end:; |
152 | } | 156 | } |
153 | 157 | ||
154 | void lh_node_stats(const _LHASH *lh, FILE *fp) | 158 | void |
155 | { | 159 | lh_node_stats(const _LHASH *lh, FILE *fp) |
160 | { | ||
156 | BIO *bp; | 161 | BIO *bp; |
157 | 162 | ||
158 | bp=BIO_new(BIO_s_file()); | 163 | bp = BIO_new(BIO_s_file()); |
159 | if (bp == NULL) goto end; | 164 | if (bp == NULL) |
160 | BIO_set_fp(bp,fp,BIO_NOCLOSE); | 165 | goto end; |
161 | lh_node_stats_bio(lh,bp); | 166 | BIO_set_fp(bp, fp, BIO_NOCLOSE); |
167 | lh_node_stats_bio(lh, bp); | ||
162 | BIO_free(bp); | 168 | BIO_free(bp); |
163 | end:; | 169 | end:; |
164 | } | 170 | } |
165 | 171 | ||
166 | void lh_node_usage_stats(const _LHASH *lh, FILE *fp) | 172 | void |
167 | { | 173 | lh_node_usage_stats(const _LHASH *lh, FILE *fp) |
174 | { | ||
168 | BIO *bp; | 175 | BIO *bp; |
169 | 176 | ||
170 | bp=BIO_new(BIO_s_file()); | 177 | bp = BIO_new(BIO_s_file()); |
171 | if (bp == NULL) goto end; | 178 | if (bp == NULL) |
172 | BIO_set_fp(bp,fp,BIO_NOCLOSE); | 179 | goto end; |
173 | lh_node_usage_stats_bio(lh,bp); | 180 | BIO_set_fp(bp, fp, BIO_NOCLOSE); |
181 | lh_node_usage_stats_bio(lh, bp); | ||
174 | BIO_free(bp); | 182 | BIO_free(bp); |
175 | end:; | 183 | end:; |
176 | } | 184 | } |
177 | 185 | ||
178 | #endif | 186 | #endif |
179 | 187 | ||
180 | void lh_stats_bio(const _LHASH *lh, BIO *out) | 188 | void |
181 | { | 189 | lh_stats_bio(const _LHASH *lh, BIO *out) |
182 | BIO_printf(out,"num_items = %lu\n",lh->num_items); | 190 | { |
183 | BIO_printf(out,"num_nodes = %u\n",lh->num_nodes); | 191 | BIO_printf(out, "num_items = %lu\n", lh->num_items); |
184 | BIO_printf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes); | 192 | BIO_printf(out, "num_nodes = %u\n", lh->num_nodes); |
185 | BIO_printf(out,"num_expands = %lu\n",lh->num_expands); | 193 | BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes); |
186 | BIO_printf(out,"num_expand_reallocs = %lu\n", | 194 | BIO_printf(out, "num_expands = %lu\n", lh->num_expands); |
187 | lh->num_expand_reallocs); | 195 | BIO_printf(out, "num_expand_reallocs = %lu\n", |
188 | BIO_printf(out,"num_contracts = %lu\n",lh->num_contracts); | 196 | lh->num_expand_reallocs); |
189 | BIO_printf(out,"num_contract_reallocs = %lu\n", | 197 | BIO_printf(out, "num_contracts = %lu\n", lh->num_contracts); |
190 | lh->num_contract_reallocs); | 198 | BIO_printf(out, "num_contract_reallocs = %lu\n", |
191 | BIO_printf(out,"num_hash_calls = %lu\n",lh->num_hash_calls); | 199 | lh->num_contract_reallocs); |
192 | BIO_printf(out,"num_comp_calls = %lu\n",lh->num_comp_calls); | 200 | BIO_printf(out, "num_hash_calls = %lu\n", lh->num_hash_calls); |
193 | BIO_printf(out,"num_insert = %lu\n",lh->num_insert); | 201 | BIO_printf(out, "num_comp_calls = %lu\n", lh->num_comp_calls); |
194 | BIO_printf(out,"num_replace = %lu\n",lh->num_replace); | 202 | BIO_printf(out, "num_insert = %lu\n", lh->num_insert); |
195 | BIO_printf(out,"num_delete = %lu\n",lh->num_delete); | 203 | BIO_printf(out, "num_replace = %lu\n", lh->num_replace); |
196 | BIO_printf(out,"num_no_delete = %lu\n",lh->num_no_delete); | 204 | BIO_printf(out, "num_delete = %lu\n", lh->num_delete); |
197 | BIO_printf(out,"num_retrieve = %lu\n",lh->num_retrieve); | 205 | BIO_printf(out, "num_no_delete = %lu\n", lh->num_no_delete); |
198 | BIO_printf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss); | 206 | BIO_printf(out, "num_retrieve = %lu\n", lh->num_retrieve); |
199 | BIO_printf(out,"num_hash_comps = %lu\n",lh->num_hash_comps); | 207 | BIO_printf(out, "num_retrieve_miss = %lu\n", lh->num_retrieve_miss); |
208 | BIO_printf(out, "num_hash_comps = %lu\n", lh->num_hash_comps); | ||
200 | #if 0 | 209 | #if 0 |
201 | BIO_printf(out,"p = %u\n",lh->p); | 210 | BIO_printf(out, "p = %u\n", lh->p); |
202 | BIO_printf(out,"pmax = %u\n",lh->pmax); | 211 | BIO_printf(out, "pmax = %u\n", lh->pmax); |
203 | BIO_printf(out,"up_load = %lu\n",lh->up_load); | 212 | BIO_printf(out, "up_load = %lu\n", lh->up_load); |
204 | BIO_printf(out,"down_load = %lu\n",lh->down_load); | 213 | BIO_printf(out, "down_load = %lu\n", lh->down_load); |
205 | #endif | 214 | #endif |
206 | } | 215 | } |
207 | 216 | ||
208 | void lh_node_stats_bio(const _LHASH *lh, BIO *out) | 217 | void |
209 | { | 218 | lh_node_stats_bio(const _LHASH *lh, BIO *out) |
219 | { | ||
210 | LHASH_NODE *n; | 220 | LHASH_NODE *n; |
211 | unsigned int i,num; | 221 | unsigned int i, num; |
212 | 222 | ||
213 | for (i=0; i<lh->num_nodes; i++) | 223 | for (i = 0; i < lh->num_nodes; i++) { |
214 | { | 224 | for (n = lh->b[i], num = 0; n != NULL; n = n->next) |
215 | for (n=lh->b[i],num=0; n != NULL; n=n->next) | ||
216 | num++; | 225 | num++; |
217 | BIO_printf(out,"node %6u -> %3u\n",i,num); | 226 | BIO_printf(out, "node %6u -> %3u\n", i, num); |
218 | } | ||
219 | } | 227 | } |
228 | } | ||
220 | 229 | ||
221 | void lh_node_usage_stats_bio(const _LHASH *lh, BIO *out) | 230 | void |
222 | { | 231 | lh_node_usage_stats_bio(const _LHASH *lh, BIO *out) |
232 | { | ||
223 | LHASH_NODE *n; | 233 | LHASH_NODE *n; |
224 | unsigned long num; | 234 | unsigned long num; |
225 | unsigned int i; | 235 | unsigned int i; |
226 | unsigned long total=0,n_used=0; | 236 | unsigned long total = 0, n_used = 0; |
227 | 237 | ||
228 | for (i=0; i<lh->num_nodes; i++) | 238 | for (i = 0; i < lh->num_nodes; i++) { |
229 | { | 239 | for (n = lh->b[i], num = 0; n != NULL; n = n->next) |
230 | for (n=lh->b[i],num=0; n != NULL; n=n->next) | ||
231 | num++; | 240 | num++; |
232 | if (num != 0) | 241 | if (num != 0) { |
233 | { | ||
234 | n_used++; | 242 | n_used++; |
235 | total+=num; | 243 | total += num; |
236 | } | ||
237 | } | 244 | } |
238 | BIO_printf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes); | ||
239 | BIO_printf(out,"%lu items\n",total); | ||
240 | if (n_used == 0) return; | ||
241 | BIO_printf(out,"load %d.%02d actual load %d.%02d\n", | ||
242 | (int)(total/lh->num_nodes), | ||
243 | (int)((total%lh->num_nodes)*100/lh->num_nodes), | ||
244 | (int)(total/n_used), | ||
245 | (int)((total%n_used)*100/n_used)); | ||
246 | } | 245 | } |
246 | BIO_printf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes); | ||
247 | BIO_printf(out, "%lu items\n", total); | ||
248 | if (n_used == 0) | ||
249 | return; | ||
250 | BIO_printf(out, "load %d.%02d actual load %d.%02d\n", | ||
251 | (int)(total / lh->num_nodes), | ||
252 | (int)((total % lh->num_nodes) * 100 / lh->num_nodes), | ||
253 | (int)(total / n_used), | ||
254 | (int)((total % n_used) * 100 / n_used)); | ||
255 | } | ||
247 | 256 | ||
248 | #endif | 257 | #endif |
diff --git a/src/lib/libcrypto/lhash/lh_test.c b/src/lib/libcrypto/lhash/lh_test.c index 2224a216ab..6167be383f 100644 --- a/src/lib/libcrypto/lhash/lh_test.c +++ b/src/lib/libcrypto/lhash/lh_test.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -62,27 +62,27 @@ | |||
62 | #include <openssl/lhash.h> | 62 | #include <openssl/lhash.h> |
63 | 63 | ||
64 | main() | 64 | main() |
65 | { | 65 | { |
66 | LHASH *conf; | 66 | LHASH *conf; |
67 | char buf[256]; | 67 | char buf[256]; |
68 | int i; | 68 | int i; |
69 | 69 | ||
70 | conf=lh_new(lh_strhash,strcmp); | 70 | conf = lh_new(lh_strhash, strcmp); |
71 | for (;;) | 71 | for (;;) { |
72 | { | ||
73 | char *p; | 72 | char *p; |
74 | 73 | ||
75 | buf[0]='\0'; | 74 | buf[0] = '\0'; |
76 | fgets(buf,256,stdin); | 75 | fgets(buf, 256, stdin); |
77 | if (buf[0] == '\0') break; | 76 | if (buf[0] == '\0') |
78 | i=strlen(buf); | 77 | break; |
79 | p=malloc(i+1); | 78 | i = strlen(buf); |
80 | memcpy(p,buf,i+1); | 79 | p = malloc(i + 1); |
81 | lh_insert(conf,p); | 80 | memcpy(p, buf, i + 1); |
82 | } | 81 | lh_insert(conf, p); |
82 | } | ||
83 | 83 | ||
84 | lh_node_stats(conf,stdout); | 84 | lh_node_stats(conf, stdout); |
85 | lh_stats(conf,stdout); | 85 | lh_stats(conf, stdout); |
86 | lh_node_usage_stats(conf,stdout); | 86 | lh_node_usage_stats(conf, stdout); |
87 | exit(0); | 87 | exit(0); |
88 | } | 88 | } |
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c index 78ba26db83..ad24a7726b 100644 --- a/src/lib/libcrypto/lhash/lhash.c +++ b/src/lib/libcrypto/lhash/lhash.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -100,9 +100,9 @@ | |||
100 | #include <openssl/crypto.h> | 100 | #include <openssl/crypto.h> |
101 | #include <openssl/lhash.h> | 101 | #include <openssl/lhash.h> |
102 | 102 | ||
103 | const char lh_version[]="lhash" OPENSSL_VERSION_PTEXT; | 103 | const char lh_version[] = "lhash" OPENSSL_VERSION_PTEXT; |
104 | 104 | ||
105 | #undef MIN_NODES | 105 | #undef MIN_NODES |
106 | #define MIN_NODES 16 | 106 | #define MIN_NODES 16 |
107 | #define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */ | 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) */ | 108 | #define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */ |
@@ -111,365 +111,354 @@ static void expand(_LHASH *lh); | |||
111 | static void contract(_LHASH *lh); | 111 | static void contract(_LHASH *lh); |
112 | static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash); | 112 | static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash); |
113 | 113 | ||
114 | _LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c) | 114 | _LHASH * |
115 | { | 115 | lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c) |
116 | { | ||
116 | _LHASH *ret; | 117 | _LHASH *ret; |
117 | int i; | 118 | int i; |
118 | 119 | ||
119 | if ((ret=malloc(sizeof(_LHASH))) == NULL) | 120 | if ((ret = malloc(sizeof(_LHASH))) == NULL) |
120 | goto err0; | 121 | goto err0; |
121 | if ((ret->b=malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL) | 122 | if ((ret->b = malloc(sizeof(LHASH_NODE *) * MIN_NODES)) == NULL) |
122 | goto err1; | 123 | goto err1; |
123 | for (i=0; i<MIN_NODES; i++) | 124 | for (i = 0; i < MIN_NODES; i++) |
124 | ret->b[i]=NULL; | 125 | ret->b[i] = NULL; |
125 | ret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c); | 126 | ret->comp = ((c == NULL) ? (LHASH_COMP_FN_TYPE)strcmp : c); |
126 | ret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h); | 127 | ret->hash = ((h == NULL) ? (LHASH_HASH_FN_TYPE)lh_strhash : h); |
127 | ret->num_nodes=MIN_NODES/2; | 128 | ret->num_nodes = MIN_NODES / 2; |
128 | ret->num_alloc_nodes=MIN_NODES; | 129 | ret->num_alloc_nodes = MIN_NODES; |
129 | ret->p=0; | 130 | ret->p = 0; |
130 | ret->pmax=MIN_NODES/2; | 131 | ret->pmax = MIN_NODES / 2; |
131 | ret->up_load=UP_LOAD; | 132 | ret->up_load = UP_LOAD; |
132 | ret->down_load=DOWN_LOAD; | 133 | ret->down_load = DOWN_LOAD; |
133 | ret->num_items=0; | 134 | ret->num_items = 0; |
134 | 135 | ||
135 | ret->num_expands=0; | 136 | ret->num_expands = 0; |
136 | ret->num_expand_reallocs=0; | 137 | ret->num_expand_reallocs = 0; |
137 | ret->num_contracts=0; | 138 | ret->num_contracts = 0; |
138 | ret->num_contract_reallocs=0; | 139 | ret->num_contract_reallocs = 0; |
139 | ret->num_hash_calls=0; | 140 | ret->num_hash_calls = 0; |
140 | ret->num_comp_calls=0; | 141 | ret->num_comp_calls = 0; |
141 | ret->num_insert=0; | 142 | ret->num_insert = 0; |
142 | ret->num_replace=0; | 143 | ret->num_replace = 0; |
143 | ret->num_delete=0; | 144 | ret->num_delete = 0; |
144 | ret->num_no_delete=0; | 145 | ret->num_no_delete = 0; |
145 | ret->num_retrieve=0; | 146 | ret->num_retrieve = 0; |
146 | ret->num_retrieve_miss=0; | 147 | ret->num_retrieve_miss = 0; |
147 | ret->num_hash_comps=0; | 148 | ret->num_hash_comps = 0; |
148 | 149 | ||
149 | ret->error=0; | 150 | ret->error = 0; |
150 | return(ret); | 151 | return (ret); |
152 | |||
151 | err1: | 153 | err1: |
152 | free(ret); | 154 | free(ret); |
153 | err0: | 155 | err0: |
154 | return(NULL); | 156 | return (NULL); |
155 | } | 157 | } |
156 | 158 | ||
157 | void lh_free(_LHASH *lh) | 159 | void |
158 | { | 160 | lh_free(_LHASH *lh) |
161 | { | ||
159 | unsigned int i; | 162 | unsigned int i; |
160 | LHASH_NODE *n,*nn; | 163 | LHASH_NODE *n, *nn; |
161 | 164 | ||
162 | if (lh == NULL) | 165 | if (lh == NULL) |
163 | return; | 166 | return; |
164 | 167 | ||
165 | for (i=0; i<lh->num_nodes; i++) | 168 | for (i = 0; i < lh->num_nodes; i++) { |
166 | { | 169 | n = lh->b[i]; |
167 | n=lh->b[i]; | 170 | while (n != NULL) { |
168 | while (n != NULL) | 171 | nn = n->next; |
169 | { | ||
170 | nn=n->next; | ||
171 | free(n); | 172 | free(n); |
172 | n=nn; | 173 | n = nn; |
173 | } | ||
174 | } | 174 | } |
175 | } | ||
175 | free(lh->b); | 176 | free(lh->b); |
176 | free(lh); | 177 | free(lh); |
177 | } | 178 | } |
178 | 179 | ||
179 | void *lh_insert(_LHASH *lh, void *data) | 180 | void * |
180 | { | 181 | lh_insert(_LHASH *lh, void *data) |
182 | { | ||
181 | unsigned long hash; | 183 | unsigned long hash; |
182 | LHASH_NODE *nn,**rn; | 184 | LHASH_NODE *nn, **rn; |
183 | void *ret; | 185 | void *ret; |
184 | 186 | ||
185 | lh->error=0; | 187 | lh->error = 0; |
186 | if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) | 188 | if (lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)) |
187 | expand(lh); | 189 | expand(lh); |
188 | 190 | ||
189 | rn=getrn(lh,data,&hash); | 191 | rn = getrn(lh, data, &hash); |
190 | 192 | ||
191 | if (*rn == NULL) | 193 | if (*rn == NULL) { |
192 | { | 194 | if ((nn = (LHASH_NODE *)malloc(sizeof(LHASH_NODE))) == NULL) { |
193 | if ((nn=(LHASH_NODE *)malloc(sizeof(LHASH_NODE))) == NULL) | ||
194 | { | ||
195 | lh->error++; | 195 | lh->error++; |
196 | return(NULL); | 196 | return (NULL); |
197 | } | 197 | } |
198 | nn->data=data; | 198 | nn->data = data; |
199 | nn->next=NULL; | 199 | nn->next = NULL; |
200 | #ifndef OPENSSL_NO_HASH_COMP | 200 | #ifndef OPENSSL_NO_HASH_COMP |
201 | nn->hash=hash; | 201 | nn->hash = hash; |
202 | #endif | 202 | #endif |
203 | *rn=nn; | 203 | *rn = nn; |
204 | ret=NULL; | 204 | ret = NULL; |
205 | lh->num_insert++; | 205 | lh->num_insert++; |
206 | lh->num_items++; | 206 | lh->num_items++; |
207 | } | 207 | } |
208 | else /* replace same key */ | 208 | else /* replace same key */ |
209 | { | 209 | { |
210 | ret= (*rn)->data; | 210 | ret = (*rn)->data; |
211 | (*rn)->data=data; | 211 | (*rn)->data = data; |
212 | lh->num_replace++; | 212 | lh->num_replace++; |
213 | } | ||
214 | return(ret); | ||
215 | } | 213 | } |
214 | return (ret); | ||
215 | } | ||
216 | 216 | ||
217 | void *lh_delete(_LHASH *lh, const void *data) | 217 | void * |
218 | { | 218 | lh_delete(_LHASH *lh, const void *data) |
219 | { | ||
219 | unsigned long hash; | 220 | unsigned long hash; |
220 | LHASH_NODE *nn,**rn; | 221 | LHASH_NODE *nn, **rn; |
221 | void *ret; | 222 | void *ret; |
222 | 223 | ||
223 | lh->error=0; | 224 | lh->error = 0; |
224 | rn=getrn(lh,data,&hash); | 225 | rn = getrn(lh, data, &hash); |
225 | 226 | ||
226 | if (*rn == NULL) | 227 | if (*rn == NULL) { |
227 | { | ||
228 | lh->num_no_delete++; | 228 | lh->num_no_delete++; |
229 | return(NULL); | 229 | return (NULL); |
230 | } | 230 | } else { |
231 | else | ||
232 | { | ||
233 | nn= *rn; | 231 | nn= *rn; |
234 | *rn=nn->next; | 232 | *rn = nn->next; |
235 | ret=nn->data; | 233 | ret = nn->data; |
236 | free(nn); | 234 | free(nn); |
237 | lh->num_delete++; | 235 | lh->num_delete++; |
238 | } | 236 | } |
239 | 237 | ||
240 | lh->num_items--; | 238 | lh->num_items--; |
241 | if ((lh->num_nodes > MIN_NODES) && | 239 | if ((lh->num_nodes > MIN_NODES) && |
242 | (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) | 240 | (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))) |
243 | contract(lh); | 241 | contract(lh); |
244 | 242 | ||
245 | return(ret); | 243 | return (ret); |
246 | } | 244 | } |
247 | 245 | ||
248 | void *lh_retrieve(_LHASH *lh, const void *data) | 246 | void * |
249 | { | 247 | lh_retrieve(_LHASH *lh, const void *data) |
248 | { | ||
250 | unsigned long hash; | 249 | unsigned long hash; |
251 | LHASH_NODE **rn; | 250 | LHASH_NODE **rn; |
252 | void *ret; | 251 | void *ret; |
253 | 252 | ||
254 | lh->error=0; | 253 | lh->error = 0; |
255 | rn=getrn(lh,data,&hash); | 254 | rn = getrn(lh, data, &hash); |
256 | 255 | ||
257 | if (*rn == NULL) | 256 | if (*rn == NULL) { |
258 | { | ||
259 | lh->num_retrieve_miss++; | 257 | lh->num_retrieve_miss++; |
260 | return(NULL); | 258 | return (NULL); |
261 | } | 259 | } else { |
262 | else | 260 | ret = (*rn)->data; |
263 | { | ||
264 | ret= (*rn)->data; | ||
265 | lh->num_retrieve++; | 261 | lh->num_retrieve++; |
266 | } | ||
267 | return(ret); | ||
268 | } | 262 | } |
263 | return (ret); | ||
264 | } | ||
269 | 265 | ||
270 | static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, | 266 | static void |
271 | LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) | 267 | doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, |
272 | { | 268 | LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) |
269 | { | ||
273 | int i; | 270 | int i; |
274 | LHASH_NODE *a,*n; | 271 | LHASH_NODE *a, *n; |
275 | 272 | ||
276 | if (lh == NULL) | 273 | if (lh == NULL) |
277 | return; | 274 | return; |
278 | 275 | ||
279 | /* reverse the order so we search from 'top to bottom' | 276 | /* reverse the order so we search from 'top to bottom' |
280 | * We were having memory leaks otherwise */ | 277 | * We were having memory leaks otherwise */ |
281 | for (i=lh->num_nodes-1; i>=0; i--) | 278 | for (i = lh->num_nodes - 1; i >= 0; i--) { |
282 | { | 279 | a = lh->b[i]; |
283 | a=lh->b[i]; | 280 | while (a != NULL) { |
284 | while (a != NULL) | ||
285 | { | ||
286 | /* 28/05/91 - eay - n added so items can be deleted | 281 | /* 28/05/91 - eay - n added so items can be deleted |
287 | * via lh_doall */ | 282 | * via lh_doall */ |
288 | /* 22/05/08 - ben - eh? since a is not passed, | 283 | /* 22/05/08 - ben - eh? since a is not passed, |
289 | * this should not be needed */ | 284 | * this should not be needed */ |
290 | n=a->next; | 285 | n = a->next; |
291 | if(use_arg) | 286 | if (use_arg) |
292 | func_arg(a->data,arg); | 287 | func_arg(a->data, arg); |
293 | else | 288 | else |
294 | func(a->data); | 289 | func(a->data); |
295 | a=n; | 290 | a = n; |
296 | } | ||
297 | } | 291 | } |
298 | } | 292 | } |
293 | } | ||
299 | 294 | ||
300 | void lh_doall(_LHASH *lh, LHASH_DOALL_FN_TYPE func) | 295 | void |
301 | { | 296 | lh_doall(_LHASH *lh, LHASH_DOALL_FN_TYPE func) |
297 | { | ||
302 | doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL); | 298 | doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL); |
303 | } | 299 | } |
304 | 300 | ||
305 | void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg) | 301 | void |
306 | { | 302 | lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg) |
303 | { | ||
307 | doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg); | 304 | doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg); |
308 | } | 305 | } |
309 | 306 | ||
310 | static void expand(_LHASH *lh) | 307 | static void |
311 | { | 308 | expand(_LHASH *lh) |
312 | LHASH_NODE **n,**n1,**n2,*np; | 309 | { |
313 | unsigned int p,i,j; | 310 | LHASH_NODE **n, **n1, **n2, *np; |
314 | unsigned long hash,nni; | 311 | unsigned int p, i, j; |
312 | unsigned long hash, nni; | ||
315 | 313 | ||
316 | lh->num_nodes++; | 314 | lh->num_nodes++; |
317 | lh->num_expands++; | 315 | lh->num_expands++; |
318 | p=(int)lh->p++; | 316 | p = (int)lh->p++; |
319 | n1= &(lh->b[p]); | 317 | n1 = &(lh->b[p]); |
320 | n2= &(lh->b[p+(int)lh->pmax]); | 318 | n2 = &(lh->b[p + (int)lh->pmax]); |
321 | *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */ | 319 | *n2 = NULL; /* 27/07/92 - eay - undefined pointer bug */ |
322 | nni=lh->num_alloc_nodes; | 320 | nni = lh->num_alloc_nodes; |
323 | 321 | ||
324 | for (np= *n1; np != NULL; ) | 322 | for (np = *n1; np != NULL; ) { |
325 | { | ||
326 | #ifndef OPENSSL_NO_HASH_COMP | 323 | #ifndef OPENSSL_NO_HASH_COMP |
327 | hash=np->hash; | 324 | hash = np->hash; |
328 | #else | 325 | #else |
329 | hash=lh->hash(np->data); | 326 | hash = lh->hash(np->data); |
330 | lh->num_hash_calls++; | 327 | lh->num_hash_calls++; |
331 | #endif | 328 | #endif |
332 | if ((hash%nni) != p) | 329 | if ((hash % nni) != p) { /* move it */ |
333 | { /* move it */ | 330 | *n1 = (*n1)->next; |
334 | *n1= (*n1)->next; | ||
335 | np->next= *n2; | 331 | np->next= *n2; |
336 | *n2=np; | 332 | *n2 = np; |
337 | } | 333 | } else |
338 | else | 334 | n1 = &((*n1)->next); |
339 | n1= &((*n1)->next); | ||
340 | np= *n1; | 335 | np= *n1; |
341 | } | 336 | } |
342 | 337 | ||
343 | if ((lh->p) >= lh->pmax) | 338 | if ((lh->p) >= lh->pmax) { |
344 | { | 339 | j = (int)lh->num_alloc_nodes * 2; |
345 | j=(int)lh->num_alloc_nodes*2; | 340 | n = (LHASH_NODE **)realloc(lh->b, |
346 | n=(LHASH_NODE **)realloc(lh->b, | 341 | (int)(sizeof(LHASH_NODE *) * j)); |
347 | (int)(sizeof(LHASH_NODE *)*j)); | 342 | if (n == NULL) { |
348 | if (n == NULL) | 343 | /* fputs("realloc error in lhash", stderr); */ |
349 | { | ||
350 | /* fputs("realloc error in lhash",stderr); */ | ||
351 | lh->error++; | 344 | lh->error++; |
352 | lh->p=0; | 345 | lh->p = 0; |
353 | return; | 346 | return; |
354 | } | 347 | } |
355 | /* else */ | 348 | /* else */ |
356 | for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */ | 349 | for (i = (int)lh->num_alloc_nodes; i < j; i++)/* 26/02/92 eay */ |
357 | n[i]=NULL; /* 02/03/92 eay */ | 350 | n[i] = NULL; /* 02/03/92 eay */ |
358 | lh->pmax=lh->num_alloc_nodes; | 351 | lh->pmax = lh->num_alloc_nodes; |
359 | lh->num_alloc_nodes=j; | 352 | lh->num_alloc_nodes = j; |
360 | lh->num_expand_reallocs++; | 353 | lh->num_expand_reallocs++; |
361 | lh->p=0; | 354 | lh->p = 0; |
362 | lh->b=n; | 355 | lh->b = n; |
363 | } | ||
364 | } | 356 | } |
365 | 357 | } | |
366 | static void contract(_LHASH *lh) | 358 | |
367 | { | 359 | static void |
368 | LHASH_NODE **n,*n1,*np; | 360 | contract(_LHASH *lh) |
369 | 361 | { | |
370 | np=lh->b[lh->p+lh->pmax-1]; | 362 | LHASH_NODE **n, *n1, *np; |
371 | lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */ | 363 | |
372 | if (lh->p == 0) | 364 | np = lh->b[lh->p + lh->pmax - 1]; |
373 | { | 365 | lh->b[lh->p+lh->pmax - 1] = NULL; /* 24/07-92 - eay - weird but :-( */ |
374 | n=(LHASH_NODE **)realloc(lh->b, | 366 | if (lh->p == 0) { |
375 | (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); | 367 | n = (LHASH_NODE **)realloc(lh->b, |
376 | if (n == NULL) | 368 | (unsigned int)(sizeof(LHASH_NODE *) * lh->pmax)); |
377 | { | 369 | if (n == NULL) { |
378 | /* fputs("realloc error in lhash",stderr); */ | 370 | /* fputs("realloc error in lhash", stderr); */ |
379 | lh->error++; | 371 | lh->error++; |
380 | return; | 372 | return; |
381 | } | ||
382 | lh->num_contract_reallocs++; | ||
383 | lh->num_alloc_nodes/=2; | ||
384 | lh->pmax/=2; | ||
385 | lh->p=lh->pmax-1; | ||
386 | lh->b=n; | ||
387 | } | 373 | } |
388 | else | 374 | lh->num_contract_reallocs++; |
375 | lh->num_alloc_nodes /= 2; | ||
376 | lh->pmax /= 2; | ||
377 | lh->p = lh->pmax - 1; | ||
378 | lh->b = n; | ||
379 | } else | ||
389 | lh->p--; | 380 | lh->p--; |
390 | 381 | ||
391 | lh->num_nodes--; | 382 | lh->num_nodes--; |
392 | lh->num_contracts++; | 383 | lh->num_contracts++; |
393 | 384 | ||
394 | n1=lh->b[(int)lh->p]; | 385 | n1 = lh->b[(int)lh->p]; |
395 | if (n1 == NULL) | 386 | if (n1 == NULL) |
396 | lh->b[(int)lh->p]=np; | 387 | lh->b[(int)lh->p] = np; |
397 | else | 388 | else { |
398 | { | ||
399 | while (n1->next != NULL) | 389 | while (n1->next != NULL) |
400 | n1=n1->next; | 390 | n1 = n1->next; |
401 | n1->next=np; | 391 | n1->next = np; |
402 | } | ||
403 | } | 392 | } |
393 | } | ||
404 | 394 | ||
405 | static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash) | 395 | static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash) |
406 | { | 396 | { |
407 | LHASH_NODE **ret,*n1; | 397 | LHASH_NODE **ret, *n1; |
408 | unsigned long hash,nn; | 398 | unsigned long hash, nn; |
409 | LHASH_COMP_FN_TYPE cf; | 399 | LHASH_COMP_FN_TYPE cf; |
410 | 400 | ||
411 | hash=(*(lh->hash))(data); | 401 | hash = (*(lh->hash))(data); |
412 | lh->num_hash_calls++; | 402 | lh->num_hash_calls++; |
413 | *rhash=hash; | 403 | *rhash = hash; |
414 | 404 | ||
415 | nn=hash%lh->pmax; | 405 | nn = hash % lh->pmax; |
416 | if (nn < lh->p) | 406 | if (nn < lh->p) |
417 | nn=hash%lh->num_alloc_nodes; | 407 | nn = hash % lh->num_alloc_nodes; |
418 | 408 | ||
419 | cf=lh->comp; | 409 | cf = lh->comp; |
420 | ret= &(lh->b[(int)nn]); | 410 | ret = &(lh->b[(int)nn]); |
421 | for (n1= *ret; n1 != NULL; n1=n1->next) | 411 | for (n1 = *ret; n1 != NULL; n1 = n1->next) { |
422 | { | ||
423 | #ifndef OPENSSL_NO_HASH_COMP | 412 | #ifndef OPENSSL_NO_HASH_COMP |
424 | lh->num_hash_comps++; | 413 | lh->num_hash_comps++; |
425 | if (n1->hash != hash) | 414 | if (n1->hash != hash) { |
426 | { | 415 | ret = &(n1->next); |
427 | ret= &(n1->next); | ||
428 | continue; | 416 | continue; |
429 | } | 417 | } |
430 | #endif | 418 | #endif |
431 | lh->num_comp_calls++; | 419 | lh->num_comp_calls++; |
432 | if(cf(n1->data,data) == 0) | 420 | if (cf(n1->data, data) == 0) |
433 | break; | 421 | break; |
434 | ret= &(n1->next); | 422 | ret = &(n1->next); |
435 | } | ||
436 | return(ret); | ||
437 | } | 423 | } |
424 | return (ret); | ||
425 | } | ||
438 | 426 | ||
439 | /* The following hash seems to work very well on normal text strings | 427 | /* The following hash seems to work very well on normal text strings |
440 | * no collisions on /usr/dict/words and it distributes on %2^n quite | 428 | * no collisions on /usr/dict/words and it distributes on %2^n quite |
441 | * well, not as good as MD5, but still good. | 429 | * well, not as good as MD5, but still good. |
442 | */ | 430 | */ |
443 | unsigned long lh_strhash(const char *c) | 431 | unsigned long |
444 | { | 432 | lh_strhash(const char *c) |
445 | unsigned long ret=0; | 433 | { |
434 | unsigned long ret = 0; | ||
446 | long n; | 435 | long n; |
447 | unsigned long v; | 436 | unsigned long v; |
448 | int r; | 437 | int r; |
449 | 438 | ||
450 | if ((c == NULL) || (*c == '\0')) | 439 | if ((c == NULL) || (*c == '\0')) |
451 | return(ret); | 440 | return (ret); |
452 | /* | 441 | /* |
453 | unsigned char b[16]; | 442 | unsigned char b[16]; |
454 | MD5(c,strlen(c),b); | 443 | MD5(c,strlen(c),b); |
455 | return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24)); | 444 | return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24)); |
456 | */ | 445 | */ |
457 | 446 | ||
458 | n=0x100; | 447 | n = 0x100; |
459 | while (*c) | 448 | while (*c) { |
460 | { | 449 | v = n | (*c); |
461 | v=n|(*c); | 450 | n += 0x100; |
462 | n+=0x100; | 451 | r = (int)((v >> 2) ^ v) & 0x0f; |
463 | r= (int)((v>>2)^v)&0x0f; | 452 | ret = (ret << r)|(ret >> (32 - r)); |
464 | ret=(ret<<r)|(ret>>(32-r)); | 453 | ret &= 0xFFFFFFFFL; |
465 | ret&=0xFFFFFFFFL; | 454 | ret ^= v * v; |
466 | ret^=v*v; | ||
467 | c++; | 455 | c++; |
468 | } | ||
469 | return((ret>>16)^ret); | ||
470 | } | 456 | } |
457 | return ((ret >> 16) ^ ret); | ||
458 | } | ||
471 | 459 | ||
472 | unsigned long lh_num_items(const _LHASH *lh) | 460 | unsigned long |
473 | { | 461 | lh_num_items(const _LHASH *lh) |
462 | { | ||
474 | return lh ? lh->num_items : 0; | 463 | return lh ? lh->num_items : 0; |
475 | } | 464 | } |
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h index e7d8763591..ea40ef184e 100644 --- a/src/lib/libcrypto/lhash/lhash.h +++ b/src/lib/libcrypto/lhash/lhash.h | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -76,14 +76,13 @@ | |||
76 | extern "C" { | 76 | extern "C" { |
77 | #endif | 77 | #endif |
78 | 78 | ||
79 | typedef struct lhash_node_st | 79 | typedef struct lhash_node_st { |
80 | { | ||
81 | void *data; | 80 | void *data; |
82 | struct lhash_node_st *next; | 81 | struct lhash_node_st *next; |
83 | #ifndef OPENSSL_NO_HASH_COMP | 82 | #ifndef OPENSSL_NO_HASH_COMP |
84 | unsigned long hash; | 83 | unsigned long hash; |
85 | #endif | 84 | #endif |
86 | } LHASH_NODE; | 85 | } LHASH_NODE; |
87 | 86 | ||
88 | typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *); | 87 | typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *); |
89 | typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *); | 88 | typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *); |
@@ -135,8 +134,7 @@ typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *); | |||
135 | name##_doall_arg(a, b); } | 134 | name##_doall_arg(a, b); } |
136 | #define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG | 135 | #define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG |
137 | 136 | ||
138 | typedef struct lhash_st | 137 | typedef struct lhash_st { |
139 | { | ||
140 | LHASH_NODE **b; | 138 | LHASH_NODE **b; |
141 | LHASH_COMP_FN_TYPE comp; | 139 | LHASH_COMP_FN_TYPE comp; |
142 | LHASH_HASH_FN_TYPE hash; | 140 | LHASH_HASH_FN_TYPE hash; |
@@ -163,8 +161,8 @@ typedef struct lhash_st | |||
163 | unsigned long num_hash_comps; | 161 | unsigned long num_hash_comps; |
164 | 162 | ||
165 | int error; | 163 | int error; |
166 | } _LHASH; /* Do not use _LHASH directly, use LHASH_OF | 164 | } _LHASH; /* Do not use _LHASH directly, use LHASH_OF |
167 | * and friends */ | 165 | * and friends */ |
168 | 166 | ||
169 | #define LH_LOAD_MULT 256 | 167 | #define LH_LOAD_MULT 256 |
170 | 168 | ||
@@ -238,4 +236,3 @@ DECLARE_LHASH_OF(OPENSSL_CSTRING); | |||
238 | #endif | 236 | #endif |
239 | 237 | ||
240 | #endif | 238 | #endif |
241 | |||