]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add random hash key value to lcidm struct
authorNeil Horman <nhorman@openssl.org>
Wed, 19 Feb 2025 21:17:45 +0000 (16:17 -0500)
committerNeil Horman <nhorman@openssl.org>
Sat, 22 Feb 2025 18:23:16 +0000 (13:23 -0500)
This is in preparation for using siphash to compute lcidm hash table
values

Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26849)

ssl/quic/quic_lcidm.c

index ce7e354f3e0e557588f053f5f5879f8af652e56e..a91ee6cfe83ece1ab1133f45ed21ee541cf2a8e0 100644 (file)
@@ -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;