Skip to content

Commit d355a30

Browse files
committed
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.
1 parent c48e788 commit d355a30

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/netaddress.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,14 @@ bool CNetAddr::SetSpecial(const std::string& str)
255255
Span<const uint8_t> input_checksum{input.data() + ADDR_TORV3_SIZE, torv3::CHECKSUM_LEN};
256256
Span<const uint8_t> input_version{input.data() + ADDR_TORV3_SIZE + torv3::CHECKSUM_LEN, sizeof(torv3::VERSION)};
257257

258+
if (input_version != torv3::VERSION) {
259+
return false;
260+
}
261+
258262
uint8_t calculated_checksum[torv3::CHECKSUM_LEN];
259263
torv3::Checksum(input_pubkey, calculated_checksum);
260264

261-
if (input_checksum != calculated_checksum || input_version != torv3::VERSION) {
265+
if (input_checksum != calculated_checksum) {
262266
return false;
263267
}
264268

0 commit comments

Comments
 (0)