summaryrefslogtreecommitdiff
path: root/ext/standard/uniqid.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/uniqid.c')
-rw-r--r--ext/standard/uniqid.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/standard/uniqid.c b/ext/standard/uniqid.c
index 3671cc3213..0dc9098af0 100644
--- a/ext/standard/uniqid.c
+++ b/ext/standard/uniqid.c
@@ -32,6 +32,7 @@
#endif
#include "php_lcg.h"
+#include "php_random.h"
#ifdef HAVE_GETTIMEOFDAY
ZEND_TLS struct timeval prev_tv = { 0, 0 };
@@ -40,7 +41,7 @@ ZEND_TLS struct timeval prev_tv = { 0, 0 };
PHP_FUNCTION(uniqid)
{
char *prefix = "";
- zend_bool more_entropy = 0;
+ bool more_entropy = 0;
zend_string *uniqid;
int sec, usec;
size_t prefix_len = 0;
@@ -71,7 +72,14 @@ PHP_FUNCTION(uniqid)
* digits for usecs.
*/
if (more_entropy) {
- uniqid = strpprintf(0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg() * 10);
+ uint32_t bytes;
+ double seed;
+ if (php_random_bytes_silent(&bytes, sizeof(uint32_t)) == FAILURE) {
+ seed = php_combined_lcg() * 10;
+ } else {
+ seed = ((double) bytes / UINT32_MAX) * 10.0;
+ }
+ uniqid = strpprintf(0, "%s%08x%05x%.8F", prefix, sec, usec, seed);
} else {
uniqid = strpprintf(0, "%s%08x%05x", prefix, sec, usec);
}