note 68054 modified in function.mcrypt-create-iv by cmb
| From: | cmb@php.net | Date: | Mon, 27 Jul 2015 17:06:32 +0000 |
| Subject: | note 68054 modified in function.mcrypt-create-iv by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203195@lists.php.net to get a copy of this message | ||
After profiling a rather large, dynamic website I maintain to determine the cause of intermittent
freezing in execution, I found that calls to mcrypt_create_iv() using MCRYPT_DEV_RANDOM as the
source consistently halted execution for anywhere from 0.2 to ~12 seconds per call, ironically at
random. I'm making the assumption that the halts were caused by insufficient random input being
currently available in /dev/random due to its intended function to block until enough random input
is provided back to the device. I've found it to be sufficient for my needs to use a modified
version of the alt_mcrypt_create_iv() function found below.
Although untested, I assume using MCRYPT_DEV_URANDOM or a combination of MCRYPT_DEV_RAND with
srand() would've solved the problem as well; I found out after the fact that
/dev/urandom's intended function is to seamlessly provide cryptographically secure output from
the random number generator when the /dev/urandom buffer was empty, and MCRYPT_DEV_RAND would simply
use the same rand() function as alt_mcrypt_create_iv().
-Kevin Kaiser
--was--
After profiling a rather large, dynamic website I maintain to determine the cause of intermittent
freezing in execution, I found that calls to mcrypt_create_iv() using DEV_RANDOM as the source
consistently halted execution for anywhere from 0.2 to ~12 seconds per call, ironically at random.
I'm making the assumption that the halts were caused by insufficient random input being
currently available in /dev/random due to its intended function to block until enough random input
is provided back to the device. I've found it to be sufficient for my needs to use a modified
version of the alt_mcrypt_create_iv() function found below.
Although untested, I assume using DEV_URANDOM or a combination of DEV_RAND with srand()
would've solved the problem as well; I found out after the fact that /dev/urandom's
intended function is to seamlessly provide cryptographically secure output from the random number
generator when the /dev/urandom buffer was empty, and DEV_RAND would simply use the same rand()
function as alt_mcrypt_create_iv().
-Kevin Kaiser
http://php.net/manual/en/function.mcrypt-create-iv.php