|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-08-03 13:37 UTC] php-bugs at thequod dot de
Description: ------------ mcrypt_create_iv (or likely rather the underlying function php_win32_get_random_bytes) is not reliable on Windows with MCRYPT_DEV_RANDOM/MCRYPT_DEV_URANDOM. Since 5.3.0 MCRYPT_DEV_RANDOM and MCRYPT_DEV_URANDOM became available on Windows platforms. (http://php.net/mcrypt_create_iv) MCRYPT_RAND will still works, as with PHP prior to 5.3.0. Test script: --------------- The following code should loop forever, but does not do so on Windows (XP and Windows 7): php -r "$i=0; while( mcrypt_create_iv(16) !== false ) {echo ($i++).'.';};" Expected result: ---------------- Infinite loop. Actual result: -------------- 0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17. Fatal error: mcrypt_create_iv(): Could not gather sufficient random data in Command line code on line 1 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 18:00:01 2025 UTC |
Windows: % while php -r '$s = microtime(true); if( mcrypt_create_iv(16, MCRYPT_DEV_RANDOM) === false ) exit(1); $e = microtime(true); printf("%.5f\n", $e-$s);'; do true; done 0.00449 0.00454 Fatal error: mcrypt_create_iv(): Could not gather sufficient random data in Command line code on line 1 Linux: # while php -r '$s = microtime(true); if( mcrypt_create_iv(16, MCRYPT_DEV_RANDOM) === false ) exit(1); $e = microtime(true); printf("%.2f\n", $e-$s);'; do true; done 0.00 3.51 3.56 4.03 3.58 4.06 3.71 5.12 4.19 3.41 3.87 3.91 3.74 5.09 4.26 3.71 3.78 4.41 5.48 5.09 6.50 4.14 3.58 3.83 6.02 3.74 3.87 4.68 6.92 4.52 6.01 ... Completely different machines though, of course.@derick urandom is not crypto safe (to be more precised). @thequod About the patch in typo3, this code is wrong. They use urandom on non windows platform, then try alternatives on windows only. Problem is that they first try COM (very slow), then try with mcrypt_create_iv and overwrite COM output (regardless if it worked well or not). MCrypt also always exists on windows with 5.3+, no need to test it (statically compiled). The openssl code won't be used either (never reached this condition). However even if the openssl code was used, its logic is wrong. It considers non strong (not crypto safe) output as invalid. But urandom is not crypto safe anyway. They should test for the openssl function in the 1st place then use fopen('urandom') and finally mcrypt and other options. Much better/cleaner. About your last comment, that fits in the explanation I gave earlier. Nothing new.