^1
to ^1|^2
if you want other
changes (i.e. better compatibility with type-safety), because the
v2 branch is where most of the development effort is focused.
Continued support for v1.x is considered "only for emergencies".random_int()
caused by misusing
the library (really you should only ever include lib/random.php
and never any
of the other files). See #125.mcrypt_create_iv()
from being used.
See #111.lib/error_polyfill.php
to resolve corner cases.Update comment in random.php
Restored OpenSSL in the version 1 branch in preparation to remove OpenSSL in version 2.
open_baseir
check.openssl_random_pseudo_bytes()
entirely. If you are using
random_compat in PHP on a Unix-like OS but cannot access
/dev/urandom
, version 1.3+ will throw an Exception
. If you want to
trust OpenSSL, feel free to write your own fallback code. e.g.
try {
$bytes = random_bytes(32);
} catch (Exception $ex) {
$strong = false;
$bytes = openssl_random_pseudo_bytes(32, $strong);
if (!$strong) {
throw $ex;
}
}
/dev/urandom
is not
accessible to PHP, skip mcrypt (which just fails before giving OpenSSL
a chance and was morally equivalent to not offering OpenSSL at all)./dev/urandom
is
readable) otherwise you're relying on OpenSSL.Every time we publish a new release, we will also upload a .phar to Github. Our public key is signed by our GPG key.
open_basedir
warnings by detecting this configuration setting.
(Thanks @oucil for reporting this.)MCRYPT_CREATE_IV
constant, I
meant to write MCRYPT_DEV_URANDOM
)Prevent fatal errors on platforms with older versions of libsodium.
Thanks @narfbg for critiquing the previous patch and suggesting a fix.
The test for COM in disabled_classes is now case-insensitive.
Don't instantiate COM if it's a disabled class. Removes the E_WARNING on Windows.
Fix a performance issue with /dev/urandom
buffering.
Fix performance issues with ancient versions of PHP on Windows, but dropped support for PHP < 5.4.1 without mcrypt on Windows 7+ in the process. Since this is a BC break, semver dictates a minor version bump.
$var = null
instead of unset($var)
to avoid triggering the garbage
collector and slowing things down.There is an outstanding issue mcrypt_create_iv()
and PHP 7's random_bytes()
on Windows reported by @nicolas-grekas caused by proc_open()
and environment
variable handling (discovered by Appveyor when developing Symfony).
Since the break is consistent, it's not our responsibility to fix it, but we
should fail the same way PHP 7 will (i.e. throw an Exception
rather than raise
an error and then throw an Exception
).
new COM('CAPICOM.Utilities.1')
is not
always available).phpunit.sh each
in the
tests
directory.Several large integer handling bugfixes were contributed by @oittaa.
Don't let the version number fool you, this was a pretty significant change.
getrandom(2)
support without having to expose the
syscall interface in PHP-land./dev/urandom
. Now it will still do
so if you can.One change that we discussed was making random_bytes()
and random_int()
strict typed; meaning you could only pass integers to either function. While
most veteran programmers are probably only doing this already (we strongly
encourage it), it wouldn't be consistent with how these functions behave in PHP
We've had even more of the PHP community involved in this release; the contributors list has been updated. If I forgot anybody, I promise you it's not because your contributions (either code or ideas) aren't valued, it's because I'm a bit overloaded with information at the moment. Please let me know immediately and I will correct my oversight.
Thanks everyone for helping make random_compat better.
Got rid of the methods in the Throwable
interface, which was causing problems
on PHP 5.2. While we would normally not care about 5.2 (since 5.4 and earlier are EOL'd),
we do want to encourage widespread adoption (e.g. Wordpress).
Removed redundant if()
checks, since lib/random.php
is the entrypoint people
should use.
This release contains bug fixes contributed by the community.
Although none of these bugs were outright security-affecting, updating ASAP is still strongly encouraged.
Less strict input validation on random_int()
parameters. PHP 7's random_int()
accepts strings and floats that look like numbers, so we should too.
Thanks @dd32 for correcting this oversight.
Instead of throwing an Exception immediately on insecure platforms, only do so
when random_bytes()
is invoked.
Our API is now stable and forward-compatible with the CSPRNG features in PHP 7 (as of 7.0.0 RC3).
A lot of great people have contributed their time and expertise to make this compatibility library possible. That this library has reached a stable release is more a reflection on the community than it is on PIE.
We are confident that random_compat will serve as the simplest and most secure CSPRNG interface available for PHP5 projects.
An attempt to achieve compatibility with Error/TypeError in the RFC.
This should be identical to 1.0.0 sans any last-minute changes or performance enhancements.
/dev/urandom
has been opened (thanks
@narfbg and @jedisct1)/dev/urandom
is a character device
/dev/arandom
which is an old OpenBSD feature, thanks @jedisct1filetype()
check, thanks @jedisct1/dev/arandom
and /dev/urandom
are actually devices.Unless the Exceptions change to PHP 7 fails, this should be the last pre-release version. If need be, we'll make one more pre-release version with compatible behavior.
Changes since 0.9.2:
/dev/arandom
and /dev/urandom
over mcrypt.
@oittaa removed the -1 and +1 juggling on $range
calculations for random_int()
$range > PHP_INT_MAX
logic with $range <= PHP_INT_MAX
(thanks
@oittaa and @CodesInChaos)tests/phpunit.sh
now also runs the tests with mbstring.func_overload
and
open_basedir
PHP_INT_MAX
(thanks @CodesInChaos)mcrypt_create_iv()
with MCRYPT_DEV_URANDOM
/dev/arandom
/dev/urandom
openssl_random_pseudo_bytes()
This should be a sane polyfill for PHP 7's random_bytes()
and random_int()
.
We hesitate to call it production ready until it has received sufficient third
party review.