aboutsummaryrefslogtreecommitdiff
path: root/src/hash/jenkins.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash/jenkins.c')
-rw-r--r--src/hash/jenkins.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/hash/jenkins.c b/src/hash/jenkins.c
new file mode 100644
index 0000000..b11de8e
--- /dev/null
+++ b/src/hash/jenkins.c
@@ -0,0 +1,31 @@
+#include "../i_util.h"
+#include "../crypto.h"
+#include <stdio.h>
+#include <stdint.h>
+
+uint32_t jenkins_oaat(uint8_t* in, size_t len){
+ uint32_t hash = 0;
+
+ for(int i = 0; i != len;){
+ hash += in[i++];
+ hash += hash << 10;
+ hash ^= hash >> 6;
+ }
+ hash += hash << 3;
+ hash ^= hash >> 11;
+ hash += hash << 15;
+
+ return hash;
+}
+
+int l_oaat(lua_State* L){
+ size_t len = 0;
+ uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len);
+
+ char digest[64];
+
+ uint32_t u = jenkins_oaat(a, len);
+ sprintf(digest,"%04x",u);
+ lua_pushstring(L, digest);
+ return 1;
+}