]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Use siphash to implement lcidm hash function
authorNeil Horman <nhorman@openssl.org>
Thu, 20 Feb 2025 15:37:30 +0000 (10:37 -0500)
committerNeil Horman <nhorman@openssl.org>
Sat, 22 Feb 2025 18:23:16 +0000 (13:23 -0500)
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 fd3a0bcbedac840b75c4eeca3ae62273905fba33..7d5cace0e6e6404878fb131b0d4535e1bfc6a4b9 100644 (file)
@@ -11,6 +11,7 @@
 #include "internal/quic_types.h"
 #include "internal/quic_vlint.h"
 #include "internal/common.h"
+#include "crypto/siphash.h"
 #include <openssl/lhash.h>
 #include <openssl/rand.h>
 #include <openssl/err.h>
@@ -67,20 +68,21 @@ struct quic_lcidm_st {
 #endif
 };
 
-static unsigned long bin_hash(const unsigned char *buf, size_t buf_len)
-{
-    unsigned long hash = 0;
-    size_t i;
-
-    for (i = 0; i < buf_len; ++i)
-        hash ^= ((unsigned long)buf[i]) << (8 * (i % sizeof(unsigned long)));
-
-    return hash;
-}
-
 static unsigned long lcid_hash(const QUIC_LCID *lcid_obj)
 {
-    return bin_hash(lcid_obj->cid.id, lcid_obj->cid.id_len);
+    SIPHASH siphash = {0, };
+    unsigned long hashval = 0;
+
+    if (!SipHash_set_hash_size(&siphash, sizeof(unsigned long)))
+        goto out;
+    if (!SipHash_Init(&siphash, (uint8_t *)lcid_obj->hash_key, 0, 0))
+        goto out;
+    SipHash_Update(&siphash, lcid_obj->cid.id, lcid_obj->cid.id_len);
+    if (!SipHash_Final(&siphash, (unsigned char *)&hashval,
+                       sizeof(unsigned long)))
+        goto out;
+out:
+    return hashval;
 }
 
 static int lcid_comp(const QUIC_LCID *a, const QUIC_LCID *b)