aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlontivero <lucasontivero@gmail.com>2020-11-16 15:54:24 -0300
committerlontivero <lucasontivero@gmail.com>2020-11-16 15:54:24 -0300
commitd355a302d9b7e4aaac04edaa0671ced3b3eaef45 (patch)
tree764dafb081b7c352f6d41272657d9f1afb31dad0
parentc48e788246fcced78cb4eb1d4bd09cb41a9ff09b (diff)
Break circuit earlier
There is no need to calculate the full checksum for an Tor v3 onion address if the version byte is not the expected one.
-rw-r--r--src/netaddress.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/netaddress.cpp b/src/netaddress.cpp
index c0193fa2e9..35e9161f58 100644
--- a/src/netaddress.cpp
+++ b/src/netaddress.cpp
@@ -255,10 +255,14 @@ bool CNetAddr::SetSpecial(const std::string& str)
Span<const uint8_t> input_checksum{input.data() + ADDR_TORV3_SIZE, torv3::CHECKSUM_LEN};
Span<const uint8_t> input_version{input.data() + ADDR_TORV3_SIZE + torv3::CHECKSUM_LEN, sizeof(torv3::VERSION)};
+ if (input_version != torv3::VERSION) {
+ return false;
+ }
+
uint8_t calculated_checksum[torv3::CHECKSUM_LEN];
torv3::Checksum(input_pubkey, calculated_checksum);
- if (input_checksum != calculated_checksum || input_version != torv3::VERSION) {
+ if (input_checksum != calculated_checksum) {
return false;
}