From 98c6b1b0407fa639e40a80428b8fb2cff61b96dd Mon Sep 17 00:00:00 2001 From: amelia squires Date: Tue, 30 Sep 2025 18:00:29 -0500 Subject: another hash that i didnt really make (afaik) --- src/crypto.h | 2 -- src/hash/fasthash.c | 82 ----------------------------------------------------- src/hash/fasthash.h | 8 ------ 3 files changed, 92 deletions(-) delete mode 100644 src/hash/fasthash.c delete mode 100644 src/hash/fasthash.h (limited to 'src') diff --git a/src/crypto.h b/src/crypto.h index 78c8d4f..9561008 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -12,7 +12,6 @@ #include "hash/xor.h" #include "hash/buzhash.h" #include "hash/djb2.h" -#include "hash/fasthash.h" #include "hash/fnv.h" #include "hash/jenkins.h" #include "hash/loselose.h" @@ -112,7 +111,6 @@ static const luaL_Reg crypto_function_list [] = { {"setpearson",l_setpearson}, {"fletcher8",l_fletcher8}, {"fletcher16",l_fletcher16}, {"fletcher32",l_fletcher32}, {"setbuzhash",l_setbuzhash}, - {"fasthash32", l_fasthash32}, {"fasthash64", l_fasthash64}, {"loselose", l_loselose}, {"murmur1_32", l_murmur1_32}, {"murmur2_32", l_murmur2_32}, diff --git a/src/hash/fasthash.c b/src/hash/fasthash.c deleted file mode 100644 index 12ec3be..0000000 --- a/src/hash/fasthash.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "../crypto.h" -#include -#include -//almost entirely taken from https://github.com/ztanml/fast-hash/blob/master/fasthash.c - -#define mix(h) ({ \ - (h) ^= (h) >> 23; \ - (h) *= 0x2127599bf4325c37ULL; \ - (h) ^= (h) >> 47; }) - -uint64_t fasthash64(uint8_t* in, size_t len, uint64_t seed){ - uint64_t m = 0x880355f21e6d1965ULL; - uint64_t hash = seed ^ (len * m); - uint64_t* data = (uint64_t*)in; - uint64_t v; - for(;len >= 8; len-=8){ - v=*data++; - hash^=mix(v); - hash*=m; - - in+=4; - } - - uint8_t* data2 = (uint8_t*)data; - v=0; - - switch (len & 7) { - case 7: - v ^= (uint64_t)data2[6] << 48; - case 6: - v ^= (uint64_t)data2[5] << 40; - case 5: - v ^= (uint64_t)data2[4] << 32; - case 4: - v ^= (uint64_t)data2[3] << 24; - case 3: - v ^= (uint64_t)data2[2] << 16; - case 2: - v ^= (uint64_t)data2[1] << 8; - case 1: - v ^= (uint64_t)data2[0]; - hash ^= mix(v); - hash *= m; - } - - return mix(hash); -} - -uint32_t fasthash32(uint8_t *buf, size_t len, uint32_t seed){ - uint64_t hash = fasthash64(buf, len, seed); - return hash - (hash >> 32); -} - -int l_fasthash64(lua_State* L){ - size_t len = 0; - uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len); - int argv = lua_gettop(L); - uint64_t seed = 0; - if(argv > 1) seed = luaL_checkinteger(L, 2); - - char digest[64]; - - uint64_t u = fasthash64(a, len, seed); - sprintf(digest,"%016"PRIx64,u); - lua_pushstring(L, digest); - return 1; -} - -int l_fasthash32(lua_State* L){ - size_t len = 0; - uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len); - int argv = lua_gettop(L); - uint32_t seed = 0; - if(argv > 1) seed = luaL_checkinteger(L, 2); - - char digest[32]; - - uint32_t u = fasthash32(a, len, seed); - sprintf(digest,"%04"PRIx32,u); - lua_pushstring(L, digest); - return 1; -} diff --git a/src/hash/fasthash.h b/src/hash/fasthash.h deleted file mode 100644 index 0a950e7..0000000 --- a/src/hash/fasthash.h +++ /dev/null @@ -1,8 +0,0 @@ -#include "../lua.h" -#include - -uint64_t fasthash64(uint8_t* in, size_t len, uint64_t seed); -uint32_t fasthash32(uint8_t *buf, size_t len, uint32_t seed); - -int l_fasthash32(lua_State*); -int l_fasthash64(lua_State*); -- cgit v1.2.3