PackageTrack
Sign in Get early access

paragonie/random_compat

PHP 5.x polyfill for random_bytes() and random_int() from PHP 7

v9.99.100 708M downloads/mo #114 most downloaded on composer paragonie/random_compat

What this package is like to depend on

Last release 5 years ago

no release in 18 months

Release timing varies

gaps range from 2 weeks to 1.8 years

Most releases are documented

notes for 52 of 59 stable releases

Nothing withdrawn

no release was ever pulled

11 years old

59 releases · first in 2015

0 releases in the last 12 months

see the full history below

Release timeline

59 releases · Jul 2015 to Feb 2022
2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026
Release Pre-release

Releases

latest 59
  1. v9.99.100 15 Oct 2020
    Release notes

    Version 9.99.100 (2020-10-15)

    Open source →
  2. v9.99.99 02 Jul 2018

    Nothing published for this version

  3. v2.0.21 16 Feb 2022
    Release notes
    • Fix #175 - Fix CAPICOM usage on Windows
    • Widen PHPUnit version range
    • Test PHP 8.1 in GitHub Actions (thanks @jrfnl!)
    • Fix unit tests on PHP 8.1
    Open source →
  4. v2.0.20 17 Apr 2021
    Release notes
    • Switched from Travis CI to Github Actions
    • Minor whitespace change (never-ending Scrutinizer suggestion)
    Open source →
  5. v2.0.19 15 Oct 2020
    Release notes
    • Adds support for PHP 8 projects in Composer constraint
    • Fixes Travis CI for future development (Note: This required largely disabling Psalm.)
    Open source →
  6. v2.0.18 03 Jan 2019
    Release notes
    • If /dev/urandom cannot be read on Unix-based operating systems,
      a Exception with a specific error message will be thrown.
    • Fixed Psalm nits.
    • Updated the README to include a reference to the support contract
      offering by Paragon Initiative Enterprises.
    Open source →
    Release notes
    • If /dev/urandom cannot be read on Unix-based operating systems, a Exception with a specific error message will be thrown.
    • Fixed Psalm nits.
    • Updated the README to include a reference to the support contract offering by Paragon Initiative Enterprises.
    Open source →
  7. v2.0.17 04 Jul 2018
    Release notes
    • Version 2.0.16 failed Psalm checks on PHP v5.6 with Psalm v1. We could not reproduce this failure locally, so we've suppressed the MissingReturnType check (that is to say, demoted it to "info").
    Open source →
    Release notes
    • Version 2.0.16 failed Psalm checks on PHP v5.6 with Psalm v1. We could not reproduce this failure locally, so we've suppressed the MissingReturnType check (that is to say, demoted it to "info").
    Open source →
  8. v2.0.16 04 Jul 2018
    Release notes
    • Fixed type-checking consistencies that forced us to use Psalm in non-strict mode (i.e. totallyTyped="false").
    • README cleanup, added a header to the Version 9.99.99 section.
      • If you're confused by v9.99.99 and it's causing stuff to break, see this section of the README for the solution to your problem.
    • Trimmed down and annotated our psalm.xml file with explanations for why each assertion is suppressed.
    Open source →
    Release notes
    • Fixed type-checking consistencies that forced us to use Psalm in non-strict mode (i.e. totallyTyped="false").
    • README cleanup, added a header to the Version 9.99.99 section.
      • If you're confused by v9.99.99 and it's causing stuff to break, see this section of the README for the solution to your problem.
    • Trimmed down and annotated our psalm.xml file with explanations for why each assertion is suppressed.
    Open source →
  9. v2.0.15 08 Jun 2018
    Release notes
    • A reported, but difficult to reproduce, problem with file inclusion on some Windows machines was fixed by replacing / with DIRECTORY_SEPARATOR.
      For most users (i.e. not running Windows) this change should be of zero consequence. For everyone else, it should mean random_compat magically works when it didn't before.
    Open source →
    Release notes
    • A reported, but difficult to reproduce, problem with file inclusion on some Windows machines was fixed by replacing / with DIRECTORY_SEPARATOR. For most users (i.e. not running Windows) this change should be of zero consequence. For everyone else, it should mean random_compat magically works when it didn't before.
    Open source →
  10. v2.0.14 06 Jun 2018
    Release notes
    • Update version information.
    • Updated README with better instructions, including new information about the v9.99.99 tag.
    Open source →
    Release notes
    • Update version information.
    • Updated README with better instructions, including new information about the v9.99.99 tag.
    Open source →
  11. v2.0.13 06 Jun 2018
    Release notes
    • #139 - Add polyfill keyword to composer.json
    • Ensure the docblocks are consistent to aid static analysis efforts in other libraries; see https://github.com/paragonie/random_compat/commit/cbe0b11b78140bc62a921fec33a730fdaa6540d6
    Open source →
  12. v2.0.12 04 Apr 2018
    Release notes
    • Minor docblock issue that's breaking Psalm downstream.
    Open source →
  13. v2.0.11 27 Sep 2017
    Release notes
    • Minor docblock corrections.
    • Re-issuing a PHP Archive to attempt to address an issue with the Phar provided. See #134.
    Open source →
  14. v2.0.10 13 Mar 2017
    Release notes
    • Mcrypt can now be used on PHP < 5.3.7 if you're not on Windows.
    • Minor boyscouting changes.
    Open source →
  15. v2.0.9 03 Mar 2017
    Release notes
    • More Psalm integration fixes.
    Open source →
  16. v2.0.8 03 Mar 2017
    Release notes
    • Prevent function already declared error for 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.
    Open source →
  17. v2.0.7 27 Feb 2017

    Nothing published for this version

  18. v2.0.6 27 Feb 2017
    Release notes
    • Just updates to psalm.xml to silence false positives.
    Open source →
  19. v2.0.5 27 Feb 2017
    Release notes
    • Run random_compat through the static analysis tool, psalm, as part of our continuous integration process.
    • Minor readability enhancements (#122 and several docblock changes).
    Open source →
  20. v2.0.4 07 Nov 2016
    Release notes
    • Don't unnecessarily prevent mcrypt_create_iv() from being used. See #111.
    Open source →
  21. v2.0.3 17 Oct 2016
    Release notes
    Open source →
  22. v2.0.2 03 Apr 2016
    Release notes

    Added a consistency check (discovered by Taylor Hornby in his PHP encryption library). It wasn't likely causing any trouble for us.

    Open source →
  23. v2.0.1 18 Mar 2016
    Release notes

    Update comment in random.php

    Open source →
  24. v2.0.0 18 Mar 2016
    Release notes

    Due to downstream errors, the OpenSSL removal now belongs in version 2.0.0.

    Open source →
  25. v1.4.3 04 Apr 2018

    Nothing published for this version

  26. v1.4.2 13 Mar 2017

    Nothing published for this version

  27. v1.4.1 18 Mar 2016

    Nothing published for this version

  28. v1.4.0 18 Mar 2016

    Nothing published for this version

  29. v1.3.1 18 Mar 2016
    Release notes
    • Add more possible values to open_basedir check.
    Open source →
  30. v1.3.0 17 Mar 2016
    Release notes
    • Removed 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;
          }
      }
      
    Open source →
  31. v1.2.3 18 Mar 2016

    Nothing published for this version

  32. v1.2.2 11 Mar 2016
    Release notes
    • To prevent applications from hanging, if /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).
    Open source →
  33. v1.2.1 29 Feb 2016
    Release notes
    • PHP 5.6.10 - 5.6.12 will hang when mcrypt is used on Unix-based operating systems (PHP bug 69833). If you are running one of these versions, please upgrade (or make sure /dev/urandom is readable) otherwise you're relying on OpenSSL.
    Open source →
  34. v1.2.0 06 Feb 2016
    Release notes
    • Whitespace and other cosmetic changes

    • Added a changelog.

    • We now ship with a command line utility to build a PHP Archive from the command line.

      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 source →
  35. 1.1.6 29 Jan 2016
    Release notes
    • Eliminate open_basedir warnings by detecting this configuration setting. (Thanks @oucil for reporting this.)
    • Added install instructions to the README.
    • Documentation cleanup (there is, in fact, no MCRYPT_CREATE_IV constant, I meant to write MCRYPT_DEV_URANDOM)
    Open source →
  36. 1.1.5 06 Jan 2016
    Release notes

    Prevent fatal errors on platforms with older versions of libsodium.

    Open source →
  37. 1.1.4 10 Dec 2015
    Release notes

    Thanks @narfbg for critiquing the previous patch and suggesting a fix.

    Open source →
  38. 1.1.3 09 Dec 2015
    Release notes

    The test for COM in disabled_classes is now case-insensitive.

    Open source →
  39. 1.1.2 09 Dec 2015
    Release notes

    Don't instantiate COM if it's a disabled class. Removes the E_WARNING on Windows.

    Open source →
  40. 1.1.1 01 Dec 2015
    Release notes

    Fix a performance issue with /dev/urandom buffering.

    Open source →
  41. 1.1.0 10 Nov 2015
    Release notes

    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.

    Open source →
  42. 1.0.10 23 Oct 2015
    Release notes
    • Avoid a performance killer with OpenSSL on Windows PHP 5.3.0 - 5.3.3 that was affecting WordPress users.
    • Use $var = null instead of unset($var) to avoid triggering the garbage collector and slowing things down.
    Open source →
  43. 1.0.9 20 Oct 2015
    Release notes

    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).

    Open source →
  44. 1.0.8 18 Oct 2015
    Release notes
    • Fix usability issues with Windows (new COM('CAPICOM.Utilities.1') is not always available).
    • You can now test all the possible drivers by running phpunit.sh each in the tests directory.
    Open source →
  45. 1.0.7 16 Oct 2015
    Release notes

    Several large integer handling bugfixes were contributed by @oittaa.

    Open source →
  46. 1.0.6 16 Oct 2015
    Release notes

    Don't let the version number fool you, this was a pretty significant change.

    1. Added support for ext-libsodium, if it exists on the system. This is morally equivalent to adding getrandom(2) support without having to expose the syscall interface in PHP-land.
    2. Relaxed open_basedir restrictions. In previous versions, if open_basedir was set, PHP wouldn't even try to read from /dev/urandom. Now it will still do so if you can.
    3. Fixed integer casting inconsistencies between random_compat and PHP 7.
    4. Handle edge cases where an integer overflow turns one of the parameters into a float.

    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 7. Please use these functions responsibly.

    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.

    Open source →
  47. 1.0.5 08 Oct 2015
    Release notes

    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).

    Open source →
  48. 1.0.4 02 Oct 2015
    Release notes

    Removed redundant if() checks, since lib/random.php is the entrypoint people should use.

    Open source →
  49. 1.0.3 02 Oct 2015
    Release notes

    This release contains bug fixes contributed by the community.

    • Avoid a PHP Notice when PHP is running without the mbstring extension
    • Use a compatible version of PHPUnit for testing on older versions of PHP

    Although none of these bugs were outright security-affecting, updating ASAP is still strongly encouraged.

    Open source →
  50. 1.0.2 23 Sep 2015
    Release notes

    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.

    Open source →
  51. v1.0.1 10 Sep 2015
    Release notes

    Instead of throwing an Exception immediately on insecure platforms, only do so when random_bytes() is invoked.

    Open source →
    Release notes

    fdc471f

    Instead of throwing an Exception immediately on insecure platforms, only do so when random_bytes() is invoked.

    Open source →
  52. v1.0.0 07 Sep 2015
    Release notes

    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.

    Open source →
  53. v0.9.7 01 Sep 2015
    Release notes

    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.

    Open source →
  54. 0.9.5 31 Jul 2015
    Release notes
    • Validate that /dev/urandom is a character device
    • Remove support for /dev/arandom which is an old OpenBSD feature, thanks @jedisct1
    • Prevent race conditions on the filetype() check, thanks @jedisct1
    • Buffer file reads to 8 bytes (performance optimization; PHP defaults to 8192 bytes)
    Open source →
  55. 0.9.4 27 Jul 2015
    Release notes
    • Add logic to verify that /dev/arandom and /dev/urandom are actually devices.
    • Some clean-up in the comments
    Open source →
  56. 0.9.3 22 Jul 2015
    Release notes

    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:

    • Prioritize /dev/arandom and /dev/urandom over mcrypt. @oittaa removed the -1 and +1 juggling on $range calculations for random_int()
    • Whitespace and comment clean-up, plus better variable names
    • Actually put a description in the composer.json file...
    Open source →
  57. 0.9.2 17 Jul 2015
    Release notes
    • Consolidated $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
    • Style consistency, whitespace cleanup, more meaningful variable names
    Open source →
  58. 0.9.1 10 Jul 2015
    Release notes
    • Return random values on integer ranges > PHP_INT_MAX (thanks @CodesInChaos)
    • Determined CSPRNG preference:
      1. mcrypt_create_iv() with MCRYPT_DEV_URANDOM
      2. /dev/arandom
      3. /dev/urandom
      4. openssl_random_pseudo_bytes()
    • Optimized backend selection (thanks @lt)
    • Fix #3 (thanks @scottchiefbaker)
    Open source →
  59. 0.9.0 07 Jul 2015
    Release notes

    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.

    Open source →

Every package, every release, already written down.

The archive is open and free. Watching your own project is what we are building next.

Browse the archive