diff options
| author | ame <[email protected]> | 2023-11-17 10:10:47 -0600 |
|---|---|---|
| committer | ame <[email protected]> | 2023-11-17 10:10:47 -0600 |
| commit | 7eb07ccdca178abffe5ffccf686b4f818db3601d (patch) | |
| tree | 4b265eb0e9f7b1666be24cac3b9d27a6b343fbb4 /src/hash/pjw.c | |
| parent | 829ad28a66fae082f8d2e8df27164b52592a5ee6 (diff) | |
tons of hashes bleh
Diffstat (limited to 'src/hash/pjw.c')
| -rw-r--r-- | src/hash/pjw.c | 31 |
1 files changed, 31 insertions, 0 deletions
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 <stdio.h> +#include <stdint.h> + +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; +} |
