Browse Source

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@
OPENBSD_4_4
djm 16 years ago
parent
commit
5a2233d09c
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      src/lib/libc/crypt/arc4random.c

+ 2
- 2
src/lib/libc/crypt/arc4random.c View File

@ -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


Loading…
Cancel
Save