From 91e026d7ec090f7a1e4d6e745b6c76402844d097 Mon Sep 17 00:00:00 2001 From: Krystie Date: Thu, 2 Apr 2026 14:16:02 -0700 Subject: [PATCH] Fix Tor v3 onion address checksum: SHA-256 -> SHA3-256 The Tor v3 spec requires SHA3-256 (FIPS-202) for the .onion address checksum computation, but ToStringIP() was using SHA-256 (double-hash). This caused every reconstructed .onion address to have incorrect suffix characters, making all outbound Tor connections fail with SOCKS5 'general failure' - the entire network had 0 Tor peers despite working Tor instances. Fix: Replace Hash() call with OpenSSL EVP_sha3_256() which is available in OpenSSL 3.0+ and produces the correct FIPS-202 SHA3-256 checksum. Tested: All 5 onion seed nodes now connect successfully. --- src/clientversion.h | 2 +- src/netbase.cpp | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/clientversion.h b/src/clientversion.h index 86df846..6570526 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -8,7 +8,7 @@ // These need to be macros, as version.cpp's and triangles-qt.rc's voodoo requires it #define CLIENT_VERSION_MAJOR 5 #define CLIENT_VERSION_MINOR 5 -#define CLIENT_VERSION_REVISION 0 +#define CLIENT_VERSION_REVISION 1 #define CLIENT_VERSION_BUILD 0 // Converts the parameter X to a string after macro replacement on X has been performed. diff --git a/src/netbase.cpp b/src/netbase.cpp index 706a9c6..b4cb950 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -6,6 +6,7 @@ #include "netbase.h" #include "util.h" #include "sync.h" +#include #ifndef WIN32 #include @@ -860,15 +861,19 @@ std::string CNetAddr::ToStringIP() const unsigned char addr35[35]; memcpy(addr35, tor_v3_pubkey, 32); // Compute checksum: SHA3-256(".onion checksum" || pubkey || version)[:2] - // For now use a simplified checksum from the stored data unsigned char checksumInput[15 + 32 + 1]; memcpy(checksumInput, ".onion checksum", 15); memcpy(checksumInput + 15, tor_v3_pubkey, 32); checksumInput[47] = 0x03; // version - // SHA-256 as fallback (SHA3-256 via tor_crypto_compat.h for full impl) - uint256 hash = Hash(checksumInput, checksumInput + 48); - addr35[32] = ((unsigned char*)&hash)[0]; - addr35[33] = ((unsigned char*)&hash)[1]; + unsigned char sha3hash[32]; + unsigned int sha3len = 0; + EVP_MD_CTX *mdctx = EVP_MD_CTX_new(); + EVP_DigestInit_ex(mdctx, EVP_sha3_256(), NULL); + EVP_DigestUpdate(mdctx, checksumInput, 48); + EVP_DigestFinal_ex(mdctx, sha3hash, &sha3len); + EVP_MD_CTX_free(mdctx); + addr35[32] = sha3hash[0]; + addr35[33] = sha3hash[1]; addr35[34] = 0x03; // version return EncodeBase32(addr35, 35) + ".onion"; }