xref: /freebsd/crypto/openssl/include/internal/hashtable.h (revision e7be843b4a162e68651d3911f0357ed464915629)
1*e7be843bSPierre Pronchery /*
2*e7be843bSPierre Pronchery  * Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.
3*e7be843bSPierre Pronchery  *
4*e7be843bSPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*e7be843bSPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
6*e7be843bSPierre Pronchery  * in the file LICENSE in the source distribution or at
7*e7be843bSPierre Pronchery  * https://www.openssl.org/source/license.html
8*e7be843bSPierre Pronchery  */
9*e7be843bSPierre Pronchery 
10*e7be843bSPierre Pronchery #ifndef OPENSSL_HASHTABLE_H
11*e7be843bSPierre Pronchery # define OPENSSL_HASHTABLE_H
12*e7be843bSPierre Pronchery # pragma once
13*e7be843bSPierre Pronchery 
14*e7be843bSPierre Pronchery #include <stddef.h>
15*e7be843bSPierre Pronchery #include <stdint.h>
16*e7be843bSPierre Pronchery #include <openssl/e_os2.h>
17*e7be843bSPierre Pronchery #include <internal/rcu.h>
18*e7be843bSPierre Pronchery #include "crypto/context.h"
19*e7be843bSPierre Pronchery 
20*e7be843bSPierre Pronchery typedef struct ht_internal_st HT;
21*e7be843bSPierre Pronchery 
22*e7be843bSPierre Pronchery /*
23*e7be843bSPierre Pronchery  * Represents a key to a hashtable
24*e7be843bSPierre Pronchery  */
25*e7be843bSPierre Pronchery typedef struct ht_key_header_st {
26*e7be843bSPierre Pronchery     size_t keysize;
27*e7be843bSPierre Pronchery     uint8_t *keybuf;
28*e7be843bSPierre Pronchery } HT_KEY;
29*e7be843bSPierre Pronchery 
30*e7be843bSPierre Pronchery /*
31*e7be843bSPierre Pronchery  * Represents a value in the hash table
32*e7be843bSPierre Pronchery  */
33*e7be843bSPierre Pronchery typedef struct ht_value_st {
34*e7be843bSPierre Pronchery     void *value;
35*e7be843bSPierre Pronchery     uintptr_t *type_id;
36*e7be843bSPierre Pronchery     HT_KEY key;
37*e7be843bSPierre Pronchery } HT_VALUE;
38*e7be843bSPierre Pronchery 
39*e7be843bSPierre Pronchery /*
40*e7be843bSPierre Pronchery  * Represents a list of values filtered from a hash table
41*e7be843bSPierre Pronchery  */
42*e7be843bSPierre Pronchery typedef struct ht_value_list_st {
43*e7be843bSPierre Pronchery     size_t list_len;
44*e7be843bSPierre Pronchery     HT_VALUE **list;
45*e7be843bSPierre Pronchery } HT_VALUE_LIST;
46*e7be843bSPierre Pronchery 
47*e7be843bSPierre Pronchery /*
48*e7be843bSPierre Pronchery  * Hashtable configuration
49*e7be843bSPierre Pronchery  */
50*e7be843bSPierre Pronchery typedef struct ht_config_st {
51*e7be843bSPierre Pronchery     OSSL_LIB_CTX *ctx;
52*e7be843bSPierre Pronchery     void (*ht_free_fn)(HT_VALUE *obj);
53*e7be843bSPierre Pronchery     uint64_t (*ht_hash_fn)(uint8_t *key, size_t keylen);
54*e7be843bSPierre Pronchery     size_t init_neighborhoods;
55*e7be843bSPierre Pronchery     uint32_t collision_check;
56*e7be843bSPierre Pronchery     uint32_t lockless_reads;
57*e7be843bSPierre Pronchery } HT_CONFIG;
58*e7be843bSPierre Pronchery 
59*e7be843bSPierre Pronchery /*
60*e7be843bSPierre Pronchery  * Hashtable key rules
61*e7be843bSPierre Pronchery  * Any struct can be used to formulate a hash table key, as long as the
62*e7be843bSPierre Pronchery  * following rules
63*e7be843bSPierre Pronchery  * 1) The first element of the struct defining the key must be an HT_KEY
64*e7be843bSPierre Pronchery  * 2) All struct elements must have a compile time defined length
65*e7be843bSPierre Pronchery  * 3) Pointers can be used, but the value of the pointer, rather than
66*e7be843bSPierre Pronchery  *    the contents of the address it points to will be used to compute
67*e7be843bSPierre Pronchery  *    the hash
68*e7be843bSPierre Pronchery  * The key definition macros will assist with enforcing these rules
69*e7be843bSPierre Pronchery  */
70*e7be843bSPierre Pronchery 
71*e7be843bSPierre Pronchery /*
72*e7be843bSPierre Pronchery  * Starts the definition of a hash table key
73*e7be843bSPierre Pronchery  */
74*e7be843bSPierre Pronchery #define HT_START_KEY_DEFN(keyname) \
75*e7be843bSPierre Pronchery typedef struct keyname##_st { \
76*e7be843bSPierre Pronchery     HT_KEY key_header; \
77*e7be843bSPierre Pronchery     struct {
78*e7be843bSPierre Pronchery 
79*e7be843bSPierre Pronchery /*
80*e7be843bSPierre Pronchery  * Ends a hash table key definitions
81*e7be843bSPierre Pronchery  */
82*e7be843bSPierre Pronchery #define HT_END_KEY_DEFN(keyname) \
83*e7be843bSPierre Pronchery     } keyfields; \
84*e7be843bSPierre Pronchery } keyname;
85*e7be843bSPierre Pronchery 
86*e7be843bSPierre Pronchery /*
87*e7be843bSPierre Pronchery  * Defines a field in a hash table key
88*e7be843bSPierre Pronchery  */
89*e7be843bSPierre Pronchery #define HT_DEF_KEY_FIELD(name, type) type name;
90*e7be843bSPierre Pronchery 
91*e7be843bSPierre Pronchery /*
92*e7be843bSPierre Pronchery  * convenience macro to define a static char
93*e7be843bSPierre Pronchery  * array field in a hash table key
94*e7be843bSPierre Pronchery  */
95*e7be843bSPierre Pronchery #define HT_DEF_KEY_FIELD_CHAR_ARRAY(name, size) \
96*e7be843bSPierre Pronchery      HT_DEF_KEY_FIELD(name[size], char)
97*e7be843bSPierre Pronchery 
98*e7be843bSPierre Pronchery /*
99*e7be843bSPierre Pronchery  * Defines a uint8_t (blob) field in a hash table key
100*e7be843bSPierre Pronchery  */
101*e7be843bSPierre Pronchery #define HT_DEF_KEY_FIELD_UINT8T_ARRAY(name, size) \
102*e7be843bSPierre Pronchery     HT_DEF_KEY_FIELD(name[size], uint8_t)
103*e7be843bSPierre Pronchery 
104*e7be843bSPierre Pronchery /*
105*e7be843bSPierre Pronchery  * Initializes a key
106*e7be843bSPierre Pronchery  */
107*e7be843bSPierre Pronchery #define HT_INIT_KEY(key) do { \
108*e7be843bSPierre Pronchery memset((key), 0, sizeof(*(key))); \
109*e7be843bSPierre Pronchery (key)->key_header.keysize = (sizeof(*(key)) - sizeof(HT_KEY)); \
110*e7be843bSPierre Pronchery (key)->key_header.keybuf = (((uint8_t *)key) + sizeof(HT_KEY)); \
111*e7be843bSPierre Pronchery } while(0)
112*e7be843bSPierre Pronchery 
113*e7be843bSPierre Pronchery /*
114*e7be843bSPierre Pronchery  * Resets a hash table key to a known state
115*e7be843bSPierre Pronchery  */
116*e7be843bSPierre Pronchery #define HT_KEY_RESET(key) memset((key)->key_header.keybuf, 0, (key)->key_header.keysize)
117*e7be843bSPierre Pronchery 
118*e7be843bSPierre Pronchery /*
119*e7be843bSPierre Pronchery  * Sets a scalar field in a hash table key
120*e7be843bSPierre Pronchery  */
121*e7be843bSPierre Pronchery #define HT_SET_KEY_FIELD(key, member, value) (key)->keyfields.member = value;
122*e7be843bSPierre Pronchery 
123*e7be843bSPierre Pronchery /*
124*e7be843bSPierre Pronchery  * Sets a string field in a hash table key, preserving
125*e7be843bSPierre Pronchery  * null terminator
126*e7be843bSPierre Pronchery  */
127*e7be843bSPierre Pronchery #define HT_SET_KEY_STRING(key, member, value) do { \
128*e7be843bSPierre Pronchery     if ((value) != NULL) \
129*e7be843bSPierre Pronchery         strncpy((key)->keyfields.member, value, sizeof((key)->keyfields.member) - 1); \
130*e7be843bSPierre Pronchery } while(0)
131*e7be843bSPierre Pronchery 
132*e7be843bSPierre Pronchery /*
133*e7be843bSPierre Pronchery  * This is the same as HT_SET_KEY_STRING, except that it uses
134*e7be843bSPierre Pronchery  * ossl_ht_strcase to make the value being passed case insensitive
135*e7be843bSPierre Pronchery  * This is useful for instances in which we want upper and lower case
136*e7be843bSPierre Pronchery  * key value to hash to the same entry
137*e7be843bSPierre Pronchery  */
138*e7be843bSPierre Pronchery #define HT_SET_KEY_STRING_CASE(key, member, value) do { \
139*e7be843bSPierre Pronchery    ossl_ht_strcase((key)->keyfields.member, value, sizeof((key)->keyfields.member) -1); \
140*e7be843bSPierre Pronchery } while(0)
141*e7be843bSPierre Pronchery 
142*e7be843bSPierre Pronchery /*
143*e7be843bSPierre Pronchery  * Same as HT_SET_KEY_STRING but also takes length of the string.
144*e7be843bSPierre Pronchery  */
145*e7be843bSPierre Pronchery #define HT_SET_KEY_STRING_N(key, member, value, len) do { \
146*e7be843bSPierre Pronchery     if ((value) != NULL) { \
147*e7be843bSPierre Pronchery         if (len < sizeof((key)->keyfields.member)) \
148*e7be843bSPierre Pronchery             strncpy((key)->keyfields.member, value, len); \
149*e7be843bSPierre Pronchery         else \
150*e7be843bSPierre Pronchery             strncpy((key)->keyfields.member, value, sizeof((key)->keyfields.member) - 1); \
151*e7be843bSPierre Pronchery     } \
152*e7be843bSPierre Pronchery } while(0)
153*e7be843bSPierre Pronchery 
154*e7be843bSPierre Pronchery /* Same as HT_SET_KEY_STRING_CASE but also takes length of the string. */
155*e7be843bSPierre Pronchery #define HT_SET_KEY_STRING_CASE_N(key, member, value, len) do { \
156*e7be843bSPierre Pronchery     if (len < sizeof((key)->keyfields.member)) \
157*e7be843bSPierre Pronchery         ossl_ht_strcase((key)->keyfields.member, value, len); \
158*e7be843bSPierre Pronchery     else \
159*e7be843bSPierre Pronchery         ossl_ht_strcase((key)->keyfields.member, value, sizeof((key)->keyfields.member) - 1); \
160*e7be843bSPierre Pronchery } while(0)
161*e7be843bSPierre Pronchery 
162*e7be843bSPierre Pronchery /*
163*e7be843bSPierre Pronchery  * Sets a uint8_t (blob) field in a hash table key
164*e7be843bSPierre Pronchery  */
165*e7be843bSPierre Pronchery #define HT_SET_KEY_BLOB(key, member, value, len) do { \
166*e7be843bSPierre Pronchery     if (value != NULL) \
167*e7be843bSPierre Pronchery         memcpy((key)->keyfields.member, value, len); \
168*e7be843bSPierre Pronchery } while(0)
169*e7be843bSPierre Pronchery 
170*e7be843bSPierre Pronchery /*
171*e7be843bSPierre Pronchery  * Converts a defined key type to an HT_KEY
172*e7be843bSPierre Pronchery  */
173*e7be843bSPierre Pronchery #define TO_HT_KEY(key) &(key)->key_header
174*e7be843bSPierre Pronchery 
175*e7be843bSPierre Pronchery /*
176*e7be843bSPierre Pronchery  * Converts an HT_KEY back to its defined
177*e7be843bSPierre Pronchery  * type
178*e7be843bSPierre Pronchery  */
179*e7be843bSPierre Pronchery #define FROM_HT_KEY(key, type) (type)(key)
180*e7be843bSPierre Pronchery 
181*e7be843bSPierre Pronchery /*
182*e7be843bSPierre Pronchery  * Implements the following type safe operations for a hash table
183*e7be843bSPierre Pronchery  * ossl_ht_NAME_TYPE_insert - insert a value to a hash table of type TYPE
184*e7be843bSPierre Pronchery  * ossl_ht_NAME_TYPE_get - gets a value of a specific type from the hash table
185*e7be843bSPierre Pronchery  * ossl_ht_NAME_TYPE_from_value - converts an HT_VALUE to its type
186*e7be843bSPierre Pronchery  * ossl_ht_NAME_TYPE_to_value - converts a TYPE to an HT_VALUE
187*e7be843bSPierre Pronchery  * ossl_ht_NAME_TYPE_type - boolean to detect if a value is of TYPE
188*e7be843bSPierre Pronchery  */
189*e7be843bSPierre Pronchery #define IMPLEMENT_HT_VALUE_TYPE_FNS(vtype, name, pfx) \
190*e7be843bSPierre Pronchery static uintptr_t name##_##vtype##_id = 0; \
191*e7be843bSPierre Pronchery pfx ossl_unused int ossl_ht_##name##_##vtype##_insert(HT *h, HT_KEY *key,      \
192*e7be843bSPierre Pronchery                                                       vtype *data,             \
193*e7be843bSPierre Pronchery                                                       vtype **olddata) {       \
194*e7be843bSPierre Pronchery     HT_VALUE inval;                                                            \
195*e7be843bSPierre Pronchery     HT_VALUE *oval = NULL;                                                     \
196*e7be843bSPierre Pronchery     int rc;                                                                    \
197*e7be843bSPierre Pronchery                                                                                \
198*e7be843bSPierre Pronchery     inval.value = data;                                                        \
199*e7be843bSPierre Pronchery     inval.type_id = &name##_##vtype##_id;                                      \
200*e7be843bSPierre Pronchery     rc = ossl_ht_insert(h, key, &inval, olddata == NULL ? NULL : &oval);       \
201*e7be843bSPierre Pronchery     if (oval != NULL)                                                          \
202*e7be843bSPierre Pronchery         *olddata = (vtype *)oval->value;                                       \
203*e7be843bSPierre Pronchery     return rc;                                                                 \
204*e7be843bSPierre Pronchery }                                                                              \
205*e7be843bSPierre Pronchery                                                                                \
206*e7be843bSPierre Pronchery pfx ossl_unused vtype *ossl_ht_##name##_##vtype##_from_value(HT_VALUE *v)      \
207*e7be843bSPierre Pronchery {                                                                              \
208*e7be843bSPierre Pronchery     uintptr_t *expect_type = &name##_##vtype##_id;                             \
209*e7be843bSPierre Pronchery     if (v == NULL)                                                             \
210*e7be843bSPierre Pronchery         return NULL;                                                           \
211*e7be843bSPierre Pronchery     if (v->type_id != expect_type)                                             \
212*e7be843bSPierre Pronchery         return NULL;                                                           \
213*e7be843bSPierre Pronchery     return (vtype *)v->value;                                                  \
214*e7be843bSPierre Pronchery }                                                                              \
215*e7be843bSPierre Pronchery                                                                                \
216*e7be843bSPierre Pronchery pfx ossl_unused vtype *ossl_unused ossl_ht_##name##_##vtype##_get(HT *h,       \
217*e7be843bSPierre Pronchery                                                                   HT_KEY *key, \
218*e7be843bSPierre Pronchery                                                                   HT_VALUE **v)\
219*e7be843bSPierre Pronchery {                                                                              \
220*e7be843bSPierre Pronchery     HT_VALUE *vv;                                                              \
221*e7be843bSPierre Pronchery     vv = ossl_ht_get(h, key);                                                  \
222*e7be843bSPierre Pronchery     if (vv == NULL)                                                            \
223*e7be843bSPierre Pronchery         return NULL;                                                           \
224*e7be843bSPierre Pronchery     *v = ossl_rcu_deref(&vv);                                                  \
225*e7be843bSPierre Pronchery     return ossl_ht_##name##_##vtype##_from_value(*v);                          \
226*e7be843bSPierre Pronchery }                                                                              \
227*e7be843bSPierre Pronchery                                                                                \
228*e7be843bSPierre Pronchery pfx ossl_unused HT_VALUE *ossl_ht_##name##_##vtype##_to_value(vtype *data,     \
229*e7be843bSPierre Pronchery                                                               HT_VALUE *v)     \
230*e7be843bSPierre Pronchery {                                                                              \
231*e7be843bSPierre Pronchery     v->type_id = &name##_##vtype##_id;                                         \
232*e7be843bSPierre Pronchery     v->value = data;                                                           \
233*e7be843bSPierre Pronchery     return v;                                                                  \
234*e7be843bSPierre Pronchery }                                                                              \
235*e7be843bSPierre Pronchery                                                                                \
236*e7be843bSPierre Pronchery pfx ossl_unused int ossl_ht_##name##_##vtype##_type(HT_VALUE *h)               \
237*e7be843bSPierre Pronchery {                                                                              \
238*e7be843bSPierre Pronchery     return h->type_id == &name##_##vtype##_id;                                 \
239*e7be843bSPierre Pronchery }
240*e7be843bSPierre Pronchery 
241*e7be843bSPierre Pronchery #define DECLARE_HT_VALUE_TYPE_FNS(vtype, name)                                 \
242*e7be843bSPierre Pronchery int ossl_ht_##name##_##vtype##_insert(HT *h, HT_KEY *key, vtype *data,         \
243*e7be843bSPierre Pronchery                                       vtype **olddata);                        \
244*e7be843bSPierre Pronchery vtype *ossl_ht_##name##_##vtype##_from_value(HT_VALUE *v);                     \
245*e7be843bSPierre Pronchery vtype *ossl_unused ossl_ht_##name##_##vtype##_get(HT *h,                       \
246*e7be843bSPierre Pronchery                                                   HT_KEY *key,                 \
247*e7be843bSPierre Pronchery                                                   HT_VALUE **v);               \
248*e7be843bSPierre Pronchery HT_VALUE *ossl_ht_##name##_##vtype##_to_value(vtype *data, HT_VALUE *v);       \
249*e7be843bSPierre Pronchery int ossl_ht_##name##_##vtype##_type(HT_VALUE *h);                              \
250*e7be843bSPierre Pronchery 
251*e7be843bSPierre Pronchery /*
252*e7be843bSPierre Pronchery  * Helper function to construct case insensitive keys
253*e7be843bSPierre Pronchery  */
ossl_ht_strcase(char * tgt,const char * src,int len)254*e7be843bSPierre Pronchery static void ossl_unused ossl_ht_strcase(char *tgt, const char *src, int len)
255*e7be843bSPierre Pronchery {
256*e7be843bSPierre Pronchery     int i;
257*e7be843bSPierre Pronchery #if defined(CHARSET_EBCDIC) && !defined(CHARSET_EBCDIC_TEST)
258*e7be843bSPierre Pronchery     const long int case_adjust = ~0x40;
259*e7be843bSPierre Pronchery #else
260*e7be843bSPierre Pronchery     const long int case_adjust = ~0x20;
261*e7be843bSPierre Pronchery #endif
262*e7be843bSPierre Pronchery 
263*e7be843bSPierre Pronchery     if (src == NULL)
264*e7be843bSPierre Pronchery         return;
265*e7be843bSPierre Pronchery 
266*e7be843bSPierre Pronchery     for (i = 0; src[i] != '\0' && i < len; i++)
267*e7be843bSPierre Pronchery         tgt[i] = case_adjust & src[i];
268*e7be843bSPierre Pronchery }
269*e7be843bSPierre Pronchery 
270*e7be843bSPierre Pronchery /*
271*e7be843bSPierre Pronchery  * Create a new hashtable
272*e7be843bSPierre Pronchery  */
273*e7be843bSPierre Pronchery HT *ossl_ht_new(const HT_CONFIG *conf);
274*e7be843bSPierre Pronchery 
275*e7be843bSPierre Pronchery /*
276*e7be843bSPierre Pronchery  * Frees a hash table, potentially freeing all elements
277*e7be843bSPierre Pronchery  */
278*e7be843bSPierre Pronchery void ossl_ht_free(HT *htable);
279*e7be843bSPierre Pronchery 
280*e7be843bSPierre Pronchery /*
281*e7be843bSPierre Pronchery  * Lock the table for reading
282*e7be843bSPierre Pronchery  */
283*e7be843bSPierre Pronchery void ossl_ht_read_lock(HT *htable);
284*e7be843bSPierre Pronchery 
285*e7be843bSPierre Pronchery /*
286*e7be843bSPierre Pronchery  * Lock the table for writing
287*e7be843bSPierre Pronchery  */
288*e7be843bSPierre Pronchery void ossl_ht_write_lock(HT *htable);
289*e7be843bSPierre Pronchery 
290*e7be843bSPierre Pronchery /*
291*e7be843bSPierre Pronchery  * Read unlock
292*e7be843bSPierre Pronchery  */
293*e7be843bSPierre Pronchery void ossl_ht_read_unlock(HT *htable);
294*e7be843bSPierre Pronchery 
295*e7be843bSPierre Pronchery /*
296*e7be843bSPierre Pronchery  * Write unlock
297*e7be843bSPierre Pronchery  */
298*e7be843bSPierre Pronchery void ossl_ht_write_unlock (HT *htable);
299*e7be843bSPierre Pronchery 
300*e7be843bSPierre Pronchery /*
301*e7be843bSPierre Pronchery  * Empties a hash table, potentially freeing all elements
302*e7be843bSPierre Pronchery  */
303*e7be843bSPierre Pronchery int  ossl_ht_flush(HT *htable);
304*e7be843bSPierre Pronchery 
305*e7be843bSPierre Pronchery /*
306*e7be843bSPierre Pronchery  * Inserts an element to a hash table, optionally returning
307*e7be843bSPierre Pronchery  * replaced data to caller
308*e7be843bSPierre Pronchery  * Returns 1 if the insert was successful, 0 on error
309*e7be843bSPierre Pronchery  */
310*e7be843bSPierre Pronchery int ossl_ht_insert(HT *htable, HT_KEY *key, HT_VALUE *data,
311*e7be843bSPierre Pronchery                    HT_VALUE **olddata);
312*e7be843bSPierre Pronchery 
313*e7be843bSPierre Pronchery /*
314*e7be843bSPierre Pronchery  * Deletes a value from a hash table, based on key
315*e7be843bSPierre Pronchery  * Returns 1 if the key was removed, 0 if they key was not found
316*e7be843bSPierre Pronchery  */
317*e7be843bSPierre Pronchery int ossl_ht_delete(HT *htable, HT_KEY *key);
318*e7be843bSPierre Pronchery 
319*e7be843bSPierre Pronchery /*
320*e7be843bSPierre Pronchery  * Returns number of elements in the hash table
321*e7be843bSPierre Pronchery  */
322*e7be843bSPierre Pronchery size_t ossl_ht_count(HT *htable);
323*e7be843bSPierre Pronchery 
324*e7be843bSPierre Pronchery /*
325*e7be843bSPierre Pronchery  * Iterates over each element in the table.
326*e7be843bSPierre Pronchery  * aborts the loop when cb returns 0
327*e7be843bSPierre Pronchery  * Contents of elements in the list may be modified during
328*e7be843bSPierre Pronchery  * this traversal, assuming proper thread safety is observed while doing
329*e7be843bSPierre Pronchery  * so (holding the table write lock is sufficient).  However, elements of the
330*e7be843bSPierre Pronchery  * table may not be inserted or removed while iterating.
331*e7be843bSPierre Pronchery  */
332*e7be843bSPierre Pronchery void ossl_ht_foreach_until(HT *htable, int (*cb)(HT_VALUE *obj, void *arg),
333*e7be843bSPierre Pronchery                            void *arg);
334*e7be843bSPierre Pronchery /*
335*e7be843bSPierre Pronchery  * Returns a list of elements in a hash table based on
336*e7be843bSPierre Pronchery  * filter function return value.  Returns NULL on error,
337*e7be843bSPierre Pronchery  * or an HT_VALUE_LIST object on success.  Note it is possible
338*e7be843bSPierre Pronchery  * That a list will be returned with 0 entries, if none were found.
339*e7be843bSPierre Pronchery  * The zero length list must still be freed via ossl_ht_value_list_free
340*e7be843bSPierre Pronchery  */
341*e7be843bSPierre Pronchery HT_VALUE_LIST *ossl_ht_filter(HT *htable, size_t max_len,
342*e7be843bSPierre Pronchery                               int (*filter)(HT_VALUE *obj, void *arg),
343*e7be843bSPierre Pronchery                               void *arg);
344*e7be843bSPierre Pronchery /*
345*e7be843bSPierre Pronchery  * Frees the list returned from ossl_ht_filter
346*e7be843bSPierre Pronchery  */
347*e7be843bSPierre Pronchery void ossl_ht_value_list_free(HT_VALUE_LIST *list);
348*e7be843bSPierre Pronchery 
349*e7be843bSPierre Pronchery /*
350*e7be843bSPierre Pronchery  * Fetches a value from the hash table, based
351*e7be843bSPierre Pronchery  * on key.  Returns NULL if the element was not found.
352*e7be843bSPierre Pronchery  */
353*e7be843bSPierre Pronchery HT_VALUE *ossl_ht_get(HT *htable, HT_KEY *key);
354*e7be843bSPierre Pronchery 
355*e7be843bSPierre Pronchery #endif
356