diff options
author | 2003-12-10 07:21:00 +0000 | |
---|---|---|
committer | 2003-12-10 07:21:00 +0000 | |
commit | 7c5afa882790e29a8b82eabf056b59ce8ed5015c (patch) | |
tree | 048af0dae58a907b53e0f14207c8c4441120c20a /sys/netinet6 | |
parent | - fix a few exit cases that would exit with no log (diff) | |
download | wireguard-openbsd-7c5afa882790e29a8b82eabf056b59ce8ed5015c.tar.xz wireguard-openbsd-7c5afa882790e29a8b82eabf056b59ce8ed5015c.zip |
correct non-repetitive ID code, based on comments from niels provos.
- seed2 is necessary, but use it as "seed2 + x" not "seed2 ^ x".
- skipping number is not needed, so disable it for 16bit generator (makes
the repetition period to 30000)
Diffstat (limited to 'sys/netinet6')
-rw-r--r-- | sys/netinet6/ip6_id.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/sys/netinet6/ip6_id.c b/sys/netinet6/ip6_id.c index e509a6364a6..5b6151a246a 100644 --- a/sys/netinet6/ip6_id.c +++ b/sys/netinet6/ip6_id.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_id.c,v 1.1 2003/10/01 21:41:05 itojun Exp $ */ +/* $OpenBSD: ip6_id.c,v 1.2 2003/12/10 07:21:01 itojun Exp $ */ /* $NetBSD: ip6_id.c,v 1.7 2003/09/13 21:32:59 itojun Exp $ */ /* $KAME: ip6_id.c,v 1.8 2003/09/06 13:41:06 itojun Exp $ */ @@ -223,15 +223,12 @@ static u_int32_t randomid(struct randomtab *p) { int i, n; - u_int32_t tmp; if (p->ru_counter >= p->ru_max || time.tv_sec > p->ru_reseed) initid(p); - tmp = arc4random(); - /* Skip a random number of ids */ - n = tmp & 0x3; tmp = tmp >> 2; + n = arc4random() & 0x3; if (p->ru_counter + n >= p->ru_max) initid(p); @@ -242,7 +239,7 @@ randomid(struct randomtab *p) p->ru_counter += i; - return (p->ru_seed ^ pmod(p->ru_g, p->ru_seed2 ^ p->ru_x, p->ru_n)) | + return (p->ru_seed ^ pmod(p->ru_g, p->ru_seed2 + p->ru_x, p->ru_n)) | p->ru_msb; } |