svn commit: r327295 - head/sys/netinet6

Pedro F. Giffuni pfg at FreeBSD.org
Thu Dec 28 20:26:52 UTC 2017


Author: pfg
Date: Thu Dec 28 20:26:51 2017
New Revision: 327295
URL: https://svnweb.freebsd.org/changeset/base/327295

Log:
  Start syncing changes from OpenBSD's ip6_id.c instead of ip_id.c.
  
  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)
  
  Obtained from:	OpenBSD (CVS rev. 1.2)
  MFC after:	1 week

Modified:
  head/sys/netinet6/ip6_id.c

Modified: head/sys/netinet6/ip6_id.c
==============================================================================
--- head/sys/netinet6/ip6_id.c	Thu Dec 28 20:10:10 2017	(r327294)
+++ head/sys/netinet6/ip6_id.c	Thu Dec 28 20:26:51 2017	(r327295)
@@ -65,7 +65,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $OpenBSD: ip_id.c,v 1.6 2002/03/15 18:19:52 millert Exp $
+ * $OpenBSD: ip6_id.c,v 1.2 2003/12/10 07:21:01 itojun Exp $
  */
 
 #include <sys/cdefs.h>
@@ -232,15 +232,12 @@ static u_int32_t
 randomid(struct randomtab *p)
 {
 	int i, n;
-	u_int32_t tmp;
 
 	if (p->ru_counter >= p->ru_max || time_uptime > 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);
 
@@ -251,7 +248,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;
 }
 


More information about the svn-src-all mailing list