aboutsummaryrefslogtreecommitdiff
path: root/src/hash/xor.c
diff options
context:
space:
mode:
authorame <[email protected]>2024-04-15 08:23:28 -0500
committerame <[email protected]>2024-04-15 08:23:28 -0500
commit8d85e6501a9aa49da4a4a910207566e85bd5fd4d (patch)
treee864d5bb71d06320ede5a5f15158938dcc4c1912 /src/hash/xor.c
parent3b9343ae3f25684e1dfa3bd8f123d61dcfd81be7 (diff)
msys2 + fix logging
Diffstat (limited to 'src/hash/xor.c')
-rw-r--r--src/hash/xor.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/src/hash/xor.c b/src/hash/xor.c
index 205408f..fab17d7 100644
--- a/src/hash/xor.c
+++ b/src/hash/xor.c
@@ -1,48 +1,48 @@
-#include "../crypto.h"
-#include <stdio.h>
-#include <stdint.h>
-
-struct xor8_hash xor8_init(){
- return (struct xor8_hash){.a = 0};
-}
-
-void xor8_update(uint8_t* aa, size_t len, struct xor8_hash* hash){
- for(int i = 0; i != len; i++)
- hash->a += aa[i] & 0xff;
-}
-
-uint8_t xor8_final(struct xor8_hash* hash){
- return ((hash->a ^ 0xff) + 1) & 0xff;
-}
-
-uint8_t xor8(uint8_t* aa, size_t len){
- struct xor8_hash a = xor8_init();
- xor8_update(aa, len, &a);
- return xor8_final(&a);
-}
-
-common_hash_clone(xor8)
-common_hash_init_update(xor8);
-
-int l_xor8_final(lua_State* L){
- struct xor8_hash* a = (struct xor8_hash*)lua_touserdata(L, 1);
- uint8_t u = xor8_final(a);
- char digest[8];
- sprintf(digest,"%02x",u);
- lua_pushstring(L, digest);
- return 1;
-}
-
-int l_xor8(lua_State* L){
- if(lua_gettop(L) == 0) return l_xor8_init(L);
- size_t len = 0;
- uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len);
-
- char digest[8];
-
- uint8_t u = xor8(a, len);
- sprintf(digest,"%02x",u);
- lua_pushstring(L, digest);
-
- return 1;
-}
+#include "../crypto.h"
+#include <stdio.h>
+#include <stdint.h>
+
+struct xor8_hash xor8_init(){
+ return (struct xor8_hash){.a = 0};
+}
+
+void xor8_update(uint8_t* aa, size_t len, struct xor8_hash* hash){
+ for(int i = 0; i != len; i++)
+ hash->a += aa[i] & 0xff;
+}
+
+uint8_t xor8_final(struct xor8_hash* hash){
+ return ((hash->a ^ 0xff) + 1) & 0xff;
+}
+
+uint8_t xor8(uint8_t* aa, size_t len){
+ struct xor8_hash a = xor8_init();
+ xor8_update(aa, len, &a);
+ return xor8_final(&a);
+}
+
+common_hash_clone(xor8)
+common_hash_init_update(xor8);
+
+int l_xor8_final(lua_State* L){
+ struct xor8_hash* a = (struct xor8_hash*)lua_touserdata(L, 1);
+ uint8_t u = xor8_final(a);
+ char digest[8];
+ sprintf(digest,"%02x",u);
+ lua_pushstring(L, digest);
+ return 1;
+}
+
+int l_xor8(lua_State* L){
+ if(lua_gettop(L) == 0) return l_xor8_init(L);
+ size_t len = 0;
+ uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len);
+
+ char digest[8];
+
+ uint8_t u = xor8(a, len);
+ sprintf(digest,"%02x",u);
+ lua_pushstring(L, digest);
+
+ return 1;
+}