-/* $OpenBSD: rde_attr.c,v 1.92 2014/10/08 16:15:37 deraadt Exp $ */
+/* $OpenBSD: rde_attr.c,v 1.93 2014/12/12 18:15:51 tedu Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
*/
#include <sys/types.h>
-#include <sys/hash.h>
#include <sys/queue.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <siphash.h>
#include "bgpd.h"
#include "rde.h"
u_int32_t hashmask;
} attrtable;
+SIPHASH_KEY attrtablekey;
+
#define ATTR_HASH(x) \
&attrtable.hashtbl[(x) & attrtable.hashmask]
{
u_int32_t hs, i;
+ arc4random_buf(&attrtablekey, sizeof(attrtablekey));
for (hs = 1; hs < hashsize; hs <<= 1)
;
attrtable.hashtbl = calloc(hs, sizeof(struct attr_list));
attr_alloc(u_int8_t flags, u_int8_t type, const void *data, u_int16_t len)
{
struct attr *a;
+ SIPHASH_CTX ctx;
a = calloc(1, sizeof(struct attr));
if (a == NULL)
flags &= ~ATTR_DEFMASK; /* normalize mask */
a->flags = flags;
- a->hash = hash32_buf(&flags, sizeof(flags), HASHINIT);
a->type = type;
- a->hash = hash32_buf(&type, sizeof(type), a->hash);
a->len = len;
if (len != 0) {
if ((a->data = malloc(len)) == NULL)
} else
a->data = NULL;
- a->hash = hash32_buf(&len, sizeof(len), a->hash);
- a->hash = hash32_buf(a->data, a->len, a->hash);
+ SipHash24_Init(&ctx, &attrtablekey);
+ SipHash24_Update(&ctx, &flags, sizeof(flags));
+ SipHash24_Update(&ctx, &type, sizeof(type));
+ SipHash24_Update(&ctx, &len, sizeof(len));
+ SipHash24_Update(&ctx, a->data, a->len);
+ a->hash = SipHash24_End(&ctx);
LIST_INSERT_HEAD(ATTR_HASH(a->hash), a, entry);
return (a);
struct attr_list *head;
struct attr *a;
u_int32_t hash;
+ SIPHASH_CTX ctx;
flags &= ~ATTR_DEFMASK; /* normalize mask */
- hash = hash32_buf(&flags, sizeof(flags), HASHINIT);
- hash = hash32_buf(&type, sizeof(type), hash);
- hash = hash32_buf(&len, sizeof(len), hash);
- hash = hash32_buf(data, len, hash);
+
+ SipHash24_Init(&ctx, &attrtablekey);
+ SipHash24_Update(&ctx, &flags, sizeof(flags));
+ SipHash24_Update(&ctx, &type, sizeof(type));
+ SipHash24_Update(&ctx, &len, sizeof(len));
+ SipHash24_Update(&ctx, data, len);
+ hash = SipHash24_End(&ctx);
head = ATTR_HASH(hash);
LIST_FOREACH(a, head, entry) {
u_int32_t hashmask;
} astable;
+SIPHASH_KEY astablekey;
+
#define ASPATH_HASH(x) \
&astable.hashtbl[(x) & astable.hashmask]
LIST_INIT(&astable.hashtbl[i]);
astable.hashmask = hs - 1;
+ arc4random_buf(&astablekey, sizeof(astablekey));
}
void
memcpy(aspath->data, data, len);
/* link */
- head = ASPATH_HASH(hash32_buf(aspath->data, aspath->len,
- HASHINIT));
+ head = ASPATH_HASH(SipHash24(&astablekey, aspath->data,
+ aspath->len));
LIST_INSERT_HEAD(head, aspath, entry);
}
aspath->refcnt++;
struct aspath *aspath;
u_int32_t hash;
- hash = hash32_buf(data, len, HASHINIT);
+ hash = SipHash24(&astablekey, data, len);
head = ASPATH_HASH(hash);
LIST_FOREACH(aspath, head, entry) {
-/* $OpenBSD: rde_rib.c,v 1.139 2014/10/08 16:15:37 deraadt Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.140 2014/12/12 18:15:51 tedu Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
#include <stdlib.h>
#include <string.h>
+#include <siphash.h>
#include "bgpd.h"
#include "rde.h"
struct path_table pathtable;
+SIPHASH_KEY pathtablekey;
+
/* XXX the hash should also include communities and the other attrs */
#define PATH_HASH(x) \
- &pathtable.path_hashtbl[hash32_buf((x)->data, (x)->len, HASHINIT) & \
+ &pathtable.path_hashtbl[SipHash24(&pathtablekey, (x)->data, (x)->len) & \
pathtable.path_hashmask]
void
LIST_INIT(&pathtable.path_hashtbl[i]);
pathtable.path_hashmask = hs - 1;
+ arc4random_buf(&pathtablekey, sizeof(pathtablekey));
}
void