summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/drand48.c
diff options
context:
space:
mode:
authorderaadt <>2014-12-08 21:45:20 +0000
committerderaadt <>2014-12-08 21:45:20 +0000
commit1e2b0be5bee045db1b0abb1f87801004db563bb8 (patch)
treebf17a76201de02c2ce50358a383001a6b6c5cc64 /src/lib/libc/stdlib/drand48.c
parent4b0b4fc5d98edef87738071b3784e13573327bab (diff)
downloadopenbsd-1e2b0be5bee045db1b0abb1f87801004db563bb8.tar.gz
openbsd-1e2b0be5bee045db1b0abb1f87801004db563bb8.tar.bz2
openbsd-1e2b0be5bee045db1b0abb1f87801004db563bb8.zip
Change rand(), random(), drand48(), lrand48(), mrand48(), and srand48()
to returning strong random by default, source from arc4random(3). Parameters to the seeding functions are ignored, and the subsystems remain in strong random mode. If you wish the standardized deterministic mode, call srand_deterministic(), srandom_determistic(), srand48_deterministic(), seed48_deterministic() or lcong48_deterministic() instead. The re-entrant functions rand_r(), erand48(), nrand48(), jrand48() are unaffected by this change and remain in deterministic mode (for now). Verified as a good roadmap forward by auditing 8800 pieces of software. Roughly 60 pieces of software will need adaptation to request the deterministic mode. Violates POSIX and C89, which violate best practice in this century. ok guenther tedu millert
Diffstat (limited to 'src/lib/libc/stdlib/drand48.c')
-rw-r--r--src/lib/libc/stdlib/drand48.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/lib/libc/stdlib/drand48.c b/src/lib/libc/stdlib/drand48.c
index b6c046c831..bbeedf8a8a 100644
--- a/src/lib/libc/stdlib/drand48.c
+++ b/src/lib/libc/stdlib/drand48.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: drand48.c,v 1.3 2005/08/08 08:05:36 espie Exp $ */ 1/* $OpenBSD: drand48.c,v 1.4 2014/12/08 21:45:20 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 1993 Martin Birgmeier 3 * Copyright (c) 1993 Martin Birgmeier
4 * All rights reserved. 4 * All rights reserved.
@@ -19,5 +19,13 @@ extern unsigned short __rand48_seed[3];
19double 19double
20drand48(void) 20drand48(void)
21{ 21{
22 if (__rand48_deterministic == 0) {
23 short rseed[3];
24
25 arc4random_buf(rseed, sizeof rseed);
26 return ldexp((double) rseed[0], -48) +
27 ldexp((double) rseed[1], -32) +
28 ldexp((double) rseed[2], -16);
29 }
22 return erand48(__rand48_seed); 30 return erand48(__rand48_seed);
23} 31}