aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-02-15 15:59:10 -0500
committerNick Mathewson <nickm@torproject.org>2014-02-15 15:59:10 -0500
commit35423d397f9d4f7810e538b608ded47c33311026 (patch)
tree61acc3efaad82b92b1752568a03a296738bf03fb /src/or
parentb3a69074933492080629d45b1c890606aa2bd08a (diff)
parent1ad6dd0dbee7c757ef5f2f2d38b846ab7d991fb2 (diff)
downloadtor-35423d397f9d4f7810e538b608ded47c33311026.tar
tor-35423d397f9d4f7810e538b608ded47c33311026.tar.gz
Merge branch 'bug4900_siphash_v2'
Diffstat (limited to 'src/or')
-rw-r--r--src/or/channel.c7
-rw-r--r--src/or/dns.c2
-rw-r--r--src/or/fp_pair.c13
-rw-r--r--src/or/geoip.c8
-rw-r--r--src/or/main.c7
-rw-r--r--src/or/microdesc.c7
-rw-r--r--src/or/nodelist.c9
-rw-r--r--src/or/policies.c30
8 files changed, 35 insertions, 48 deletions
diff --git a/src/or/channel.c b/src/or/channel.c
index a345bab20..9f6887588 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -95,12 +95,7 @@ typedef struct channel_idmap_entry_s {
static INLINE unsigned
channel_idmap_hash(const channel_idmap_entry_t *ent)
{
- const unsigned *a = (const unsigned *)ent->digest;
-#if SIZEOF_INT == 4
- return a[0] ^ a[1] ^ a[2] ^ a[3] ^ a[4];
-#elif SIZEOF_INT == 8
- return a[0] ^ a[1];
-#endif
+ return (unsigned) siphash24g(ent->digest, DIGEST_LEN);
}
static INLINE int
diff --git a/src/or/dns.c b/src/or/dns.c
index a1fe0de1d..a88a46eb7 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -239,7 +239,7 @@ cached_resolves_eq(cached_resolve_t *a, cached_resolve_t *b)
static INLINE unsigned int
cached_resolve_hash(cached_resolve_t *a)
{
- return ht_string_hash(a->address);
+ return (unsigned) siphash24g((const uint8_t*)a->address, strlen(a->address));
}
HT_PROTOTYPE(cache_map, cached_resolve_t, node, cached_resolve_hash,
diff --git a/src/or/fp_pair.c b/src/or/fp_pair.c
index 4d8a835c8..55e4c89a4 100644
--- a/src/or/fp_pair.c
+++ b/src/or/fp_pair.c
@@ -32,17 +32,8 @@ fp_pair_map_entries_eq(const fp_pair_map_entry_t *a,
static INLINE unsigned int
fp_pair_map_entry_hash(const fp_pair_map_entry_t *a)
{
- const uint32_t *p;
- unsigned int hash;
-
- p = (const uint32_t *)(a->key.first);
- /* Hashes are 20 bytes long, so 5 times uint32_t */
- hash = p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4];
- /* Now XOR in the second fingerprint */
- p = (const uint32_t *)(a->key.second);
- hash ^= p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4];
-
- return hash;
+ tor_assert(sizeof(a->key) == DIGEST_LEN*2);
+ return (unsigned) siphash24g(&a->key, DIGEST_LEN*2);
}
/*
diff --git a/src/or/geoip.c b/src/or/geoip.c
index dc4730c81..6088f5d19 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -486,10 +486,12 @@ static HT_HEAD(clientmap, clientmap_entry_t) client_history =
static INLINE unsigned
clientmap_entry_hash(const clientmap_entry_t *a)
{
- unsigned h = tor_addr_hash(&a->addr);
+ unsigned h = (unsigned) tor_addr_hash(&a->addr);
+
if (a->transport_name)
- h += ht_string_hash(a->transport_name);
- return ht_improve_hash(h);
+ h += (unsigned) siphash24g(a->transport_name, strlen(a->transport_name));
+
+ return h;
}
/** Hashtable helper: compare two clientmap_entry_t values for equality. */
static INLINE int
diff --git a/src/or/main.c b/src/or/main.c
index 959c41b64..a191d1c61 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -2319,6 +2319,13 @@ tor_init(int argc, char *argv[])
/* Have the log set up with our application name. */
tor_snprintf(progname, sizeof(progname), "Tor %s", get_version());
log_set_application_name(progname);
+
+ /* Set up the crypto nice and early */
+ if (crypto_early_init() < 0) {
+ log_err(LD_GENERAL, "Unable to initialize the crypto subsystem!");
+ return 1;
+ }
+
/* Initialize the history structures. */
rep_hist_init();
/* Initialize the service cache. */
diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index 11249910c..8052ca998 100644
--- a/src/or/microdesc.c
+++ b/src/or/microdesc.c
@@ -45,12 +45,7 @@ struct microdesc_cache_t {
static INLINE unsigned int
microdesc_hash_(microdesc_t *md)
{
- unsigned *d = (unsigned*)md->digest;
-#if SIZEOF_INT == 4
- return d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6] ^ d[7];
-#else
- return d[0] ^ d[1] ^ d[2] ^ d[3];
-#endif
+ return (unsigned) siphash24g(md->digest, sizeof(md->digest));
}
/** Helper: compares <b>a</b> and </b> for equality for hash-table purposes. */
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index 402fb2e96..03fa836d4 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -43,14 +43,7 @@ typedef struct nodelist_t {
static INLINE unsigned int
node_id_hash(const node_t *node)
{
-#if SIZEOF_INT == 4
- const uint32_t *p = (const uint32_t*)node->identity;
- return p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4];
-#elif SIZEOF_INT == 8
- const uint64_t *p = (const uint32_t*)node->identity;
- const uint32_t *p32 = (const uint32_t*)node->identity;
- return p[0] ^ p[1] ^ p32[4];
-#endif
+ return (unsigned) siphash24g(node->identity, DIGEST_LEN);
}
static INLINE unsigned int
diff --git a/src/or/policies.c b/src/or/policies.c
index be4da5506..05377ec20 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,