Skip to content

Commit 7c0d412

Browse files
committed
Merge #20405: p2p: avoid calculating onion address checksum when version is not 3
d355a30 Break circuit earlier (lontivero) Pull request description: Currently when parsing an onion v3 address the pubic key checksum is calculated in order to compare it with the received address checksum. However this step is not necessary if the address version byte is not 3, in which case the method can return with false immediately. ACKs for top commit: jonatack: ACK d355a30 practicalswift: ACK d355a30 -- patch looks correct hebasto: ACK d355a30, I have reviewed the code and it looks OK, I agree it can be merged. sipa: utACK d355a30 Tree-SHA512: 9e4506793b7f4a62ce8edc41a260a8c125ae81ed2f90cd850eb2a9214d323c446edc7586c7b0590dcbf3aed5be534718b77bb19c45b48f8f52553d32a3663a65
2 parents c48e788 + d355a30 commit 7c0d412

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)