diff --git a/include/socks/util.h b/include/socks/util.h index e48114c..c94303e 100644 --- a/include/socks/util.h +++ b/include/socks/util.h @@ -9,6 +9,7 @@ extern "C" { #endif +extern uint64_t hash_string(const char *s); extern void data_size_to_string(size_t value, char *out, size_t outsz); static inline bool power_of_2(size_t x) { return (x > 0 && (x & (x - 1)) == 0); } static inline unsigned long long div64_pow2(unsigned long long x, unsigned long long y) diff --git a/util/hash.c b/util/hash.c new file mode 100644 index 0000000..7f8a2c6 --- /dev/null +++ b/util/hash.c @@ -0,0 +1,14 @@ +#include + +uint64_t hash_string(const char *s) +{ + uint64_t h = 0xcbf29ce484222325; + + while (*s) { + h ^= *(unsigned char *)s; + h *= 0x100000001b3; + s++; + } + + return h; +}