aboutsummaryrefslogtreecommitdiff
path: root/src/hash/djb2.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
commitb224d2f0b9b344a08c6c508d61f15bdf205464f8 (patch)
tree4b265eb0e9f7b1666be24cac3b9d27a6b343fbb4 /src/hash/djb2.c
parent4fc59207afdf442cd769992339b7fdea0ff2a2b8 (diff)
tons of hashes bleh
Diffstat (limited to 'src/hash/djb2.c')
-rw-r--r--src/hash/djb2.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/hash/djb2.c b/src/hash/djb2.c
new file mode 100644
index 0000000..8949ca8
--- /dev/null
+++ b/src/hash/djb2.c
@@ -0,0 +1,27 @@
+#include "../i_util.h"
+#include "../crypto.h"
+#include <stdio.h>
+#include <stdint.h>
+
+uint64_t djb2(uint8_t* in, size_t len){
+ uint64_t hash = 5381;
+
+ for(int i = 0; i != len; i++){
+ hash = ((hash << 5) + hash) + (uint64_t)*in;
+ in++;
+ }
+
+ return hash;
+}
+
+int l_djb2(lua_State* L){
+ size_t len = 0;
+ uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len);
+
+ char digest[64];
+
+ uint64_t u = djb2(a, len);
+ sprintf(digest,"%08lx",u);
+ lua_pushstring(L, digest);
+ return 1;
+}