diff options
author | Rasmus Lerdorf <rasmus@php.net> | 2010-01-08 09:43:14 +0000 |
---|---|---|
committer | Rasmus Lerdorf <rasmus@php.net> | 2010-01-08 09:43:14 +0000 |
commit | 58867bacc1df663b1d404ec488161d3d35c474dd (patch) | |
tree | 984198b6223e1822185bc0210ff1f053b856fc34 | |
parent | 679b228391cd13fa5cc434981834aa5700158507 (diff) | |
download | php-git-58867bacc1df663b1d404ec488161d3d35c474dd.tar.gz |
Worked with Samy Kamkar to improve LCG entropy.
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | ext/standard/lcg.c | 7 |
2 files changed, 7 insertions, 1 deletions
@@ -7,6 +7,7 @@ PHP NEWS - Added missing host validation for HTTP urls inside FILTER_VALIDATE_URL. (Ilia) - Added stream_resolve_include_path(). (Mikko) +- Improved LCG entropy (Rasmus, Samy Kamkar) - Fixed bug #50680 (strtotime() does not support eighth ordinal number). (Ilia) diff --git a/ext/standard/lcg.c b/ext/standard/lcg.c index ad9c4744f8..aa0adff2fb 100644 --- a/ext/standard/lcg.c +++ b/ext/standard/lcg.c @@ -78,7 +78,7 @@ static void lcg_seed(TSRMLS_D) /* {{{ */ struct timeval tv; if (gettimeofday(&tv, NULL) == 0) { - LCG(s1) = tv.tv_sec ^ (~tv.tv_usec); + LCG(s1) = tv.tv_sec ^ (tv.tv_usec<<11); } else { LCG(s1) = 1; } @@ -88,6 +88,11 @@ static void lcg_seed(TSRMLS_D) /* {{{ */ LCG(s2) = (long) getpid(); #endif + /* Add entropy to s2 by calling gettimeofday() again */ + if (gettimeofday(&tv, NULL) == 0) { + LCG(s2) ^= (tv.tv_usec<<11); + } + LCG(seeded) = 1; } /* }}} */ |