diff options
| author | ame <[email protected]> | 2023-11-03 19:45:15 -0500 |
|---|---|---|
| committer | ame <[email protected]> | 2023-11-03 19:45:15 -0500 |
| commit | 5cd20516567da82c60b5513c732e23db6918a4b6 (patch) | |
| tree | ec66bbcd1453fda3b7fde17ffa42b70180a149d1 /src/hash/sysvchecksum.c | |
| parent | c3d9a4d44c1c6930fac277d20c6ea48801e39a18 (diff) | |
tons of checksums (i had fun:3)
Diffstat (limited to 'src/hash/sysvchecksum.c')
| -rw-r--r-- | src/hash/sysvchecksum.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/hash/sysvchecksum.c b/src/hash/sysvchecksum.c new file mode 100644 index 0000000..a4ce824 --- /dev/null +++ b/src/hash/sysvchecksum.c @@ -0,0 +1,29 @@ +#include "../crypto.h" +#include <stdio.h> +#include <stdint.h> +#include <math.h> + +uint32_t i_sysvchecksum(uint8_t *aa, size_t len){ + uint32_t check = 0x0; + + for(int i = 0; i != len; i++){ + check += aa[i]; + } + + uint32_t r = check % (int)pow(2,16) + (check % (int)pow(2,32)) / (int)pow(2,16); + return (r % (int)pow(2,16)) + r / (int)pow(2,16); +} + +int l_sysvchecksum(lua_State* L){ + + size_t len = 0; + uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len); + + char digest[32]; + + uint32_t u = i_sysvchecksum(a, len); + sprintf(digest,"%x",u); + lua_pushstring(L, digest); + + return 1; +} |
