stefanesser/suhosin — pull request #40 by DavisNT (2014-04-06 23:02:14+00:00)
Title: Enhanced reseeding of PRNGs

Often pseudo-random number generation in PHP applications is used for creation of sensitive material (application session IDs, API keys etc.). Suhosin already makes _mt_rand()_ and _rand()_ PRNGs much more secure by using 256-bit cryptographically hashed seed with customized Mersenne twister initialization.

This commit takes a step further by reseeding PRNGs with pseudo-random data on per-request basis and when corresponding functions are called (ignoring any supplied seed). This commit also introduces additional configurable key that can be used on low-entropy systems to impede predicting of 256-bit cryptographically hashed seed.

This commit makes the following changes:
1. When _suhosin.mt_srand.ignore_ and/or _suhosin.srand.ignore_ are enabled,
corresponding PRNGs are reseeded with random values (ignoring supplied
seeds) when _mt_srand($seed)_ and/or _srand($seed)_ are called. This way
applications that reseed PRNG(s) to create a brand new sequence of
random numbers will create a brand new sequence, but (in most cases)
with much more random/secure seed. Previous behavior was to ignore calls
to _mt_srand()_ and _srand()_ when _suhosin.mt_srand.ignore_ and/or
_suhosin.srand.ignore are enabled_.
2. _mt_rand()_ and _rand()_ PRNGs are reseeded before first use in each new
request. This way it is much harder to predict random numbers generated
in past (or subsequest) requests that are server by the same PHP
process. Previous behaviour was to automatically seed PRNGs before first
use in each new PHP process.
3. A new php.ini value _suhosin.rands.seedkey_ is introduced. This (along
with collected entropy) is cryptographically hashed and used as random
seeds for PRNGs. Setting this key to a long random and secret string
makes it even harder to predict generation of random PRNG seeds. This is
especially useful on systems without _/dev/urandom_.