| 189 | static constexpr size_t TOTAL_LEN = ADDR_TORV3_SIZE + CHECKSUM_LEN + sizeof(VERSION); |
| 190 | |
| 191 | static 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 |
no test coverage detected