From: tedu Date: Thu, 18 Dec 2014 19:27:04 +0000 (+0000) Subject: simple to use siphash here. ok deraadt X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5bc82be202f2b88fef7e6235e5586c1e83420dd3;p=openbsd simple to use siphash here. ok deraadt --- diff --git a/usr.sbin/ospf6d/lsupdate.c b/usr.sbin/ospf6d/lsupdate.c index 60e355bd8ec..198309cf032 100644 --- a/usr.sbin/ospf6d/lsupdate.c +++ b/usr.sbin/ospf6d/lsupdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsupdate.c,v 1.10 2013/03/25 14:29:35 markus Exp $ */ +/* $OpenBSD: lsupdate.c,v 1.11 2014/12/18 19:27:04 tedu Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -18,7 +18,6 @@ */ #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include +#include #include "ospf6.h" #include "ospf6d.h" @@ -542,6 +542,8 @@ struct lsa_cache { u_int32_t hashmask; } lsacache; +SIPHASH_KEY lsacachekey; + struct lsa_ref *lsa_cache_look(struct lsa_hdr *); void @@ -557,10 +559,17 @@ lsa_cache_init(u_int32_t hashsize) for (i = 0; i < hs; i++) LIST_INIT(&lsacache.hashtbl[i]); + arc4random_buf(&lsacachekey, sizeof(lsacachekey)); lsacache.hashmask = hs - 1; } +uint32_t +lsa_hash_hdr(const struct lsa_hdr *hdr) +{ + return SipHash24(&lsacachekey, hdr, sizeof(*hdr)); +} + struct lsa_ref * lsa_cache_add(void *data, u_int16_t len) { @@ -587,8 +596,7 @@ lsa_cache_add(void *data, u_int16_t len) ref->len = len; ref->refcnt = 1; - head = &lsacache.hashtbl[hash32_buf(&ref->hdr, sizeof(ref->hdr), - HASHINIT) & lsacache.hashmask]; + head = &lsacache.hashtbl[lsa_hash_hdr(&ref->hdr) & lsacache.hashmask]; LIST_INSERT_HEAD(head, ref, entry); return (ref); } @@ -626,8 +634,7 @@ lsa_cache_look(struct lsa_hdr *lsa_hdr) struct lsa_cache_head *head; struct lsa_ref *ref; - head = &lsacache.hashtbl[hash32_buf(lsa_hdr, sizeof(*lsa_hdr), - HASHINIT) & lsacache.hashmask]; + head = &lsacache.hashtbl[lsa_hash_hdr(lsa_hdr) & lsacache.hashmask]; LIST_FOREACH(ref, head, entry) { if (memcmp(&ref->hdr, lsa_hdr, sizeof(*lsa_hdr)) == 0)