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_dev_urandom.php | 148 +++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 include/random_compat/random_bytes_dev_urandom.php (limited to 'include/random_compat/random_bytes_dev_urandom.php') diff --git a/include/random_compat/random_bytes_dev_urandom.php b/include/random_compat/random_bytes_dev_urandom.php new file mode 100644 index 000000000..db93b0757 --- /dev/null +++ b/include/random_compat/random_bytes_dev_urandom.php @@ -0,0 +1,148 @@ + 0); + + /** + * Is our result valid? + */ + if ($buf !== false) { + if (RandomCompat_strlen($buf) === $bytes) { + /** + * Return our random entropy buffer here: + */ + return $buf; + } + } + } + + /** + * If we reach here, PHP has failed us. + */ + throw new Exception( + 'Error reading from source device' + ); +} -- cgit v1.2.3