]> 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)
ext/standard/lcg.c

index b92ef3b3a4e19d56a85f9af41ac8d053c77f50cb..b2ea786a442dcee2e5954b4ef68e50e5e3fbf007 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;
 }
 /* }}} */