diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-02-09 12:08:12 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-02-09 12:08:12 -0500 |
commit | abdf2a6f7f400bf7769b701c79b51e51f1cc9e55 (patch) | |
tree | 98a3ca09c057afef4f4ac1e2152bc9c33669319a /src/common/address.c | |
parent | d9826b0a30f42754dc5764ce02c7b0271d996c92 (diff) | |
parent | 1a4fc9cddf27595db6f5da981a557f768fa32f66 (diff) | |
download | tor-abdf2a6f7f400bf7769b701c79b51e51f1cc9e55.tar.gz tor-abdf2a6f7f400bf7769b701c79b51e51f1cc9e55.zip |
Merge remote-tracking branch 'dgoulet/ticket24902_029_05'
Diffstat (limited to 'src/common/address.c')
-rw-r--r-- | src/common/address.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/address.c b/src/common/address.c index 7ff81206e5..1946a5f503 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -1204,6 +1204,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 0x4e4d5342; + 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) |