From 0c003aecb135b7e419c53c231fc2c25c8f8dfccf Mon Sep 17 00:00:00 2001 From: stilic Date: Wed, 6 May 2026 15:16:27 +0200 Subject: fix 32bit compilation --- src/net.c | 2 +- src/thread.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/net.c b/src/net.c index 98cdf52..5208377 100644 --- a/src/net.c +++ b/src/net.c @@ -197,7 +197,7 @@ int i_ws_write(lua_State* L){ lua_gettable(L, 1); struct net_data* data = lua_touserdata(L, -1); - uint64_t clen; + size_t clen; const char* content = luaL_tolstring(L, 2, &clen); str* send_data = str_init(""); diff --git a/src/thread.c b/src/thread.c index 1e58aef..cd2eb5f 100644 --- a/src/thread.c +++ b/src/thread.c @@ -453,7 +453,8 @@ int _buffer_func_wrapper(lua_State* L){ } int l_buffer_index(lua_State* L){ - uint64_t len, hash; + size_t len; + uint64_t hash; struct thread_buffer *buffer = lua_touserdata(L, 1); const char* str = luaL_tolstring(L, 2, &len); -- cgit v1.2.3 From a832c8e3c1abdd4bb267cb118ae85e94c8ce1c27 Mon Sep 17 00:00:00 2001 From: stilic Date: Wed, 6 May 2026 15:21:24 +0200 Subject: fix? --- src/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.h b/src/config.h index f09af91..8fbd460 100644 --- a/src/config.h +++ b/src/config.h @@ -25,7 +25,7 @@ struct config { //location of table in lua registery int* c_table_idx; //length used for c_string or c_function - size_t* len; + uint64_t* len; } value; }; -- cgit v1.2.3 From 4de77da5c950bf4359429f95380d1bc5a108f3b9 Mon Sep 17 00:00:00 2001 From: stilic Date: Wed, 6 May 2026 15:24:42 +0200 Subject: fix for real this time --- src/net.c | 4 ++-- src/net/websocket.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net.c b/src/net.c index 5208377..66c2f65 100644 --- a/src/net.c +++ b/src/net.c @@ -250,7 +250,7 @@ int i_ws_close(lua_State* L){ #define BUFFER_LEN 16384 int l_wss(lua_State* L){ - uint64_t len = 0; + size_t len; char* request_url = (char*)lua_tolstring(L, 1, &len); struct url awa = parse_url(request_url, len); if(awa.proto != NULL && strcmp(awa.proto->c, "ws") == 0){ @@ -437,7 +437,7 @@ ssize_t _request_write(struct request_state* state, const void* buffer, size_t c int _request(lua_State* L, struct request_state* state){ int params = lua_gettop(L); - uint64_t ilen = 0; + size_t ilen; char* request_url = (char*)lua_tolstring(L, 1, &ilen); struct url awa = parse_url(request_url, ilen); if(awa.proto != NULL && strcmp(awa.proto->c, "http") == 0){ diff --git a/src/net/websocket.c b/src/net/websocket.c index af37f32..06283f6 100644 --- a/src/net/websocket.c +++ b/src/net/websocket.c @@ -158,7 +158,7 @@ int l_ws_write(lua_State* L){ frame.mask = 0; frame.opcode = 0b0001; - uint64_t len; + size_t len; const char* s = lua_tolstring(L, 2, &len); str* f = str_init(""); -- cgit v1.2.3 From 3ad4984a82e2ef521a738b31f9af3db3ffcc5667 Mon Sep 17 00:00:00 2001 From: stilic Date: Wed, 6 May 2026 15:28:50 +0200 Subject: hope it builds fine --- src/net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net.c b/src/net.c index 66c2f65..5082c26 100644 --- a/src/net.c +++ b/src/net.c @@ -414,7 +414,7 @@ int l_request(lua_State* L){ ssize_t _request_read(struct request_state* state, void* buffer, size_t count){ if(state->secure){ - uint64_t len; + size_t len; if(SSL_read_ex(state->ssl, buffer, count, &len) == 0) return 0; return len; @@ -425,7 +425,7 @@ ssize_t _request_read(struct request_state* state, void* buffer, size_t count){ ssize_t _request_write(struct request_state* state, const void* buffer, size_t count){ if(state->secure){ - uint64_t len; + size_t len; if(SSL_write_ex(state->ssl, buffer, count, &len) == 0) return 0; return len; -- cgit v1.2.3 From 0b12634ac6613675abecbdcadc9374e87590cdb7 Mon Sep 17 00:00:00 2001 From: stilic Date: Wed, 6 May 2026 15:31:10 +0200 Subject: Update config.h --- src/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.h b/src/config.h index 8fbd460..f09af91 100644 --- a/src/config.h +++ b/src/config.h @@ -25,7 +25,7 @@ struct config { //location of table in lua registery int* c_table_idx; //length used for c_string or c_function - uint64_t* len; + size_t* len; } value; }; -- cgit v1.2.3 From 054ea901178f56acb599b274c14c8584e4bc1d50 Mon Sep 17 00:00:00 2001 From: stilic Date: Wed, 6 May 2026 15:32:20 +0200 Subject: Update net.h --- src/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net.h b/src/net.h index 75c2515..79f3c38 100644 --- a/src/net.h +++ b/src/net.h @@ -48,7 +48,7 @@ static const luaL_Reg net_function_list [] = { }; extern char* _mimetypes; -extern uint64_t _mimetypes_len; +extern size_t _mimetypes_len; static struct config net_config[] = { {.name = "mimetypes", .type = c_string, .value = {.c_string = &_mimetypes, .len = &_mimetypes_len}}, -- cgit v1.2.3 From 5cf623fde7f1382c5328b0ddc37c18b31721cb9c Mon Sep 17 00:00:00 2001 From: stilic Date: Wed, 6 May 2026 15:34:41 +0200 Subject: Update util.c --- src/net/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net/util.c b/src/net/util.c index cc478e4..d770f5e 100644 --- a/src/net/util.c +++ b/src/net/util.c @@ -348,7 +348,7 @@ parray_t* route_match(parray_t* paths, char* request, larray_t** _params){ map_t* mime_type = NULL; char* _mimetypes = "/etc/mime.types"; -uint64_t _mimetypes_len = 15; +size_t _mimetypes_len = 15; void parse_mimetypes(){ if(_mimetypes == NULL || _mimetypes_len == 0) return; -- cgit v1.2.3 From 91ddebee4f1d889fd2da9af6cc754026ddd2ede4 Mon Sep 17 00:00:00 2001 From: stilic Date: Wed, 6 May 2026 15:36:14 +0200 Subject: Update lua.c --- src/net/lua.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/net/lua.c b/src/net/lua.c index 50d050a..ffa10c4 100644 --- a/src/net/lua.c +++ b/src/net/lua.c @@ -279,7 +279,8 @@ int l_connection_upgrade(lua_State* L){ int req_idx = 2; lua_getfield(L, req_idx, "upgrade"); - uint64_t hash, len; + uint64_t hash; + size_t len; uint8_t* s = (uint8_t*)luaL_checklstring(L, -1, &len); hash = fnv_1(s, len, v_1); -- cgit v1.2.3 From ddc618791543a4acf804151b3757faf4f6c9b7b2 Mon Sep 17 00:00:00 2001 From: stilic Date: Wed, 6 May 2026 15:46:03 +0200 Subject: Update sha2-256.c --- src/hash/sha2-256.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/hash/sha2-256.c b/src/hash/sha2-256.c index 06841c5..1b8acb3 100644 --- a/src/hash/sha2-256.c +++ b/src/hash/sha2-256.c @@ -22,15 +22,6 @@ const uint64_t k[80] = {0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b 0x113f9804bef90dae, 0x1b710b35131c471b, 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817}; -void endian_swap128(__uint128_t *x){ - uint8_t *y = (uint8_t*)x; - for (size_t low = 0, high = sizeof(__uint128_t) - 1; high > low; low++, high--){ - y[low] ^= y[high]; - y[high] ^= y[low]; - y[low] ^= y[high]; - } -} - void endian_swap64(uint64_t *x){ uint8_t *y = (uint8_t*)x; for (size_t low = 0, high = sizeof(uint64_t) - 1; high > low; low++, high--){ @@ -168,9 +159,17 @@ void _sha512_t_final(struct sha512_hash* hash){ memset(hash->buffer, 0, bs); } - __uint128_t bigL = hash->total*8; - endian_swap128(&bigL); - memcpy(&hash->buffer[128 - sizeof(__uint128_t)], &bigL, sizeof(__uint128_t)); + uint64_t total = hash->total; + uint64_t bit_len_high = total >> 61; + uint64_t bit_len_low = total << 3; + + uint64_t be_high = bit_len_high; + uint64_t be_low = bit_len_low; + endian_swap64(&be_high); + endian_swap64(&be_low); + + memcpy(&hash->buffer[128 - 16], &be_high, 8); + memcpy(&hash->buffer[128 - 8], &be_low, 8); sha512_round(hash); } -- cgit v1.2.3