MCPcopy Create free account
hub / github.com/ElementsProject/elements / Checksum

Function Checksum

src/netaddress.cpp:191–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189static constexpr size_t TOTAL_LEN = ADDR_TORV3_SIZE + CHECKSUM_LEN + sizeof(VERSION);
190
191static void Checksum(Span<const uint8_t> addr_pubkey, uint8_t (&checksum)[CHECKSUM_LEN])
192{
193 // TORv3 CHECKSUM = H(".onion checksum" | PUBKEY | VERSION)[:2]
194 static const unsigned char prefix[] = ".onion checksum";
195 static constexpr size_t prefix_len = 15;
196
197 SHA3_256 hasher;
198
199 hasher.Write(Span{prefix}.first(prefix_len));
200 hasher.Write(addr_pubkey);
201 hasher.Write(VERSION);
202
203 uint8_t checksum_full[SHA3_256::OUTPUT_SIZE];
204
205 hasher.Finalize(checksum_full);
206
207 memcpy(checksum, checksum_full, sizeof(checksum));
208}
209
210}; // namespace torv3
211

Callers 2

SetTorMethod · 0.85
OnionToStringFunction · 0.85

Calls 2

WriteMethod · 0.45
FinalizeMethod · 0.45

Tested by

no test coverage detected