From 3e3942b42fe45d83070f67bbe8451ed02a47ec96 Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Wed, 19 Feb 2025 16:17:45 -0500 Subject: [PATCH] Add random hash key value to lcidm struct MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is in preparation for using siphash to compute lcidm hash table values Reviewed-by: Saša Nedvědický Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/26849) --- ssl/quic/quic_lcidm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ssl/quic/quic_lcidm.c b/ssl/quic/quic_lcidm.c index ce7e354f3e0..a91ee6cfe83 100644 --- a/ssl/quic/quic_lcidm.c +++ b/ssl/quic/quic_lcidm.c @@ -32,6 +32,9 @@ typedef struct quic_lcid_st { QUIC_CONN_ID cid; uint64_t seq_num; + /* copy of the hash key from lcidm */ + uint64_t *hash_key; + /* Back-pointer to the owning QUIC_LCIDM_CONN structure. */ QUIC_LCIDM_CONN *conn; @@ -55,6 +58,7 @@ struct quic_lcidm_conn_st { struct quic_lcidm_st { OSSL_LIB_CTX *libctx; + uint64_t hash_key[2]; /* random key for siphash */ LHASH_OF(QUIC_LCID) *lcids; /* (QUIC_CONN_ID) -> (QUIC_LCID *) */ LHASH_OF(QUIC_LCIDM_CONN) *conns; /* (void *opaque) -> (QUIC_LCIDM_CONN *) */ size_t lcid_len; /* Length in bytes for all LCIDs */ @@ -104,6 +108,11 @@ QUIC_LCIDM *ossl_quic_lcidm_new(OSSL_LIB_CTX *libctx, size_t lcid_len) if ((lcidm = OPENSSL_zalloc(sizeof(*lcidm))) == NULL) goto err; + /* generate a random key for the hash tables hash function */ + if (!RAND_bytes_ex(libctx, (unsigned char *)&lcidm->hash_key, + sizeof(uint64_t) * 2, 0)) + goto err; + if ((lcidm->lcids = lh_QUIC_LCID_new(lcid_hash, lcid_comp)) == NULL) goto err; -- 2.47.2