/src/openssl/include/internal/hashfunc.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #ifndef OPENSSL_HASHFUNC_H |
11 | | #define OPENSSL_HASHFUNC_H |
12 | | |
13 | | #include <openssl/e_os2.h> |
14 | | #include <stddef.h> |
15 | | #include <limits.h> |
16 | | |
17 | | /** |
18 | | * Generalized fnv1a 64 bit hash function |
19 | | */ |
20 | | ossl_unused uint64_t ossl_fnv1a_hash(uint8_t *key, size_t len); |
21 | | |
22 | | /* |
23 | | * Mix a 64-bit value so that every bit of the result depends on every bit |
24 | | * of the input (the splitmix64 finaliser). An LHASH bucket is the hash |
25 | | * modulo a power of two, so a hash that is a raw integer or pointer must be |
26 | | * mixed first: a pointer's low bits are its allocation alignment, and |
27 | | * objects of one size from the allocator sit at a fixed stride, so without |
28 | | * mixing they share a handful of buckets and the chains grow with the |
29 | | * number of objects. Likewise an integer whose low bits are a type tag. |
30 | | */ |
31 | | static ossl_unused ossl_inline uint64_t ossl_hash_mix64(uint64_t x) |
32 | 0 | { |
33 | 0 | x ^= x >> 30; |
34 | 0 | x *= 0xbf58476d1ce4e5b9ULL; |
35 | 0 | x ^= x >> 27; |
36 | 0 | x *= 0x94d049bb133111ebULL; |
37 | 0 | x ^= x >> 31; |
38 | 0 | return x; |
39 | 0 | } Unexecuted instantiation: quic_impl.c:ossl_hash_mix64 Unexecuted instantiation: quic_srtm.c:ossl_hash_mix64 Unexecuted instantiation: d1_lib.c:ossl_hash_mix64 Unexecuted instantiation: quic_lcidm.c:ossl_hash_mix64 Unexecuted instantiation: hashfunc.c:ossl_hash_mix64 Unexecuted instantiation: hashtable.c:ossl_hash_mix64 |
40 | | |
41 | | /* A 64-bit value, mixed, as an LHASH hash value. */ |
42 | | static ossl_unused ossl_inline unsigned long ossl_lh_hash_u64(uint64_t x) |
43 | 0 | { |
44 | 0 | x = ossl_hash_mix64(x); |
45 | 0 | #if ULONG_MAX > 0xFFFFFFFFUL |
46 | 0 | return (unsigned long)x; |
47 | | #else |
48 | | return (unsigned long)(x ^ (x >> 32)); |
49 | | #endif |
50 | 0 | } Unexecuted instantiation: quic_impl.c:ossl_lh_hash_u64 Unexecuted instantiation: quic_srtm.c:ossl_lh_hash_u64 Unexecuted instantiation: d1_lib.c:ossl_lh_hash_u64 Unexecuted instantiation: quic_lcidm.c:ossl_lh_hash_u64 Unexecuted instantiation: hashfunc.c:ossl_lh_hash_u64 Unexecuted instantiation: hashtable.c:ossl_lh_hash_u64 |
51 | | |
52 | | /* A pointer's identity, mixed, as an LHASH hash value. */ |
53 | | static ossl_unused ossl_inline unsigned long ossl_lh_hash_ptr(const void *p) |
54 | 0 | { |
55 | 0 | return ossl_lh_hash_u64((uint64_t)(uintptr_t)p); |
56 | 0 | } Unexecuted instantiation: quic_impl.c:ossl_lh_hash_ptr Unexecuted instantiation: quic_srtm.c:ossl_lh_hash_ptr Unexecuted instantiation: d1_lib.c:ossl_lh_hash_ptr Unexecuted instantiation: quic_lcidm.c:ossl_lh_hash_ptr Unexecuted instantiation: hashfunc.c:ossl_lh_hash_ptr Unexecuted instantiation: hashtable.c:ossl_lh_hash_ptr |
57 | | |
58 | | #endif |