From 5fb257074253f2439ddeb6d789bfca39d4937a9e Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Sun, 10 Jul 2011 14:59:33 +0000 Subject: [PATCH] - use php_win32_get_random_bytes instead of over slow and partially wrong openssl's version --- ext/openssl/openssl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index a36a523bff..06473744b3 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -36,6 +36,10 @@ #include "ext/standard/md5.h" #include "ext/standard/base64.h" +#if PHP_WIN32 +# include "win32/winutil.h" +#endif + /* OpenSSL includes */ #include #include @@ -4920,10 +4924,19 @@ PHP_FUNCTION(openssl_random_pseudo_bytes) buffer = emalloc(buffer_length + 1); +#ifdef PHP_WIN32 + strong_result = 1; + /* random/urandom equivalent on Windows */ + if (php_win32_get_random_bytes(buffer, (size_t) buffer_length) == FAILURE){ + efree(buffer); + RETURN_FALSE; + } +#else if ((strong_result = RAND_pseudo_bytes(buffer, buffer_length)) < 0) { efree(buffer); RETURN_FALSE; } +#endif buffer[buffer_length] = 0; RETVAL_STRINGL((char *)buffer, buffer_length, 0); -- 2.40.0