mcrypt_create_iv() is the cleanest access to a universal system-level primitive that supports both /dev/urandom and php_win32_get_random_bytes() under the hood. Unfortunately, it resides in /ext/mcrypt and the mcrypt extension isn't always enabled/available (nor should it be). At any rate, it is quite odd that the function php_win32_get_random_bytes() is compiled into the core of PHP by default under Windows but there's currently no way to get at it except through an extension. There's good code in mcrypt_create_iv() that is significantly useful outside of the rest of that extension and it isn't actually dependent upon libmcrypt for proper operation.
Moving the guts of this non-dependent function into the core would allow mcrypt_create_iv() to just become an alias. The new userland function could be located in /ext/standard/rand.c and have an uncreative name like rand_bytes().
--
Thomas Hruska
CubicleSoft President
I've got great, time saving software that you will find useful.
Hi Thomas,
On Fri, Feb 7, 2014 at 3:05 PM, Thomas Hruska thruska@cubiclesoft.comwrote:
mcrypt_create_iv() is the cleanest access to a universal system-level primitive that supports both /dev/urandom and php_win32_get_random_bytes() under the hood. Unfortunately, it resides in /ext/mcrypt and the mcrypt extension isn't always enabled/available (nor should it be). At any rate, it is quite odd that the function php_win32_get_random_bytes() is compiled into the core of PHP by default under Windows but there's currently no way to get at it except through an extension. There's good code in mcrypt_create_iv() that is significantly useful outside of the rest of that extension and it isn't actually dependent upon libmcrypt for proper operation.
We already have something similar to that in password.c:
http://lxr.php.net/xref/PHP_5_6/ext/standard/password.c#111
It shouldn't be hard to turn this into an API function so that other code written against php can use it for their own purposes.
Quoted text · 7 lines
Moving the guts of this non-dependent function into the core would allow mcrypt_create_iv() to just become an alias. The new userland function could be located in /ext/standard/rand.c and have an uncreative name like rand_bytes().
--
Thomas Hruska
CubicleSoft PresidentI've got great, time saving software that you will find useful.
--
--
Tjerk
Quoted text · 6 lines
Hi Thomas,
On Fri, Feb 7, 2014 at 3:05 PM, Thomas Hruska thruska@cubiclesoft.comwrote:
mcrypt_create_iv() is the cleanest access to a universal system-level primitive that supports both /dev/urandom and php_win32_get_random_bytes() under the hood. Unfortunately, it resides in /ext/mcrypt and the mcrypt extension isn't always enabled/available (nor should it be). At any rate, it is quite odd that the function php_win32_get_random_bytes() is compiled into the core of PHP by default under Windows but there's currently no way to get at it except through an extension. There's good code in mcrypt_create_iv() that is significantly useful outside of the rest of that extension and it isn't actually dependent upon libmcrypt for proper operation.
We already have something similar to that in password.c:
http://lxr.php.net/xref/PHP_5_6/ext/standard/password.c#111
It shouldn't be hard to turn this into an API function so that other code written against php can use it for their own purposes.
While reading this code portion, I wonder if anyone has tested it on system where there is no urandom available but other names. I think it should use the entropy source ini setting instead of hard coded urandom. Thoughts?
Cheers,
Pierre
@pierrejoye | http://www.libgd.org
mcrypt_create_iv() is the cleanest access to a universal system-level primitive that supports both /dev/urandom and php_win32_get_random_bytes() under the hood. Unfortunately, it resides in /ext/mcrypt and the mcrypt extension isn't always enabled/available (nor should it be). At any rate, it is quite odd that the function php_win32_get_random_bytes() is compiled into the core of PHP by default under Windows but there's currently no way to get at it except through an extension. There's good code in mcrypt_create_iv() that is significantly useful outside of the rest of that extension and it isn't actually dependent upon libmcrypt for proper operation.
Moving the guts of this non-dependent function into the core would allow mcrypt_create_iv() to just become an alias. The new userland function could be located in /ext/standard/rand.c and have an uncreative name like rand_bytes().
We do not force to enable extension with external dependencies, even less in ext/standard.
However, if any function should be enabled by default, if the deps are available obviously, it should be the one from openssl, it is by far more available and better.
Also we need something to differentiate crypto safe vs strong entropy sources to avoid the usual issues with crypto safe used in cases with no requirements for crypto safe entropy.
Cheers,
Pierre
@pierrejoye | http://www.libgd.org
Hi Thomas,
On Fri, Feb 7, 2014 at 4:05 PM, Thomas Hruska thruska@cubiclesoft.comwrote:
Moving the guts of this non-dependent function into the core would allow mcrypt_create_iv() to just become an alias. The new userland function could be located in /ext/standard/rand.c and have an uncreative name like rand_bytes().
There is new great PECL package.
http://pecl.php.net/package/crypto
I would like to see it as default for crypt related feature.
Anyway, we need default rundom_bytes() function in ext/standard. This is mandatory for secure apps, but we have no default function. This should be resolved.
Anyway, mcrypt_create_iv() is not optimum, yet. Here is possible improvement.
https://github.com/yohgaki/php-src/compare/PHP-5.6-mcrypt_create_iv
It still requires random source and it does not support windows well, though.
I'm about to adding new function which solves all of them like session module.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Quoted text · 12 lines
Hi Thomas,
On Fri, Feb 7, 2014 at 4:05 PM, Thomas Hruska <thruska@cubiclesoft.com
wrote:
Moving the guts of this non-dependent function into the core would allow mcrypt_create_iv() to just become an alias. The new userland function could be located in /ext/standard/rand.c and have an uncreative name like rand_bytes().
There is new great PECL package.
http://pecl.php.net/package/crypto
I would like to see it as default for crypt related feature.Anyway, we need default rundom_bytes() function in ext/standard. This is mandatory for secure apps, but we have no default function. This should be resolved.
Anyway, mcrypt_create_iv() is not optimum, yet. Here is possible improvement.
https://github.com/yohgaki/php-src/compare/PHP-5.6-mcrypt_create_iv
It still requires random source and it does not support windows well, though.
I'm about to adding new function which solves all of them like session module.
Speaking of which, it would be nice if session id generation depended on this shiny new API as well ... basically we solve two problems:
- An easy way to get a bunch of random bytes
- Centralize random number generation internally, i.e. session ids and password salts are generated with it.
I'm not sure whether this should extend to providing an easy way to generate crypto safe random numbers, but that would obviously be nice if feasible.
Quoted text · 4 lines
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
--
Tjerk
On Fri, Feb 7, 2014 at 12:31 PM, Tjerk Meesters tjerk.meesters@gmail.com wrote:
Quoted text · 4 lines
Speaking of which, it would be nice if session id generation depended on this shiny new API as well ... basically we solve two problems:
- An easy way to get a bunch of random bytes
- Centralize random number generation internally, i.e. session ids and password salts are generated with it.
I'm not sure whether this should extend to providing an easy way to generate crypto safe random numbers, but that would obviously be nice if feasible.
See my other post today about unifying entropy source. We may discuss that there.
--
Pierre
@pierrejoye | http://www.libgd.org
Hi Thomas,
On Fri, Feb 7, 2014 at 4:05 PM, Thomas Hruska thruska@cubiclesoft.comwrote:
mcrypt_create_iv() is the cleanest access to a universal system-level primitive that supports both /dev/urandom and php_win32_get_random_bytes() under the hood. Unfortunately, it resides in /ext/mcrypt and the mcrypt extension isn't always enabled/available (nor should it be). At any rate, it is quite odd that the function php_win32_get_random_bytes() is compiled into the core of PHP by default under Windows but there's currently no way to get at it except through an extension. There's good code in mcrypt_create_iv() that is significantly useful outside of the rest of that extension and it isn't actually dependent upon libmcrypt for proper operation.
Moving the guts of this non-dependent function into the core would allow mcrypt_create_iv() to just become an alias. The new userland function could be located in /ext/standard/rand.c and have an uncreative name like rand_bytes().
rand_bytes() (or random_bytes()) is common names for the task. We may adopt it.
Anyway, I've wrote portable one for the task.
https://github.com/yohgaki/php-src/compare/PHP-5.6-rfc-random_bytes
Function name could be rand_bytes() or anything. Name is important, but implementation is
more important here. It's still work in progress, as it does not use OpenSSL.
I would like to use OpenSSL's RAND_bytes() for this. This mean when OpenSSL is available,
PHP is linked with OpenSSL. With OpenSSL's RAND_bytes() and RAND_peduso_bytes(), we
may be able to use better RNG/PRNG for the platform.
Any comments?
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net