]> granicus.if.org Git - php/commitdiff
Worked with Samy Kamkar to improve LCG entropy.
authorRasmus Lerdorf <rasmus@php.net>
Fri, 8 Jan 2010 09:43:14 +0000 (09:43 +0000)
committerRasmus Lerdorf <rasmus@php.net>
Fri, 8 Jan 2010 09:43:14 +0000 (09:43 +0000)
NEWS
ext/standard/lcg.c

diff --git a/NEWS b/NEWS
index 3d61dd9b79dbef50ea2848b4325b995dcd2e0431..f926949846b4f8fd6ea5c9b75e50aabaae608f6c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,8 @@ PHP                                                                        NEWS
 
 - Fixed build of mysqli with MySQL 5.5.0-m2. (Andrey)
 
+- Improved LCG entropy (Rasmus, Samy Kamkar)
+
 - Fixed bug #50680 (strtotime() does not support eighth ordinal number).
   (Ilia)
 - Fixed bug #50661 (DOMDocument::loadXML does not allow UTF-16). (Rob)
index 71abc775835ea3f147faa7f7f3deb2dbb063cfdb..8c66a2fa5981b3bb7df2e1e156d914558508c45a 100644 (file)
@@ -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;
 }