]> granicus.if.org Git - php/commitdiff
- use php_win32_get_random_bytes instead of over slow and partially wrong openssl...
authorPierre Joye <pajoye@php.net>
Sun, 10 Jul 2011 14:59:33 +0000 (14:59 +0000)
committerPierre Joye <pajoye@php.net>
Sun, 10 Jul 2011 14:59:33 +0000 (14:59 +0000)
ext/openssl/openssl.c

index a36a523bff0880f5e486874fd542ec2245f3fbef..06473744b36202cc4fee1e12659ec0a18801444c 100644 (file)
 #include "ext/standard/md5.h"
 #include "ext/standard/base64.h"
 
+#if PHP_WIN32
+# include "win32/winutil.h"
+#endif
+
 /* OpenSSL includes */
 #include <openssl/evp.h>
 #include <openssl/x509.h>
@@ -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);