summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-arc4random.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2008-06-04 10:54:00 +1000
committerDamien Miller <djm@mindrot.org>2008-06-04 10:54:00 +1000
commit58ea61ba2a747e4f0beb3afcbbdea8ada5119143 (patch)
treeec76bc8cd66c5c5b61fe7d3bf3c7ae99b6d2b758 /openbsd-compat/bsd-arc4random.c
parenta7058ec7c03017b89ba75fc0b9a58ca672aab9e9 (diff)
- (djm) [openbsd-compat/bsd-arc4random.c] Fix math bug that caused bias
in arc4random_uniform with upper_bound in (2^30,2*31). Note that OpenSSH did not make requests with upper bounds in this range.
Diffstat (limited to 'openbsd-compat/bsd-arc4random.c')
-rw-r--r--openbsd-compat/bsd-arc4random.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/openbsd-compat/bsd-arc4random.c b/openbsd-compat/bsd-arc4random.c
index 92e7e7b58..9d4c8690e 100644
--- a/openbsd-compat/bsd-arc4random.c
+++ b/openbsd-compat/bsd-arc4random.c
@@ -129,7 +129,7 @@ arc4random_uniform(u_int32_t upper_bound)
129 min = 1 + ~upper_bound; /* 2**32 - upper_bound */ 129 min = 1 + ~upper_bound; /* 2**32 - upper_bound */
130 else { 130 else {
131 /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */ 131 /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
132 min = ((0xffffffff - (upper_bound << 2)) + 1) % upper_bound; 132 min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
133 } 133 }
134#endif 134#endif
135 135