diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-02-07 17:38:16 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-02-12 11:32:10 -0500 |
commit | 0e97c8e23e2572c14dd0f4f4fbfca77ee8a48be2 (patch) | |
tree | a9d0e1914c9bf8e136486ca02658029273e86be5 /src/or/policies.c | |
parent | f05820531a1e4bc5935609900f0067b2643f0529 (diff) | |
download | tor-0e97c8e23e2572c14dd0f4f4fbfca77ee8a48be2.tar.gz tor-0e97c8e23e2572c14dd0f4f4fbfca77ee8a48be2.zip |
Siphash-2-4 is now our hash in nearly all cases.
I've made an exception for cases where I'm sure that users can't
influence the inputs. This is likely to cause a slowdown somewhere,
but it's safer to siphash everything and *then* look for cases to
optimize.
This patch doesn't actually get us any _benefit_ from siphash yet,
since we don't really randomize the key at any point.
Diffstat (limited to 'src/or/policies.c')
-rw-r--r-- | src/or/policies.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/or/policies.c b/src/or/policies.c index be4da55061..05377ec205 100644 --- a/src/or/policies.c +++ b/src/or/policies.c @@ -597,21 +597,25 @@ policy_eq(policy_map_ent_t *a, policy_map_ent_t *b) /** Return a hashcode for <b>ent</b> */ static unsigned int -policy_hash(policy_map_ent_t *ent) +policy_hash(const policy_map_ent_t *ent) { - addr_policy_t *a = ent->policy; - unsigned int r; - if (a->is_private) - r = 0x1234abcd; - else - r = tor_addr_hash(&a->addr); - r += a->prt_min << 8; - r += a->prt_max << 16; - r += a->maskbits; - if (a->policy_type == ADDR_POLICY_REJECT) - r ^= 0xffffffff; + const addr_policy_t *a = ent->policy; + addr_policy_t aa; + memset(&aa, 0, sizeof(aa)); + + aa.prt_min = a->prt_min; + aa.prt_max = a->prt_max; + aa.maskbits = a->maskbits; + aa.policy_type = a->policy_type; + aa.is_private = a->is_private; + + if (a->is_private) { + aa.is_private = 1; + } else { + tor_addr_copy_tight(&aa.addr, &a->addr); + } - return r; + return (unsigned) siphash24g(&aa, sizeof(aa)); } HT_PROTOTYPE(policy_map, policy_map_ent_t, node, policy_hash, |