diff --git a/.gitignore b/.gitignore index 2fb5e13..fb03ab7 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,4 @@ utun.conf # MSVC temp files cl build_win.log +wintun.dll diff --git a/AGENTS.md b/AGENTS.md index 521bf3e..a77c31b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -194,14 +194,6 @@ sc_decrypt(&ctx, ciphertext, ciphertext_len, plaintext, &plaintext_len); 2. **Undefined references:** Ensure source files are listed in Makefile.am 3. **Link errors:** Check function declarations match definitions -### Testing Crypto -```bash -cd tests/ -./test_etcp_crypto # Should show all tests passing -cd tests/ -./working_crypto_test # Standalone crypto test -``` - ## πŸ“¦ Dependencies ### Build Dependencies @@ -233,7 +225,7 @@ Crypto: Fixed CCM nonce size to 13 bytes, all crypto tests passing 1. Add new source file to `src/Makefile.am` under `utun_SOURCES` 2. Add test file to `tests/Makefile.am` under `check_PROGRAMS` 3. Use existing patterns from similar modules -4. Run `make check` after changes +4. Run `make check` after changes (win: build.bat and run_tests.bat) 5. Commit with descriptive message in appropriate language --- @@ -295,4 +287,5 @@ Crypto: Fixed CCM nonce size to 13 bytes, all crypto tests passing стоп utun: sudo /home/vnc1/proj/utun3/utun_stop1.sh Π»ΠΎΠ³ΠΈ - utun.log + *Last updated: 2026-02-13 - c_util fully functional with toc/description/show/edit commands* \ No newline at end of file diff --git a/lib/platform_compat.h b/lib/platform_compat.h index 6c006b1..754d4c9 100644 --- a/lib/platform_compat.h +++ b/lib/platform_compat.h @@ -45,8 +45,10 @@ #define _SSIZE_T_DEFINED #endif - // gettimeofday for Windows - provide our own implementation - static inline int gettimeofday(struct timeval *tv, void *tz) { + // gettimeofday for Windows - provide our own implementation if not already defined + #ifndef _GETTIMEOFDAY_DEFINED + #define _GETTIMEOFDAY_DEFINED + static inline int utun_gettimeofday(struct timeval *tv, void *tz) { FILETIME ft; unsigned __int64 tmpres = 0; @@ -67,6 +69,7 @@ return 0; } + #endif // _GETTIMEOFDAY_DEFINED // Pipe creation for Windows static inline int platform_pipe(int pipefd[2]) { diff --git a/lib/socket_compat.c b/lib/socket_compat.c index 491536a..f084c34 100644 --- a/lib/socket_compat.c +++ b/lib/socket_compat.c @@ -8,20 +8,33 @@ #ifdef _WIN32 // ==================== Windows Implementation ==================== +static int wsa_init_count = 0; + int socket_platform_init(void) { - WSADATA wsaData; - int result = WSAStartup(MAKEWORD(2, 2), &wsaData); - if (result != 0) { - DEBUG_ERROR(DEBUG_CATEGORY_SOCKET, "WSAStartup failed: %d", result); - return -1; + if (wsa_init_count == 0) { + WSADATA wsaData; + int result = WSAStartup(MAKEWORD(2, 2), &wsaData); + if (result != 0) { + DEBUG_ERROR(DEBUG_CATEGORY_SOCKET, "WSAStartup failed: %d", result); + return -1; + } + DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock 2.2 initialized"); } - DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock 2.2 initialized"); + wsa_init_count++; + DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock init count: %d", wsa_init_count); return 0; } void socket_platform_cleanup(void) { - WSACleanup(); - DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock cleanup completed"); + if (wsa_init_count > 0) { + wsa_init_count--; + if (wsa_init_count == 0) { + WSACleanup(); + DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock cleanup completed"); + } else { + DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock init count after cleanup: %d", wsa_init_count); + } + } } int socket_set_nonblocking(socket_t sock) { diff --git a/src/secure_channel.c b/src/secure_channel.c index 4168e9f..767b1c6 100644 --- a/src/secure_channel.c +++ b/src/secure_channel.c @@ -574,6 +574,9 @@ sc_status_t sc_init_local_keys(struct SC_MYKEYS *mykeys, const char *public_key, curve = uECC_secp256r1(); } + /* Set RNG function for TinyCrypt - must be done before any ECC operations */ + uECC_set_rng(sc_rng); + DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "sc_init_local_keys: public_key len=%zu, private_key len=%zu", strlen(public_key), strlen(private_key)); diff --git a/src/utun.conf b/src/utun.conf deleted file mode 100644 index 0dd321f..0000000 --- a/src/utun.conf +++ /dev/null @@ -1,42 +0,0 @@ -[global] -tun_ip=10.0.0.1 -mtu=1500 # MTU for all connections (0 = use default 1500) -control_ip=127.0.0.1 -control_port=12345 -net_debug=0 - -my_node_id=61be9d4cd3c60c2d -my_private_key=1313912e5d34768983b0e06530a48c77816d228a5b5605e1ab3dc443d107a3dc -my_public_key= - - -[routing] -route_subnet=10.0.0.0/24 -route_subnet=10.22.0.0/16 -route_subnet=10.23.0.0/16 -my_subnet=10.23.5.0/24 -my_subnet=10.23.6.0/24 - -# ΠΌΠΎΠΈ адрСса ΠΈ ΠΊΠ°Π½Π°Π»Ρ‹ -[server: lo0_test] -addr=127.0.0.1:1330 -#so_mark=100 -#netif=eth0 -type=nat # public / nat / private - -[server: lan1] -addr=192.168.29.117:1333 -so_mark=100 -netif=eth0 -type=public # public / nat / private - -[client: client_test1] - -# Π»ΠΈΠ½ΠΊΠΈ -link=lo0_test:192.168.0.20:1234 -#link=wired1_fast:1.2.3.4:1234 -link=lan1:192.168.0.20:1234 -#link=wireless_bkp:1.2.3.4:1234 - -keepalive=1 -peer_public_key=deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbee \ No newline at end of file diff --git a/tests/test_routing_mesh.c b/tests/test_routing_mesh.c index b44bda3..8581fd9 100644 --- a/tests/test_routing_mesh.c +++ b/tests/test_routing_mesh.c @@ -4,7 +4,12 @@ #include #include #include -#include +#ifdef _WIN32 + #include + #include +#else + #include +#endif #include "test_utils.h" #include "../lib/platform_compat.h" #include "../src/etcp.h"