From b224d2f0b9b344a08c6c508d61f15bdf205464f8 Mon Sep 17 00:00:00 2001 From: ame Date: Fri, 17 Nov 2023 10:10:47 -0600 Subject: tons of hashes bleh --- src/hash/pjw.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/hash/pjw.c (limited to 'src/hash/pjw.c') diff --git a/src/hash/pjw.c b/src/hash/pjw.c new file mode 100644 index 0000000..8494ba2 --- /dev/null +++ b/src/hash/pjw.c @@ -0,0 +1,31 @@ +#include "../i_util.h" +#include "../crypto.h" + +#include +#include + +uint32_t pjw(uint8_t* in, size_t len){ + uint32_t hash = 0; + uint32_t high; + + for(int i = 0; i != len; i++){ + hash = (hash << 4) + *in++; + if((high = (hash & 0xf0000000))) + hash ^= high >> 24; + hash &= ~high; + } + + return hash; +} + +int l_pjw(lua_State* L){ + size_t len = 0; + uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len); + + char digest[32]; + + uint32_t u = pjw(a, len); + sprintf(digest,"%08x",u); + lua_pushstring(L, digest); + return 1; +} -- cgit v1.2.3