Re: Improving mt_rand() seed

From: Date: Sat, 21 Jan 2017 12:34:06 +0000
Subject: Re: Improving mt_rand() seed
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-97911@lists.php.net to get a copy of this message
On 16.01.2017 at 08:04, Yasuo Ohgaki wrote: > Since I was about to improve uniqid()'s entropy by replacing > php_combined_lcg() to php_random_int(), I spent time to check other places > that could be a problem. > > mt_rand()'s is seeded as follows by default. > > ext/standard/php_rand.h > #ifdef PHP_WIN32 > #define GENERATE_SEED() (((zend_long) (time(0) * GetCurrentProcessId())) ^ > ((zend_long) (1000000.0 * php_combined_lcg()))) > #else > #define GENERATE_SEED() (((zend_long) (time(0) * getpid())) ^ ((zend_long) > (1000000.0 * php_combined_lcg()))) > #endif > > We know this kind of seed is guessable. But where's the problem? mt_rand() is not suitable for cryptographic purposes anyway. > i.e. Our session id is compromised > by this kind of code. Does the session ID rely on mt_rand() or GENERATE_SEED()? If so, that would of course be an issue, but that should be fixed by not using mt_rand()/GENERATE_SEED() for the session ID at all, IMHO. -- Christoph M. Becker

« previous php.internals (#97911) next »