diff options
Diffstat (limited to 'src/lib/hash.c')
| -rw-r--r-- | src/lib/hash.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/lib/hash.c b/src/lib/hash.c index 7ffa5bc1..903474df 100644 --- a/src/lib/hash.c +++ b/src/lib/hash.c @@ -74,8 +74,10 @@ uint16_t hash_len(enum hash_algo algo) { if (algo == HASH_CRC8) return CRC8_HASH_LEN; + if (algo == HASH_CRC16) return CRC16_HASH_LEN; + if (algo == HASH_CRC64) return CRC64_HASH_LEN; #ifdef HAVE_LIBGCRYPT @@ -90,6 +92,10 @@ void mem_hash(enum hash_algo algo, const uint8_t * buf, size_t len) { +#ifndef HAVE_LIBGCRYPT + struct sha3_ctx sha3_ctx; + struct md5_ctx md5_ctx; +#endif if (algo == HASH_CRC8) { uint8_t crc = 0; @@ -97,6 +103,7 @@ void mem_hash(enum hash_algo algo, *(uint8_t *) dst = crc; return; } + if (algo == HASH_CRC16) { uint16_t crc = 0; @@ -104,6 +111,7 @@ void mem_hash(enum hash_algo algo, *(uint16_t *) dst = htobe16(crc); return; } + if (algo == HASH_CRC64) { uint64_t crc = 0; @@ -114,9 +122,6 @@ void mem_hash(enum hash_algo algo, #ifdef HAVE_LIBGCRYPT gcry_md_hash_buffer(gcry_algo_tbl[algo], dst, buf, len); #else - struct sha3_ctx sha3_ctx; - struct md5_ctx md5_ctx; - switch (algo) { case HASH_CRC32: memset(dst, 0, CRC32_HASH_LEN); @@ -161,3 +166,14 @@ void str_hash(enum hash_algo algo, { return mem_hash(algo, dst, (const uint8_t *) str, strlen(str)); } + +uint64_t hash_mix64(uint64_t key) +{ + key ^= key >> 33; + key *= 0xff51afd7ed558ccdULL; + key ^= key >> 33; + key *= 0xc4ceb9fe1a85ec53ULL; + key ^= key >> 33; + + return key; +} |
