diff options
| author | ame <[email protected]> | 2024-04-04 10:06:53 -0500 |
|---|---|---|
| committer | ame <[email protected]> | 2024-04-04 10:06:53 -0500 |
| commit | b8b5f8c7725d7431b82cb065b2b18891c1bc3fc9 (patch) | |
| tree | 174eef159441750b71e720d6639b9b221502fd1c /src/hash/loselose.c | |
| parent | cb280d5d1816ddbe0587775def896ab9c237bc4f (diff) | |
all basic hash funcs
Diffstat (limited to 'src/hash/loselose.c')
| -rw-r--r-- | src/hash/loselose.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/hash/loselose.c b/src/hash/loselose.c index f3350f5..55d3fc6 100644 --- a/src/hash/loselose.c +++ b/src/hash/loselose.c @@ -3,18 +3,43 @@ #include <stdio.h> #include <stdint.h> +struct loselose_hash loselose_init(){ + return (struct loselose_hash){.hash = 0}; +} + +void loselose_update(uint8_t* in, size_t len, struct loselose_hash* hash){ + for(int i = 0; i != len; i++){ + hash->hash += (uint64_t)*in; + in++; + } +} + +uint64_t loselose_final(struct loselose_hash* hash){ + return hash->hash; +} + uint64_t loselose(uint8_t* in, size_t len){ - uint64_t hash = 0; + struct loselose_hash a = loselose_init(); + loselose_update(in, len, &a); + return loselose_final(&a); +} + +common_hash_init_update(loselose); - for(int i = 0; i != len; i++){ - hash += (uint64_t)*in; - in++; - } +int l_loselose_final(lua_State* L){ + lua_pushstring(L, "ud"); + lua_gettable(L, 1); - return hash; + struct loselose_hash* a = (struct loselose_hash*)lua_touserdata(L, -1); + uint64_t u = loselose_final(a); + char digest[64]; + sprintf(digest,"%08x",u); + lua_pushstring(L, digest); + return 1; } int l_loselose(lua_State* L){ + if(lua_gettop(L) == 0) return l_loselose_init(L); size_t len = 0; uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len); |
