diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-02-16 09:54:13 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-02-16 09:54:13 -0500 |
commit | bd71e0a0c8ccf684c40201f08c456596eac60887 (patch) | |
tree | 5b33cdf7ee6ad33cd95499cff7e4e53b56c1559f /src/common/address.c | |
parent | c67adddacb56f90d77786820f29ca2b4b9f91cae (diff) | |
parent | 2bcd264a28e2d6bec1e806e779bf82435c9c7505 (diff) | |
download | tor-bd71e0a0c8ccf684c40201f08c456596eac60887.tar.gz tor-bd71e0a0c8ccf684c40201f08c456596eac60887.zip |
Merge branch 'maint-0.3.1' into maint-0.3.2
Diffstat (limited to 'src/common/address.c')
-rw-r--r-- | src/common/address.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/common/address.c b/src/common/address.c index dbe129be59..c683e90aac 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -1185,6 +1185,9 @@ tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2, } } +/** Input for siphash, to produce some output for an unspec value. */ +static const uint32_t unspec_hash_input[] = { 0x4e4df09f, 0x92985342 }; + /** Return a hash code based on the address addr. DOCDOC extra */ uint64_t tor_addr_hash(const tor_addr_t *addr) @@ -1193,7 +1196,7 @@ tor_addr_hash(const tor_addr_t *addr) case AF_INET: return siphash24g(&addr->addr.in_addr.s_addr, 4); case AF_UNSPEC: - return 0x4e4d5342; + return siphash24g(unspec_hash_input, sizeof(unspec_hash_input)); case AF_INET6: return siphash24g(&addr->addr.in6_addr.s6_addr, 16); /* LCOV_EXCL_START */ @@ -1204,6 +1207,28 @@ tor_addr_hash(const tor_addr_t *addr) } } +/** As tor_addr_hash, but use a particular siphash key. */ +uint64_t +tor_addr_keyed_hash(const struct sipkey *key, const tor_addr_t *addr) +{ + /* This is duplicate code with tor_addr_hash, since this function needs to + * be backportable all the way to 0.2.9. */ + + switch (tor_addr_family(addr)) { + case AF_INET: + return siphash24(&addr->addr.in_addr.s_addr, 4, key); + case AF_UNSPEC: + return siphash24(unspec_hash_input, sizeof(unspec_hash_input), key); + case AF_INET6: + return siphash24(&addr->addr.in6_addr.s6_addr, 16, key); + default: + /* LCOV_EXCL_START */ + tor_fragile_assert(); + return 0; + /* LCOV_EXCL_END */ + } +} + /** Return a newly allocated string with a representation of <b>addr</b>. */ char * tor_addr_to_str_dup(const tor_addr_t *addr) |