aboutsummaryrefslogtreecommitdiff
path: root/src/hash/sdbm.c
diff options
context:
space:
mode:
authorame <[email protected]>2023-11-17 10:10:47 -0600
committerame <[email protected]>2023-11-17 10:10:47 -0600
commit7eb07ccdca178abffe5ffccf686b4f818db3601d (patch)
tree4b265eb0e9f7b1666be24cac3b9d27a6b343fbb4 /src/hash/sdbm.c
parent829ad28a66fae082f8d2e8df27164b52592a5ee6 (diff)
tons of hashes bleh
Diffstat (limited to 'src/hash/sdbm.c')
-rw-r--r--src/hash/sdbm.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/hash/sdbm.c b/src/hash/sdbm.c
new file mode 100644
index 0000000..bec251e
--- /dev/null
+++ b/src/hash/sdbm.c
@@ -0,0 +1,28 @@
+#include "../i_util.h"
+#include "../crypto.h"
+#include <stdio.h>
+#include <stdint.h>
+
+uint64_t sdbm(uint8_t* in, size_t len){
+ uint64_t hash = 0;
+
+ for(int i = 0; i != len; i++){
+ hash = (uint64_t)*in + (hash << 6) + (hash << 16) - hash;
+ in++;
+ }
+
+ return hash;
+}
+
+int l_sdbm(lua_State* L){
+ size_t len = 0;
+ uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len);
+
+ char digest[64];
+
+ uint64_t u = sdbm(a, len);
+ sprintf(digest,"%016lx",u);
+ lua_pushstring(L, digest);
+ return 1;
+}
+