mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
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.
This commit is contained in:
+11
-10
@@ -7,6 +7,7 @@
|
||||
#define TOR_CONTAINER_H
|
||||
|
||||
#include "util.h"
|
||||
#include "siphash.h"
|
||||
|
||||
/** A resizeable list of pointers, with associated helpful functionality.
|
||||
*
|
||||
@@ -610,11 +611,11 @@ typedef struct {
|
||||
static INLINE void
|
||||
digestset_add(digestset_t *set, const char *digest)
|
||||
{
|
||||
const uint32_t *p = (const uint32_t *)digest;
|
||||
const uint32_t d1 = p[0] + (p[1]>>16);
|
||||
const uint32_t d2 = p[1] + (p[2]>>16);
|
||||
const uint32_t d3 = p[2] + (p[3]>>16);
|
||||
const uint32_t d4 = p[3] + (p[0]>>16);
|
||||
const uint64_t x = siphash24g(digest, 20);
|
||||
const uint32_t d1 = (uint32_t) x;
|
||||
const uint32_t d2 = (uint32_t)( (x>>16) + x);
|
||||
const uint32_t d3 = (uint32_t)( (x>>32) + x);
|
||||
const uint32_t d4 = (uint32_t)( (x>>48) + x);
|
||||
bitarray_set(set->ba, BIT(d1));
|
||||
bitarray_set(set->ba, BIT(d2));
|
||||
bitarray_set(set->ba, BIT(d3));
|
||||
@@ -626,11 +627,11 @@ digestset_add(digestset_t *set, const char *digest)
|
||||
static INLINE int
|
||||
digestset_contains(const digestset_t *set, const char *digest)
|
||||
{
|
||||
const uint32_t *p = (const uint32_t *)digest;
|
||||
const uint32_t d1 = p[0] + (p[1]>>16);
|
||||
const uint32_t d2 = p[1] + (p[2]>>16);
|
||||
const uint32_t d3 = p[2] + (p[3]>>16);
|
||||
const uint32_t d4 = p[3] + (p[0]>>16);
|
||||
const uint64_t x = siphash24g(digest, 20);
|
||||
const uint32_t d1 = (uint32_t) x;
|
||||
const uint32_t d2 = (uint32_t)( (x>>16) + x);
|
||||
const uint32_t d3 = (uint32_t)( (x>>32) + x);
|
||||
const uint32_t d4 = (uint32_t)( (x>>48) + x);
|
||||
return bitarray_is_set(set->ba, BIT(d1)) &&
|
||||
bitarray_is_set(set->ba, BIT(d2)) &&
|
||||
bitarray_is_set(set->ba, BIT(d3)) &&
|
||||
|
||||
Reference in New Issue
Block a user