From 8d85e6501a9aa49da4a4a910207566e85bd5fd4d Mon Sep 17 00:00:00 2001 From: ame Date: Mon, 15 Apr 2024 08:23:28 -0500 Subject: msys2 + fix logging --- src/hash/loselose.c | 100 ++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) (limited to 'src/hash/loselose.c') diff --git a/src/hash/loselose.c b/src/hash/loselose.c index bfdc017..9724e0c 100644 --- a/src/hash/loselose.c +++ b/src/hash/loselose.c @@ -1,50 +1,50 @@ -#include "../util.h" -#include "../crypto.h" -#include -#include - -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){ - struct loselose_hash a = loselose_init(); - loselose_update(in, len, &a); - return loselose_final(&a); -} - -common_hash_clone(loselose); -common_hash_init_update(loselose); - -int l_loselose_final(lua_State* L){ - struct loselose_hash* a = (struct loselose_hash*)lua_touserdata(L, 1); - uint64_t u = loselose_final(a); - char digest[64]; - sprintf(digest,"%08lx",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); - - char digest[64]; - - uint64_t u = loselose(a, len); - sprintf(digest,"%08lx",u); - lua_pushstring(L, digest); - return 1; -} +#include "../util.h" +#include "../crypto.h" +#include +#include + +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){ + struct loselose_hash a = loselose_init(); + loselose_update(in, len, &a); + return loselose_final(&a); +} + +common_hash_clone(loselose); +common_hash_init_update(loselose); + +int l_loselose_final(lua_State* L){ + struct loselose_hash* a = (struct loselose_hash*)lua_touserdata(L, 1); + uint64_t u = loselose_final(a); + char digest[64]; + sprintf(digest,"%08lx",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); + + char digest[64]; + + uint64_t u = loselose(a, len); + sprintf(digest,"%08lx",u); + lua_pushstring(L, digest); + return 1; +} -- cgit v1.2.3