diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2014-12-22 03:38:02 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2014-12-22 03:38:02 +0000 |
commit | d98892b19f775c4dd3ad9557727627fb148b2fd0 (patch) | |
tree | 3f0b596e7f63f9780be0a3b69c24e1c3d2967ba5 | |
parent | 6d52f0c2197328e902a6e5fc2a409b01e05542b8 (diff) |
convert to using siphash
-rw-r--r-- | sys/net/if_bridge.c | 38 | ||||
-rw-r--r-- | sys/net/if_bridge.h | 4 |
2 files changed, 8 insertions, 34 deletions
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index 4ef6e211c56..76484158c15 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bridge.c,v 1.230 2014/12/19 17:14:39 tedu Exp $ */ +/* $OpenBSD: if_bridge.c,v 1.231 2014/12/22 03:38:01 tedu Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -46,6 +46,8 @@ #include <sys/errno.h> #include <sys/kernel.h> +#include <crypto/siphash.h> + #include <net/if.h> #include <net/if_types.h> #include <net/if_llc.h> @@ -197,7 +199,7 @@ bridge_clone_create(struct if_clone *ifc, int unit) TAILQ_INIT(&sc->sc_spanlist); for (i = 0; i < BRIDGE_RTABLE_SIZE; i++) LIST_INIT(&sc->sc_rts[i]); - sc->sc_hashkey = arc4random(); + arc4random_buf(&sc->sc_hashkey, sizeof(sc->sc_hashkey)); ifp = &sc->sc_if; snprintf(ifp->if_xname, sizeof ifp->if_xname, "%s%d", ifc->ifc_name, unit); @@ -1805,39 +1807,11 @@ fail: return (NULL); } -/* - * The following hash function is adapted from 'Hash Functions' by Bob Jenkins - * ("Algorithm Alley", Dr. Dobbs Journal, September 1997). - * "You may use this code any way you wish, private, educational, or - * commercial. It's free." - */ -#define mix(a,b,c) \ - do { \ - a -= b; a -= c; a ^= (c >> 13); \ - b -= c; b -= a; b ^= (a << 8); \ - c -= a; c -= b; c ^= (b >> 13); \ - a -= b; a -= c; a ^= (c >> 12); \ - b -= c; b -= a; b ^= (a << 16); \ - c -= a; c -= b; c ^= (b >> 5); \ - a -= b; a -= c; a ^= (c >> 3); \ - b -= c; b -= a; b ^= (a << 10); \ - c -= a; c -= b; c ^= (b >> 15); \ - } while (0) - u_int32_t bridge_hash(struct bridge_softc *sc, struct ether_addr *addr) { - u_int32_t a = 0x9e3779b9, b = 0x9e3779b9, c = sc->sc_hashkey; - - b += addr->ether_addr_octet[5] << 8; - b += addr->ether_addr_octet[4]; - a += addr->ether_addr_octet[3] << 24; - a += addr->ether_addr_octet[2] << 16; - a += addr->ether_addr_octet[1] << 8; - a += addr->ether_addr_octet[0]; - - mix(a, b, c); - return (c & BRIDGE_RTABLE_MASK); + return SipHash24((SIPHASH_KEY *)sc->sc_hashkey, addr, ETHER_ADDR_LEN) & + BRIDGE_RTABLE_MASK; } void diff --git a/sys/net/if_bridge.h b/sys/net/if_bridge.h index 6583dabf945..eef94a78fc9 100644 --- a/sys/net/if_bridge.h +++ b/sys/net/if_bridge.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bridge.h,v 1.39 2013/10/13 12:09:54 reyk Exp $ */ +/* $OpenBSD: if_bridge.h,v 1.40 2014/12/22 03:38:01 tedu Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -425,7 +425,7 @@ struct bridge_softc { u_int32_t sc_brtmax; /* max # addresses */ u_int32_t sc_brtcnt; /* current # addrs */ int sc_brttimeout; /* timeout ticks */ - u_int32_t sc_hashkey; /* hash key */ + u_int64_t sc_hashkey[2]; /* siphash key */ struct timeout sc_brtimeout; /* timeout state */ struct bstp_state *sc_stp; /* stp state */ TAILQ_HEAD(, bridge_iflist) sc_iflist; /* interface list */ |