Re: Improving mt_rand() seed
| From: | Leigh | Date: | Tue, 17 Jan 2017 14:48:55 +0000 |
| Subject: | Re: Improving mt_rand() seed | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-97811@lists.php.net to get a copy of this message | ||
On 16 January 2017 at 07:04, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> Hi all,
>
> 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. i.e. Our session id is compromised
> by this kind of code.
mt_rand is not advertised as crypto-quality.
Where do you think mt_rand is used in session id generation?
>
> Although it would be rare that raw mt_rand() value is exposed, but
> guessable value is guessable. I'm going to replace the seeding code by
> simple php_random_int() call.
>
> Any comments?
>
> Regards,
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net