summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/lhash
diff options
context:
space:
mode:
authortb <>2024-03-02 11:11:11 +0000
committertb <>2024-03-02 11:11:11 +0000
commit3228d4664f5cbc8a4b11e8d1cf7aa6636946f529 (patch)
tree865633fee7fa46f45fa7bee8495692a2bf76544f /src/lib/libcrypto/lhash
parent2e45bf0bb5ba5d679b984ec185fbc3d2a6270f6f (diff)
downloadopenbsd-3228d4664f5cbc8a4b11e8d1cf7aa6636946f529.tar.gz
openbsd-3228d4664f5cbc8a4b11e8d1cf7aa6636946f529.tar.bz2
openbsd-3228d4664f5cbc8a4b11e8d1cf7aa6636946f529.zip
Make LHASH_OF() and STACK_OF() use opaque structs
This removes internals of these two special snowflakes and will allow further simplifications. Unfortunately, there are some pieces of software that actually use LHASH_OF() (looking at you, pound, Ruby, and openssl(1)), so we get to keep exposing this garbage, at least for now. Expose lh_error() as a symbol to replace a macro reaching into _LHASH. lh_down_load() is no longer available. _LHASH and _STACK are now opaque, LHASH_NODE becomes internal-only. from jsing
Diffstat (limited to 'src/lib/libcrypto/lhash')
-rw-r--r--src/lib/libcrypto/lhash/lhash.c11
-rw-r--r--src/lib/libcrypto/lhash/lhash.h48
-rw-r--r--src/lib/libcrypto/lhash/lhash_local.h105
3 files changed, 119 insertions, 45 deletions
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c
index 81660419c7..cd69f6fec1 100644
--- a/src/lib/libcrypto/lhash/lhash.c
+++ b/src/lib/libcrypto/lhash/lhash.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: lhash.c,v 1.21 2024/01/24 14:02:52 jsing Exp $ */ 1/* $OpenBSD: lhash.c,v 1.22 2024/03/02 11:11:11 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -103,6 +103,8 @@
103#include <openssl/crypto.h> 103#include <openssl/crypto.h>
104#include <openssl/lhash.h> 104#include <openssl/lhash.h>
105 105
106#include "lhash_local.h"
107
106#undef MIN_NODES 108#undef MIN_NODES
107#define MIN_NODES 16 109#define MIN_NODES 16
108#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */ 110#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */
@@ -157,6 +159,13 @@ lh_free(_LHASH *lh)
157} 159}
158LCRYPTO_ALIAS(lh_free); 160LCRYPTO_ALIAS(lh_free);
159 161
162int
163lh_error(_LHASH *lh)
164{
165 return lh->error;
166}
167LCRYPTO_ALIAS(lh_error);
168
160void * 169void *
161lh_insert(_LHASH *lh, void *data) 170lh_insert(_LHASH *lh, void *data)
162{ 171{
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h
index 8db0174a61..86d05544a0 100644
--- a/src/lib/libcrypto/lhash/lhash.h
+++ b/src/lib/libcrypto/lhash/lhash.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: lhash.h,v 1.13 2024/03/02 11:04:51 tb Exp $ */ 1/* $OpenBSD: lhash.h,v 1.14 2024/03/02 11:11:11 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -75,14 +75,6 @@
75extern "C" { 75extern "C" {
76#endif 76#endif
77 77
78typedef struct lhash_node_st {
79 void *data;
80 struct lhash_node_st *next;
81#ifndef OPENSSL_NO_HASH_COMP
82 unsigned long hash;
83#endif
84} LHASH_NODE;
85
86typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *); 78typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
87typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *); 79typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
88typedef void (*LHASH_DOALL_FN_TYPE)(void *); 80typedef void (*LHASH_DOALL_FN_TYPE)(void *);
@@ -133,44 +125,13 @@ typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *);
133 name##_doall_arg(a, b); } 125 name##_doall_arg(a, b); }
134#define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG 126#define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG
135 127
136typedef struct lhash_st { 128typedef struct lhash_st _LHASH;
137 LHASH_NODE **b;
138 LHASH_COMP_FN_TYPE comp;
139 LHASH_HASH_FN_TYPE hash;
140 unsigned int num_nodes;
141 unsigned int num_alloc_nodes;
142 unsigned int p;
143 unsigned int pmax;
144 unsigned long up_load; /* load times 256 */
145 unsigned long down_load; /* load times 256 */
146 unsigned long num_items;
147
148 unsigned long num_expands;
149 unsigned long num_expand_reallocs;
150 unsigned long num_contracts;
151 unsigned long num_contract_reallocs;
152 unsigned long num_hash_calls;
153 unsigned long num_comp_calls;
154 unsigned long num_insert;
155 unsigned long num_replace;
156 unsigned long num_delete;
157 unsigned long num_no_delete;
158 unsigned long num_retrieve;
159 unsigned long num_retrieve_miss;
160 unsigned long num_hash_comps;
161
162 int error;
163} _LHASH; /* Do not use _LHASH directly, use LHASH_OF
164 * and friends */
165 129
166#define LH_LOAD_MULT 256 130#define LH_LOAD_MULT 256
167 131
168/* Indicates a malloc() error in the last call, this is only bad
169 * in lh_insert(). */
170#define lh_error(lh) ((lh)->error)
171
172_LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c); 132_LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
173void lh_free(_LHASH *lh); 133void lh_free(_LHASH *lh);
134int lh_error(_LHASH *lh);
174void *lh_insert(_LHASH *lh, void *data); 135void *lh_insert(_LHASH *lh, void *data);
175void *lh_delete(_LHASH *lh, const void *data); 136void *lh_delete(_LHASH *lh, const void *data);
176void *lh_retrieve(_LHASH *lh, const void *data); 137void *lh_retrieve(_LHASH *lh, const void *data);
@@ -183,7 +144,7 @@ unsigned long lh_num_items(const _LHASH *lh);
183 144
184#define LHASH_OF(type) struct lhash_st_##type 145#define LHASH_OF(type) struct lhash_st_##type
185 146
186#define DECLARE_LHASH_OF(type) LHASH_OF(type) { int dummy; } 147#define DECLARE_LHASH_OF(type) LHASH_OF(type)
187 148
188#define CHECKED_LHASH_OF(type,lh) \ 149#define CHECKED_LHASH_OF(type,lh) \
189 ((_LHASH *)CHECKED_PTR_OF(LHASH_OF(type),lh)) 150 ((_LHASH *)CHECKED_PTR_OF(LHASH_OF(type),lh))
@@ -206,7 +167,6 @@ unsigned long lh_num_items(const _LHASH *lh);
206#define LHM_lh_doall_arg(type, lh, fn, arg_type, arg) \ 167#define LHM_lh_doall_arg(type, lh, fn, arg_type, arg) \
207 lh_doall_arg(CHECKED_LHASH_OF(type, lh), fn, CHECKED_PTR_OF(arg_type, arg)) 168 lh_doall_arg(CHECKED_LHASH_OF(type, lh), fn, CHECKED_PTR_OF(arg_type, arg))
208#define LHM_lh_num_items(type, lh) lh_num_items(CHECKED_LHASH_OF(type, lh)) 169#define LHM_lh_num_items(type, lh) lh_num_items(CHECKED_LHASH_OF(type, lh))
209#define LHM_lh_down_load(type, lh) (CHECKED_LHASH_OF(type, lh)->down_load)
210#define LHM_lh_free(type, lh) lh_free(CHECKED_LHASH_OF(type, lh)) 170#define LHM_lh_free(type, lh) lh_free(CHECKED_LHASH_OF(type, lh))
211 171
212DECLARE_LHASH_OF(OPENSSL_STRING); 172DECLARE_LHASH_OF(OPENSSL_STRING);
diff --git a/src/lib/libcrypto/lhash/lhash_local.h b/src/lib/libcrypto/lhash/lhash_local.h
new file mode 100644
index 0000000000..5466e554e7
--- /dev/null
+++ b/src/lib/libcrypto/lhash/lhash_local.h
@@ -0,0 +1,105 @@
1/* $OpenBSD: lhash_local.h,v 1.1 2024/03/02 11:11:11 tb Exp $ */
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#include <openssl/opensslconf.h>
64
65#ifndef HEADER_LHASH_LOCAL_H
66#define HEADER_LHASH_LOCAL_H
67
68typedef struct lhash_node_st {
69 void *data;
70 struct lhash_node_st *next;
71#ifndef OPENSSL_NO_HASH_COMP
72 unsigned long hash;
73#endif
74} LHASH_NODE;
75
76struct lhash_st {
77 LHASH_NODE **b;
78 LHASH_COMP_FN_TYPE comp;
79 LHASH_HASH_FN_TYPE hash;
80 unsigned int num_nodes;
81 unsigned int num_alloc_nodes;
82 unsigned int p;
83 unsigned int pmax;
84 unsigned long up_load; /* load times 256 */
85 unsigned long down_load; /* load times 256 */
86 unsigned long num_items;
87
88 unsigned long num_expands;
89 unsigned long num_expand_reallocs;
90 unsigned long num_contracts;
91 unsigned long num_contract_reallocs;
92 unsigned long num_hash_calls;
93 unsigned long num_comp_calls;
94 unsigned long num_insert;
95 unsigned long num_replace;
96 unsigned long num_delete;
97 unsigned long num_no_delete;
98 unsigned long num_retrieve;
99 unsigned long num_retrieve_miss;
100 unsigned long num_hash_comps;
101
102 int error;
103} /* _LHASH */;
104
105#endif