xref: /aosp_15_r20/external/boringssl/src/crypto/lhash/internal.h (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1*8fb009dcSAndroid Build Coastguard Worker /* Copyright (C) 1995-1998 Eric Young ([email protected])
2*8fb009dcSAndroid Build Coastguard Worker  * All rights reserved.
3*8fb009dcSAndroid Build Coastguard Worker  *
4*8fb009dcSAndroid Build Coastguard Worker  * This package is an SSL implementation written
5*8fb009dcSAndroid Build Coastguard Worker  * by Eric Young ([email protected]).
6*8fb009dcSAndroid Build Coastguard Worker  * The implementation was written so as to conform with Netscapes SSL.
7*8fb009dcSAndroid Build Coastguard Worker  *
8*8fb009dcSAndroid Build Coastguard Worker  * This library is free for commercial and non-commercial use as long as
9*8fb009dcSAndroid Build Coastguard Worker  * the following conditions are aheared to.  The following conditions
10*8fb009dcSAndroid Build Coastguard Worker  * apply to all code found in this distribution, be it the RC4, RSA,
11*8fb009dcSAndroid Build Coastguard Worker  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
12*8fb009dcSAndroid Build Coastguard Worker  * included with this distribution is covered by the same copyright terms
13*8fb009dcSAndroid Build Coastguard Worker  * except that the holder is Tim Hudson ([email protected]).
14*8fb009dcSAndroid Build Coastguard Worker  *
15*8fb009dcSAndroid Build Coastguard Worker  * Copyright remains Eric Young's, and as such any Copyright notices in
16*8fb009dcSAndroid Build Coastguard Worker  * the code are not to be removed.
17*8fb009dcSAndroid Build Coastguard Worker  * If this package is used in a product, Eric Young should be given attribution
18*8fb009dcSAndroid Build Coastguard Worker  * as the author of the parts of the library used.
19*8fb009dcSAndroid Build Coastguard Worker  * This can be in the form of a textual message at program startup or
20*8fb009dcSAndroid Build Coastguard Worker  * in documentation (online or textual) provided with the package.
21*8fb009dcSAndroid Build Coastguard Worker  *
22*8fb009dcSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
23*8fb009dcSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
24*8fb009dcSAndroid Build Coastguard Worker  * are met:
25*8fb009dcSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the copyright
26*8fb009dcSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
27*8fb009dcSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
28*8fb009dcSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
29*8fb009dcSAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
30*8fb009dcSAndroid Build Coastguard Worker  * 3. All advertising materials mentioning features or use of this software
31*8fb009dcSAndroid Build Coastguard Worker  *    must display the following acknowledgement:
32*8fb009dcSAndroid Build Coastguard Worker  *    "This product includes cryptographic software written by
33*8fb009dcSAndroid Build Coastguard Worker  *     Eric Young ([email protected])"
34*8fb009dcSAndroid Build Coastguard Worker  *    The word 'cryptographic' can be left out if the rouines from the library
35*8fb009dcSAndroid Build Coastguard Worker  *    being used are not cryptographic related :-).
36*8fb009dcSAndroid Build Coastguard Worker  * 4. If you include any Windows specific code (or a derivative thereof) from
37*8fb009dcSAndroid Build Coastguard Worker  *    the apps directory (application code) you must include an acknowledgement:
38*8fb009dcSAndroid Build Coastguard Worker  *    "This product includes software written by Tim Hudson ([email protected])"
39*8fb009dcSAndroid Build Coastguard Worker  *
40*8fb009dcSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41*8fb009dcSAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42*8fb009dcSAndroid Build Coastguard Worker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43*8fb009dcSAndroid Build Coastguard Worker  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44*8fb009dcSAndroid Build Coastguard Worker  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45*8fb009dcSAndroid Build Coastguard Worker  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46*8fb009dcSAndroid Build Coastguard Worker  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47*8fb009dcSAndroid Build Coastguard Worker  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48*8fb009dcSAndroid Build Coastguard Worker  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49*8fb009dcSAndroid Build Coastguard Worker  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50*8fb009dcSAndroid Build Coastguard Worker  * SUCH DAMAGE.
51*8fb009dcSAndroid Build Coastguard Worker  *
52*8fb009dcSAndroid Build Coastguard Worker  * The licence and distribution terms for any publically available version or
53*8fb009dcSAndroid Build Coastguard Worker  * derivative of this code cannot be changed.  i.e. this code cannot simply be
54*8fb009dcSAndroid Build Coastguard Worker  * copied and put under another distribution licence
55*8fb009dcSAndroid Build Coastguard Worker  * [including the GNU Public Licence.] */
56*8fb009dcSAndroid Build Coastguard Worker 
57*8fb009dcSAndroid Build Coastguard Worker #ifndef OPENSSL_HEADER_LHASH_INTERNAL_H
58*8fb009dcSAndroid Build Coastguard Worker #define OPENSSL_HEADER_LHASH_INTERNAL_H
59*8fb009dcSAndroid Build Coastguard Worker 
60*8fb009dcSAndroid Build Coastguard Worker #include <openssl/lhash.h>
61*8fb009dcSAndroid Build Coastguard Worker 
62*8fb009dcSAndroid Build Coastguard Worker #if defined(__cplusplus)
63*8fb009dcSAndroid Build Coastguard Worker extern "C" {
64*8fb009dcSAndroid Build Coastguard Worker #endif
65*8fb009dcSAndroid Build Coastguard Worker 
66*8fb009dcSAndroid Build Coastguard Worker 
67*8fb009dcSAndroid Build Coastguard Worker // lhash is a traditional, chaining hash table that automatically expands and
68*8fb009dcSAndroid Build Coastguard Worker // contracts as needed. One should not use the lh_* functions directly, rather
69*8fb009dcSAndroid Build Coastguard Worker // use the type-safe macro wrappers:
70*8fb009dcSAndroid Build Coastguard Worker //
71*8fb009dcSAndroid Build Coastguard Worker // A hash table of a specific type of object has type |LHASH_OF(type)|. This
72*8fb009dcSAndroid Build Coastguard Worker // can be defined (once) with |DEFINE_LHASH_OF(type)| and declared where needed
73*8fb009dcSAndroid Build Coastguard Worker // with |DECLARE_LHASH_OF(type)|. For example:
74*8fb009dcSAndroid Build Coastguard Worker //
75*8fb009dcSAndroid Build Coastguard Worker //   struct foo {
76*8fb009dcSAndroid Build Coastguard Worker //     int bar;
77*8fb009dcSAndroid Build Coastguard Worker //   };
78*8fb009dcSAndroid Build Coastguard Worker //
79*8fb009dcSAndroid Build Coastguard Worker //   DEFINE_LHASH_OF(struct foo)
80*8fb009dcSAndroid Build Coastguard Worker //
81*8fb009dcSAndroid Build Coastguard Worker // Although note that the hash table will contain /pointers/ to |foo|.
82*8fb009dcSAndroid Build Coastguard Worker //
83*8fb009dcSAndroid Build Coastguard Worker // A macro will be defined for each of the |OPENSSL_lh_*| functions below. For
84*8fb009dcSAndroid Build Coastguard Worker // |LHASH_OF(foo)|, the macros would be |lh_foo_new|, |lh_foo_num_items| etc.
85*8fb009dcSAndroid Build Coastguard Worker 
86*8fb009dcSAndroid Build Coastguard Worker 
87*8fb009dcSAndroid Build Coastguard Worker // lhash_cmp_func is a comparison function that returns a value equal, or not
88*8fb009dcSAndroid Build Coastguard Worker // equal, to zero depending on whether |*a| is equal, or not equal to |*b|,
89*8fb009dcSAndroid Build Coastguard Worker // respectively. Note the difference between this and |stack_cmp_func| in that
90*8fb009dcSAndroid Build Coastguard Worker // this takes pointers to the objects directly.
91*8fb009dcSAndroid Build Coastguard Worker //
92*8fb009dcSAndroid Build Coastguard Worker // This function's actual type signature is int (*)(const T*, const T*). The
93*8fb009dcSAndroid Build Coastguard Worker // low-level |lh_*| functions will be passed a type-specific wrapper to call it
94*8fb009dcSAndroid Build Coastguard Worker // correctly.
95*8fb009dcSAndroid Build Coastguard Worker typedef int (*lhash_cmp_func)(const void *a, const void *b);
96*8fb009dcSAndroid Build Coastguard Worker typedef int (*lhash_cmp_func_helper)(lhash_cmp_func func, const void *a,
97*8fb009dcSAndroid Build Coastguard Worker                                      const void *b);
98*8fb009dcSAndroid Build Coastguard Worker 
99*8fb009dcSAndroid Build Coastguard Worker // lhash_hash_func is a function that maps an object to a uniformly distributed
100*8fb009dcSAndroid Build Coastguard Worker // uint32_t.
101*8fb009dcSAndroid Build Coastguard Worker //
102*8fb009dcSAndroid Build Coastguard Worker // This function's actual type signature is uint32_t (*)(const T*). The
103*8fb009dcSAndroid Build Coastguard Worker // low-level |lh_*| functions will be passed a type-specific wrapper to call it
104*8fb009dcSAndroid Build Coastguard Worker // correctly.
105*8fb009dcSAndroid Build Coastguard Worker typedef uint32_t (*lhash_hash_func)(const void *a);
106*8fb009dcSAndroid Build Coastguard Worker typedef uint32_t (*lhash_hash_func_helper)(lhash_hash_func func, const void *a);
107*8fb009dcSAndroid Build Coastguard Worker 
108*8fb009dcSAndroid Build Coastguard Worker typedef struct lhash_st _LHASH;
109*8fb009dcSAndroid Build Coastguard Worker 
110*8fb009dcSAndroid Build Coastguard Worker // OPENSSL_lh_new returns a new, empty hash table or NULL on error.
111*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT _LHASH *OPENSSL_lh_new(lhash_hash_func hash,
112*8fb009dcSAndroid Build Coastguard Worker                                       lhash_cmp_func comp);
113*8fb009dcSAndroid Build Coastguard Worker 
114*8fb009dcSAndroid Build Coastguard Worker // OPENSSL_lh_free frees the hash table itself but none of the elements. See
115*8fb009dcSAndroid Build Coastguard Worker // |OPENSSL_lh_doall|.
116*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void OPENSSL_lh_free(_LHASH *lh);
117*8fb009dcSAndroid Build Coastguard Worker 
118*8fb009dcSAndroid Build Coastguard Worker // OPENSSL_lh_num_items returns the number of items in |lh|.
119*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT size_t OPENSSL_lh_num_items(const _LHASH *lh);
120*8fb009dcSAndroid Build Coastguard Worker 
121*8fb009dcSAndroid Build Coastguard Worker // OPENSSL_lh_retrieve finds an element equal to |data| in the hash table and
122*8fb009dcSAndroid Build Coastguard Worker // returns it. If no such element exists, it returns NULL.
123*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void *OPENSSL_lh_retrieve(const _LHASH *lh, const void *data,
124*8fb009dcSAndroid Build Coastguard Worker                                          lhash_hash_func_helper call_hash_func,
125*8fb009dcSAndroid Build Coastguard Worker                                          lhash_cmp_func_helper call_cmp_func);
126*8fb009dcSAndroid Build Coastguard Worker 
127*8fb009dcSAndroid Build Coastguard Worker // OPENSSL_lh_retrieve_key finds an element matching |key|, given the specified
128*8fb009dcSAndroid Build Coastguard Worker // hash and comparison function. This differs from |OPENSSL_lh_retrieve| in that
129*8fb009dcSAndroid Build Coastguard Worker // the key may be a different type than the values stored in |lh|. |key_hash|
130*8fb009dcSAndroid Build Coastguard Worker // and |cmp_key| must be compatible with the functions passed into
131*8fb009dcSAndroid Build Coastguard Worker // |OPENSSL_lh_new|.
132*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void *OPENSSL_lh_retrieve_key(const _LHASH *lh, const void *key,
133*8fb009dcSAndroid Build Coastguard Worker                                              uint32_t key_hash,
134*8fb009dcSAndroid Build Coastguard Worker                                              int (*cmp_key)(const void *key,
135*8fb009dcSAndroid Build Coastguard Worker                                                             const void *value));
136*8fb009dcSAndroid Build Coastguard Worker 
137*8fb009dcSAndroid Build Coastguard Worker // OPENSSL_lh_insert inserts |data| into the hash table. If an existing element
138*8fb009dcSAndroid Build Coastguard Worker // is equal to |data| (with respect to the comparison function) then |*old_data|
139*8fb009dcSAndroid Build Coastguard Worker // will be set to that value and it will be replaced. Otherwise, or in the
140*8fb009dcSAndroid Build Coastguard Worker // event of an error, |*old_data| will be set to NULL. It returns one on
141*8fb009dcSAndroid Build Coastguard Worker // success or zero in the case of an allocation error.
142*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int OPENSSL_lh_insert(_LHASH *lh, void **old_data, void *data,
143*8fb009dcSAndroid Build Coastguard Worker                                      lhash_hash_func_helper call_hash_func,
144*8fb009dcSAndroid Build Coastguard Worker                                      lhash_cmp_func_helper call_cmp_func);
145*8fb009dcSAndroid Build Coastguard Worker 
146*8fb009dcSAndroid Build Coastguard Worker // OPENSSL_lh_delete removes an element equal to |data| from the hash table and
147*8fb009dcSAndroid Build Coastguard Worker // returns it. If no such element is found, it returns NULL.
148*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void *OPENSSL_lh_delete(_LHASH *lh, const void *data,
149*8fb009dcSAndroid Build Coastguard Worker                                        lhash_hash_func_helper call_hash_func,
150*8fb009dcSAndroid Build Coastguard Worker                                        lhash_cmp_func_helper call_cmp_func);
151*8fb009dcSAndroid Build Coastguard Worker 
152*8fb009dcSAndroid Build Coastguard Worker // OPENSSL_lh_doall_arg calls |func| on each element of the hash table and also
153*8fb009dcSAndroid Build Coastguard Worker // passes |arg| as the second argument.
154*8fb009dcSAndroid Build Coastguard Worker // TODO(fork): rename this
155*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void OPENSSL_lh_doall_arg(_LHASH *lh,
156*8fb009dcSAndroid Build Coastguard Worker                                          void (*func)(void *, void *),
157*8fb009dcSAndroid Build Coastguard Worker                                          void *arg);
158*8fb009dcSAndroid Build Coastguard Worker 
159*8fb009dcSAndroid Build Coastguard Worker #define DEFINE_LHASH_OF(type)                                                  \
160*8fb009dcSAndroid Build Coastguard Worker   /* We disable MSVC C4191 in this macro, which warns when pointers are cast   \
161*8fb009dcSAndroid Build Coastguard Worker    * to the wrong type. While the cast itself is valid, it is often a bug      \
162*8fb009dcSAndroid Build Coastguard Worker    * because calling it through the cast is UB. However, we never actually     \
163*8fb009dcSAndroid Build Coastguard Worker    * call functions as |lhash_cmp_func|. The type is just a type-erased        \
164*8fb009dcSAndroid Build Coastguard Worker    * function pointer. (C does not guarantee function pointers fit in          \
165*8fb009dcSAndroid Build Coastguard Worker    * |void*|, and GCC will warn on this.) Thus we just disable the false       \
166*8fb009dcSAndroid Build Coastguard Worker    * positive warning. */                                                      \
167*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_MSVC_PRAGMA(warning(push))                                           \
168*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_MSVC_PRAGMA(warning(disable : 4191))                                 \
169*8fb009dcSAndroid Build Coastguard Worker                                                                                \
170*8fb009dcSAndroid Build Coastguard Worker   DECLARE_LHASH_OF(type)                                                       \
171*8fb009dcSAndroid Build Coastguard Worker                                                                                \
172*8fb009dcSAndroid Build Coastguard Worker   typedef int (*lhash_##type##_cmp_func)(const type *, const type *);          \
173*8fb009dcSAndroid Build Coastguard Worker   typedef uint32_t (*lhash_##type##_hash_func)(const type *);                  \
174*8fb009dcSAndroid Build Coastguard Worker                                                                                \
175*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE int lh_##type##_call_cmp_func(lhash_cmp_func func,            \
176*8fb009dcSAndroid Build Coastguard Worker                                                const void *a, const void *b) { \
177*8fb009dcSAndroid Build Coastguard Worker     return ((lhash_##type##_cmp_func)func)((const type *)a, (const type *)b);  \
178*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
179*8fb009dcSAndroid Build Coastguard Worker                                                                                \
180*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE uint32_t lh_##type##_call_hash_func(lhash_hash_func func,     \
181*8fb009dcSAndroid Build Coastguard Worker                                                      const void *a) {          \
182*8fb009dcSAndroid Build Coastguard Worker     return ((lhash_##type##_hash_func)func)((const type *)a);                  \
183*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
184*8fb009dcSAndroid Build Coastguard Worker                                                                                \
185*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE LHASH_OF(type) *lh_##type##_new(                              \
186*8fb009dcSAndroid Build Coastguard Worker       lhash_##type##_hash_func hash, lhash_##type##_cmp_func comp) {           \
187*8fb009dcSAndroid Build Coastguard Worker     return (LHASH_OF(type) *)OPENSSL_lh_new((lhash_hash_func)hash,             \
188*8fb009dcSAndroid Build Coastguard Worker                                             (lhash_cmp_func)comp);             \
189*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
190*8fb009dcSAndroid Build Coastguard Worker                                                                                \
191*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE void lh_##type##_free(LHASH_OF(type) *lh) {                   \
192*8fb009dcSAndroid Build Coastguard Worker     OPENSSL_lh_free((_LHASH *)lh);                                             \
193*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
194*8fb009dcSAndroid Build Coastguard Worker                                                                                \
195*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE size_t lh_##type##_num_items(const LHASH_OF(type) *lh) {      \
196*8fb009dcSAndroid Build Coastguard Worker     return OPENSSL_lh_num_items((const _LHASH *)lh);                           \
197*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
198*8fb009dcSAndroid Build Coastguard Worker                                                                                \
199*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE type *lh_##type##_retrieve(const LHASH_OF(type) *lh,          \
200*8fb009dcSAndroid Build Coastguard Worker                                             const type *data) {                \
201*8fb009dcSAndroid Build Coastguard Worker     return (type *)OPENSSL_lh_retrieve((const _LHASH *)lh, data,               \
202*8fb009dcSAndroid Build Coastguard Worker                                        lh_##type##_call_hash_func,             \
203*8fb009dcSAndroid Build Coastguard Worker                                        lh_##type##_call_cmp_func);             \
204*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
205*8fb009dcSAndroid Build Coastguard Worker                                                                                \
206*8fb009dcSAndroid Build Coastguard Worker   typedef struct {                                                             \
207*8fb009dcSAndroid Build Coastguard Worker     int (*cmp_key)(const void *key, const type *value);                        \
208*8fb009dcSAndroid Build Coastguard Worker     const void *key;                                                           \
209*8fb009dcSAndroid Build Coastguard Worker   } LHASH_CMP_KEY_##type;                                                      \
210*8fb009dcSAndroid Build Coastguard Worker                                                                                \
211*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE int lh_##type##_call_cmp_key(const void *key,                 \
212*8fb009dcSAndroid Build Coastguard Worker                                               const void *value) {             \
213*8fb009dcSAndroid Build Coastguard Worker     const LHASH_CMP_KEY_##type *cb = (const LHASH_CMP_KEY_##type *)key;        \
214*8fb009dcSAndroid Build Coastguard Worker     return cb->cmp_key(cb->key, (const type *)value);                          \
215*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
216*8fb009dcSAndroid Build Coastguard Worker                                                                                \
217*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE type *lh_##type##_retrieve_key(                               \
218*8fb009dcSAndroid Build Coastguard Worker       const LHASH_OF(type) *lh, const void *key, uint32_t key_hash,            \
219*8fb009dcSAndroid Build Coastguard Worker       int (*cmp_key)(const void *key, const type *value)) {                    \
220*8fb009dcSAndroid Build Coastguard Worker     LHASH_CMP_KEY_##type cb = {cmp_key, key};                                  \
221*8fb009dcSAndroid Build Coastguard Worker     return (type *)OPENSSL_lh_retrieve_key((const _LHASH *)lh, &cb, key_hash,  \
222*8fb009dcSAndroid Build Coastguard Worker                                            lh_##type##_call_cmp_key);          \
223*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
224*8fb009dcSAndroid Build Coastguard Worker                                                                                \
225*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE int lh_##type##_insert(LHASH_OF(type) *lh, type **old_data,   \
226*8fb009dcSAndroid Build Coastguard Worker                                         type *data) {                          \
227*8fb009dcSAndroid Build Coastguard Worker     void *old_data_void = NULL;                                                \
228*8fb009dcSAndroid Build Coastguard Worker     int ret = OPENSSL_lh_insert((_LHASH *)lh, &old_data_void, data,            \
229*8fb009dcSAndroid Build Coastguard Worker                                 lh_##type##_call_hash_func,                    \
230*8fb009dcSAndroid Build Coastguard Worker                                 lh_##type##_call_cmp_func);                    \
231*8fb009dcSAndroid Build Coastguard Worker     *old_data = (type *)old_data_void;                                         \
232*8fb009dcSAndroid Build Coastguard Worker     return ret;                                                                \
233*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
234*8fb009dcSAndroid Build Coastguard Worker                                                                                \
235*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE type *lh_##type##_delete(LHASH_OF(type) *lh,                  \
236*8fb009dcSAndroid Build Coastguard Worker                                           const type *data) {                  \
237*8fb009dcSAndroid Build Coastguard Worker     return (type *)OPENSSL_lh_delete((_LHASH *)lh, data,                       \
238*8fb009dcSAndroid Build Coastguard Worker                                      lh_##type##_call_hash_func,               \
239*8fb009dcSAndroid Build Coastguard Worker                                      lh_##type##_call_cmp_func);               \
240*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
241*8fb009dcSAndroid Build Coastguard Worker                                                                                \
242*8fb009dcSAndroid Build Coastguard Worker   typedef struct {                                                             \
243*8fb009dcSAndroid Build Coastguard Worker     void (*doall_arg)(type *, void *);                                         \
244*8fb009dcSAndroid Build Coastguard Worker     void *arg;                                                                 \
245*8fb009dcSAndroid Build Coastguard Worker   } LHASH_DOALL_##type;                                                        \
246*8fb009dcSAndroid Build Coastguard Worker                                                                                \
247*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE void lh_##type##_call_doall_arg(void *value, void *arg) {     \
248*8fb009dcSAndroid Build Coastguard Worker     const LHASH_DOALL_##type *cb = (const LHASH_DOALL_##type *)arg;            \
249*8fb009dcSAndroid Build Coastguard Worker     cb->doall_arg((type *)value, cb->arg);                                     \
250*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
251*8fb009dcSAndroid Build Coastguard Worker                                                                                \
252*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_INLINE void lh_##type##_doall_arg(                                   \
253*8fb009dcSAndroid Build Coastguard Worker       LHASH_OF(type) *lh, void (*func)(type *, void *), void *arg) {           \
254*8fb009dcSAndroid Build Coastguard Worker     LHASH_DOALL_##type cb = {func, arg};                                       \
255*8fb009dcSAndroid Build Coastguard Worker     OPENSSL_lh_doall_arg((_LHASH *)lh, lh_##type##_call_doall_arg, &cb);       \
256*8fb009dcSAndroid Build Coastguard Worker   }                                                                            \
257*8fb009dcSAndroid Build Coastguard Worker                                                                                \
258*8fb009dcSAndroid Build Coastguard Worker   OPENSSL_MSVC_PRAGMA(warning(pop))
259*8fb009dcSAndroid Build Coastguard Worker 
260*8fb009dcSAndroid Build Coastguard Worker 
261*8fb009dcSAndroid Build Coastguard Worker #if defined(__cplusplus)
262*8fb009dcSAndroid Build Coastguard Worker }  // extern C
263*8fb009dcSAndroid Build Coastguard Worker #endif
264*8fb009dcSAndroid Build Coastguard Worker 
265*8fb009dcSAndroid Build Coastguard Worker #endif  // OPENSSL_HEADER_LHASH_INTERNAL_H
266