LIBS=../../libcrypto
-SOURCE[../../libcrypto]=\
- hashtable.c
+$COMMON=hashtable.c
+
+SOURCE[../../libcrypto]=$COMMON
+SOURCE[../../providers/libfips.a]=$COMMON
return;
}
-HT *ossl_ht_new(HT_CONFIG *conf)
+HT *ossl_ht_new(const HT_CONFIG *conf)
{
HT *new = OPENSSL_zalloc(sizeof(*new));
*/
static int grow_hashtable(HT *h, size_t oldsize)
{
- struct ht_mutable_data_st *newmd = OPENSSL_zalloc(sizeof(*newmd));
+ struct ht_mutable_data_st *newmd;
struct ht_mutable_data_st *oldmd = ossl_rcu_deref(&h->md);
int rc = 0;
uint64_t oldi, oldj, newi, newj;
int rehashed;
size_t newsize = oldsize * 2;
- if (newmd == NULL)
+ if (h->config.lockless_reads)
+ goto out;
+
+ if ((newmd = OPENSSL_zalloc(sizeof(*newmd))) == NULL)
goto out;
/* bucket list is always a power of 2 */
HT_VALUE *nv = NULL;
int rc = 0;
+ if (h->config.lockless_reads)
+ return 0;
+
hash = h->config.ht_hash_fn(key->keybuf, key->keysize);
neigh_idx = hash & h->md->neighborhood_mask;
}
return rc;
}
-
=head1 SYNOPSIS
- HT *ossl_ht_new(HT_CONFIG *conf);
+ HT *ossl_ht_new(const HT_CONFIG *conf);
void ossl_ht_free(HT *htable);
void ossl_ht_read_lock(HT *htable);
void ossl_ht_read_unlock(HT *htable);
of:
I<ht_free_fn> The function to call to free a value, may be NULL.
I<ht_hash_fn> The function to generate a hash value for a key, may be NULL.
- I<init_neighborhood_len> The initial number of neighborhoods in the hash table.
+ I<init_neighborhoods> The initial number of neighborhoods in the hash table.
Note that init_bucket_len may be set to zero, which will use the default initial
bucket size, which will be automatically expanded with the hash table load
average reaches 0.75.
-Note that lockless_read operation implies behavioral restrictions. Specifically
- Only element additions are allowed, deletion operations will fail
+Note that lockless_read operation implies behavioral restrictions. Specifically
+only element additions are allowed, deletion operations will fail
Hash table growth is inhibited. init_bucket_len should be set to an
appropriate value to prevent performance degradation
The table owner is responsible for ensuring there are no readers during a
ossl_ht_get() returns an B<HT_VALUE> pointer, or NULL if the element was not
found.
+ossl_ht_insert() returns 1 if an element was inserted, 0 if the element is
+already present, -1 on fatal errors (memory allocation or growth not allowed).
+
=head1 EXAMPLES
#include <stdio.h>
int FuzzerInitialize(int *argc, char ***argv)
{
- HT_CONFIG fuzz_conf = {NULL, fuzz_free_cb, NULL, 1, 0};
+ HT_CONFIG fuzz_conf = {NULL, fuzz_free_cb, NULL, 0, 1};
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_clear_error();
OSSL_LIB_CTX *ctx;
void (*ht_free_fn)(HT_VALUE *obj);
uint64_t (*ht_hash_fn)(uint8_t *key, size_t keylen);
+ size_t init_neighborhoods;
uint32_t collision_check;
- uint32_t init_neighborhoods;
+ uint32_t lockless_reads;
} HT_CONFIG;
/*
/*
* Create a new hashtable
*/
-HT *ossl_ht_new(HT_CONFIG *conf);
+HT *ossl_ht_new(const HT_CONFIG *conf);
/*
* Frees a hash table, potentially freeing all elements
return c_CRYPTO_secure_allocated(ptr);
}
+void *CRYPTO_aligned_alloc(size_t num, size_t align, void **freeptr,
+ const char *file, int line)
+{
+ return NULL;
+}
+
int BIO_snprintf(char *buf, size_t n, const char *format, ...)
{
va_list args;
NULL,
NULL,
NULL,
- 1,
0,
+ 1,
};
INTKEY key;
int rc = 0;
NULL, /* use default context */
hashtable_intfree, /* our free function */
hashtable_hash, /* our hash function */
- 1, /* Check collisions */
625000, /* preset hash size */
+ 1, /* Check collisions */
};
HT *h;
INTKEY key;
NULL, /* use default context */
hashtable_mt_free, /* our free function */
NULL, /* default hash function */
- 1, /* Check collisions */
0, /* default hash size */
+ 1, /* Check collisions */
};
int ret = 0;
thread_t workers[4];