aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/hashtables.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-11-29 23:28:14 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-11-29 23:29:22 +0100
commit824be84dd3aaa72a0d01241439f41733a4a1b742 (patch)
tree6c6eaab7c56dbdc301f1d06f4432751025fa4831 /src/hashtables.c
parentversion: bump snapshot (diff)
downloadwireguard-monolithic-historical-824be84dd3aaa72a0d01241439f41733a4a1b742.tar.xz
wireguard-monolithic-historical-824be84dd3aaa72a0d01241439f41733a4a1b742.zip
hashtable: use random number each time
Otherwise timing information might leak information about prior index entries. We also switch back to an explicit uint64_t because siphash needs something at least that size. (This partially reverts 1550e9ba597946c88e3e7e3e8dcf33c13dd76e5b. Willy's suggestion was wrong.)
Diffstat (limited to 'src/hashtables.c')
-rw-r--r--src/hashtables.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/hashtables.c b/src/hashtables.c
index f0d8769..f30f6cf 100644
--- a/src/hashtables.c
+++ b/src/hashtables.c
@@ -68,7 +68,7 @@ void index_hashtable_init(struct index_hashtable *table)
__le32 index_hashtable_insert(struct index_hashtable *table, struct index_hashtable_entry *entry)
{
struct index_hashtable_entry *existing_entry;
- unsigned long rand = get_random_long();
+ uint64_t rand;
spin_lock(&table->lock);
hlist_del_init_rcu(&entry->index_hash);
@@ -78,7 +78,7 @@ __le32 index_hashtable_insert(struct index_hashtable *table, struct index_hashta
search_unused_slot:
/* First we try to find an unused slot, randomly, while unlocked. */
- ++rand;
+ rand = get_random_long();
entry->index = (__force __le32)siphash24((uint8_t *)&rand, sizeof(rand), table->key);
hlist_for_each_entry_rcu(existing_entry, index_bucket(table, entry->index), index_hash) {
if (existing_entry->index == entry->index)