From f51ee90c66527fd7ff634f3e8d414cb670da068d Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 26 Apr 2016 11:07:44 +0200 Subject: bug #470, use a dedicated lib to generate random bytes --- include/random_compat/random_bytes_com_dotnet.php | 81 +++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 include/random_compat/random_bytes_com_dotnet.php (limited to 'include/random_compat/random_bytes_com_dotnet.php') diff --git a/include/random_compat/random_bytes_com_dotnet.php b/include/random_compat/random_bytes_com_dotnet.php new file mode 100644 index 000000000..342282549 --- /dev/null +++ b/include/random_compat/random_bytes_com_dotnet.php @@ -0,0 +1,81 @@ +GetRandom($bytes, 0)); + if (RandomCompat_strlen($buf) >= $bytes) { + /** + * Return our random entropy buffer here: + */ + return RandomCompat_substr($buf, 0, $bytes); + } + ++$execCount; + } while ($execCount < $bytes); + + /** + * If we reach here, PHP has failed us. + */ + throw new Exception( + 'Could not gather sufficient random data' + ); +} -- cgit v1.2.3