summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordjm <djm@openbsd.org>2008-06-04 00:50:23 +0000
committerdjm <djm@openbsd.org>2008-06-04 00:50:23 +0000
commiteef9a7c1a01adee2fb47f5dbb00afe811f6cb352 (patch)
tree11bbef6aaa122e0f0c74457e143edb937396c6d2
parentfix some spacing issues; (diff)
downloadwireguard-openbsd-eef9a7c1a01adee2fb47f5dbb00afe811f6cb352.tar.xz
wireguard-openbsd-eef9a7c1a01adee2fb47f5dbb00afe811f6cb352.zip
fix math screwup that reintroduced a bias for upper_bounds in range
(2^30,2^31). Nothing in the tree yet requests random numbers bounded by this range. report jakob!deraadt; ok deraadt@
-rw-r--r--lib/libc/crypt/arc4random.c4
-rw-r--r--sys/dev/rnd.c4
-rw-r--r--usr.sbin/bind/lib/isc/random.c2
3 files changed, 5 insertions, 5 deletions
diff --git a/lib/libc/crypt/arc4random.c b/lib/libc/crypt/arc4random.c
index bbe42bd204d..22b8d1f3c1b 100644
--- a/lib/libc/crypt/arc4random.c
+++ b/lib/libc/crypt/arc4random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random.c,v 1.18 2008/03/16 19:47:43 otto Exp $ */
+/* $OpenBSD: arc4random.c,v 1.19 2008/06/04 00:50:23 djm Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -231,7 +231,7 @@ arc4random_uniform(u_int32_t upper_bound)
min = 1 + ~upper_bound; /* 2**32 - upper_bound */
else {
/* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
- min = ((0xffffffff - (upper_bound << 2)) + 1) % upper_bound;
+ min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
}
#endif
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c
index 60df674f0aa..c2692c62305 100644
--- a/sys/dev/rnd.c
+++ b/sys/dev/rnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rnd.c,v 1.87 2008/03/02 21:29:07 djm Exp $ */
+/* $OpenBSD: rnd.c,v 1.88 2008/06/04 00:50:23 djm Exp $ */
/*
* rnd.c -- A strong random number generator
@@ -626,7 +626,7 @@ arc4random_uniform(u_int32_t upper_bound)
min = 1 + ~upper_bound; /* 2**32 - upper_bound */
else {
/* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
- min = ((0xffffffff - (upper_bound << 2)) + 1) % upper_bound;
+ min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
}
#endif
diff --git a/usr.sbin/bind/lib/isc/random.c b/usr.sbin/bind/lib/isc/random.c
index 4f74f8b6d50..0cb8a0906f5 100644
--- a/usr.sbin/bind/lib/isc/random.c
+++ b/usr.sbin/bind/lib/isc/random.c
@@ -115,7 +115,7 @@ isc_random_uniform(isc_uint32_t upper_bound)
min = 1 + ~upper_bound; /* 2**32 - upper_bound */
else {
/* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
- min = ((0xffffffff - (upper_bound << 2)) + 1) % upper_bound;
+ min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
}
#endif