Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_accdb_fd_accdb_base_h 2 : #define HEADER_fd_src_flamenco_accdb_fd_accdb_base_h 3 : 4 : #include "../../util/bits/fd_bits.h" 5 : 6 : struct fd_accdb_private; 7 : typedef struct fd_accdb_private fd_accdb_t; 8 : 9 : struct fd_accdb_fork_id { ushort val; }; 10 : typedef struct fd_accdb_fork_id fd_accdb_fork_id_t; 11 : 12 : #if FD_HAS_INT128 13 : 14 : static inline ulong 15 420911424 : fd_xxh3_mul128_fold64( ulong lhs, ulong rhs ) { 16 420911424 : uint128 product = (uint128)lhs * (uint128)rhs; 17 420911424 : return (ulong)product ^ (ulong)( product>>64 ); 18 420911424 : } 19 : 20 : static inline ulong 21 : fd_xxh3_mix16b( ulong i0, ulong i1, 22 : ulong s0, ulong s1, 23 420911424 : ulong seed ) { 24 420911424 : return fd_xxh3_mul128_fold64( i0 ^ (s0 + seed), i1 ^ (s1 - seed) ); 25 420911424 : } 26 : 27 : FD_FN_PURE static inline ulong 28 : fd_accdb_hash( uchar const key[ 32 ], 29 210455712 : ulong seed ) { 30 210455712 : ulong k0 = FD_LOAD( ulong, key+ 0 ); 31 210455712 : ulong k1 = FD_LOAD( ulong, key+ 8 ); 32 210455712 : ulong k2 = FD_LOAD( ulong, key+16 ); 33 210455712 : ulong k3 = FD_LOAD( ulong, key+24 ); 34 210455712 : ulong acc = 32 * 0x9E3779B185EBCA87ULL; 35 210455712 : acc += fd_xxh3_mix16b( k0, k1, 0xbe4ba423396cfeb8UL, 0x1cad21f72c81017cUL, seed ); 36 210455712 : acc += fd_xxh3_mix16b( k2, k3, 0xdb979083e96dd4deUL, 0x1f67b3b7a4a44072UL, seed ); 37 210455712 : acc = acc ^ (acc >> 37); 38 210455712 : acc *= 0x165667919E3779F9ULL; 39 210455712 : acc = acc ^ (acc >> 32); 40 210455712 : return acc; 41 210455712 : } 42 : 43 : #else 44 : 45 : /* If the target does not support xxHash3, fallback to the 'old' key 46 : hash function. 47 : 48 : FIXME This version is vulnerable to HashDoS */ 49 : 50 : FD_FN_PURE static inline ulong 51 : fd_accdb_hash( uchar const key[ 32 ], 52 : ulong seed ) { 53 : /* tons of ILP */ 54 : return (fd_ulong_hash( seed ^ (1UL<<0) ^ FD_LOAD( ulong, key+ 0 ) ) ^ 55 : fd_ulong_hash( seed ^ (1UL<<1) ^ FD_LOAD( ulong, key+ 8 ) ) ) ^ 56 : (fd_ulong_hash( seed ^ (1UL<<2) ^ FD_LOAD( ulong, key+16 ) ) ^ 57 : fd_ulong_hash( seed ^ (1UL<<3) ^ FD_LOAD( ulong, key+24 ) ) ); 58 : } 59 : 60 : #endif /* FD_HAS_INT128 */ 61 : 62 : #endif /* HEADER_fd_src_flamenco_accdb_fd_accdb_base_h */