[openssl/openssl] 18763e: hashtable: pass HT into hash function

0 views
Skip to first unread message

nikolapajkovsky

unread,
Oct 2, 2025, 8:12:35 AMOct 2
to openssl...@openssl.org
Branch: refs/heads/master
Home: https://github.com/openssl/openssl
Commit: 18763ea15507ecd3cb24d717fd6e738223272391
https://github.com/openssl/openssl/commit/18763ea15507ecd3cb24d717fd6e738223272391
Author: Nikola Pajkovsky <nik...@openssl.org>
Date: 2025-10-02 (Thu, 02 Oct 2025)

Changed paths:
M crypto/hashtable/hashtable.c
M include/internal/hashtable.h
M test/lhash_test.c

Log Message:
-----------
hashtable: pass HT into hash function

When defining a custom hash function for a hashtable key, you typically start with:

HT_START_KEY_DEFN(key)
HT_DEF_KEY_FIELD(k, unsigned char *)
HT_END_KEY_DEFN(KEY)

In this setup, the hash function signature requires keybuf and len as
parameters rather than the hashtable key itself. As a result,
accessing members of the hashtable structure becomes awkward, since
you must do something like:

#define FROM_KEYBUF_TO_HT_KEY(keybuf, type) (type)((keybuf) - sizeof(HT_KEY))

static uint64_t ht_hash(uint8_t *keybuf, size_t keylen)
{
KEY *k = FROM_KEYBUF_TO_HT_KEY(keybuf, KEY *);
...
}

This kind of pointer arithmetic is both unnecessary and error-prone.
A cleaner approach is to pass the HT pointer directly into the hash
function. From there, you can safely cast it to the required type
without the pointer gymnastics.

Signed-off-by: Nikola Pajkovsky <nik...@openssl.org>

Reviewed-by: Saša Nedvědický <sas...@openssl.org>
Reviewed-by: Tomas Mraz <to...@openssl.org>
Reviewed-by: Neil Horman <nho...@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28677)


Commit: 512f176185ebcd98810e181601fcaf7f340439e9
https://github.com/openssl/openssl/commit/512f176185ebcd98810e181601fcaf7f340439e9
Author: Nikola Pajkovsky <nik...@openssl.org>
Date: 2025-10-02 (Thu, 02 Oct 2025)

Changed paths:
M crypto/core_namemap.c
M crypto/hashtable/hashtable.c
M doc/internal/man3/ossl_ht_new.pod
M fuzz/hashtable.c
M include/internal/hashtable.h
M test/lhash_test.c

Log Message:
-----------
hashtable: add option to disable RCU locks

a new config option _no_rcu_ is added into HT_CONFIG. When _no_rcu_ is
set then hashtable can be guarded with any other locking primitives,
and behives as ordinary hashtable. Also, all the impact of the
atomics used internally to the hash table was mitigated.

RCU performance

# INFO: @ test/lhash_test.c:747
# multithread stress runs 40000 ops in 40.779656 seconds

No RCU, guarded with RWLOCK

# INFO: @ test/lhash_test.c:747
# multithread stress runs 40000 ops in 36.976926 seconds

Signed-off-by: Nikola Pajkovsky <nik...@openssl.org>

Reviewed-by: Saša Nedvědický <sas...@openssl.org>
Reviewed-by: Tomas Mraz <to...@openssl.org>
Reviewed-by: Neil Horman <nho...@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28677)


Compare: https://github.com/openssl/openssl/compare/6387ec6d492c...512f176185eb

To unsubscribe from these emails, change your notification settings at https://github.com/openssl/openssl/settings/notifications
Reply all
Reply to author
Forward
0 new messages