pajoye                                   Tue, 08 Jun 2010 18:27:23 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=300289

Log:
- use new function to get random bytes

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/mcrypt/mcrypt.c
    U   php/php-src/trunk/ext/mcrypt/mcrypt.c

Modified: php/php-src/branches/PHP_5_3/ext/mcrypt/mcrypt.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mcrypt/mcrypt.c    2010-06-08 18:26:03 UTC 
(rev 300288)
+++ php/php-src/branches/PHP_5_3/ext/mcrypt/mcrypt.c    2010-06-08 18:27:23 UTC 
(rev 300289)
@@ -27,8 +27,7 @@
 #if HAVE_LIBMCRYPT

 #if PHP_WIN32
-# include <Wincrypt.h>
-# include <Ntsecapi.h>
+# include "win32/winutil.h"
 #endif

 #include "php_mcrypt.h"
@@ -1391,23 +1390,14 @@

        if (source == RANDOM || source == URANDOM) {
 #if PHP_WIN32
-                       /* random/urandom equivalent on Windows */
-                       HCRYPTPROV     hCryptProv;
-                       BYTE *iv_b = (BYTE *) iv;
-
-                       /* It could be done using LoadLibrary but as we rely on 
2k+ for 5.3, cleaner to use a clear dependency (Advapi32) and a
-                               standard API call (no f=getAddr..; f();) */
-                       if(!CryptAcquireContext(&hCryptProv, NULL, NULL, 
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
-                               efree(iv);
-                               php_error_docref(NULL TSRMLS_CC, E_ERROR, 
"Cannot open random device");
-                               RETURN_FALSE;
-                       }
-                       if(!CryptGenRandom(hCryptProv, size,  iv_b)) {
-                               efree(iv);
-                               php_error_docref(NULL TSRMLS_CC, E_ERROR, 
"Could not gather sufficient random data");
-                               RETURN_FALSE;
-                       }
-                       n = size;
+               /* random/urandom equivalent on Windows */
+               BYTE *iv_b = (BYTE *) iv;
+               if (php_win32_get_random_bytes(iv_b, (size_t) size) == FAILURE){
+                       efree(iv);
+                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not 
gather sufficient random data");
+                       RETURN_FALSE;
+               }
+               n = size;
 #else
                int    fd;
                size_t read_bytes = 0;

Modified: php/php-src/trunk/ext/mcrypt/mcrypt.c
===================================================================
--- php/php-src/trunk/ext/mcrypt/mcrypt.c       2010-06-08 18:26:03 UTC (rev 
300288)
+++ php/php-src/trunk/ext/mcrypt/mcrypt.c       2010-06-08 18:27:23 UTC (rev 
300289)
@@ -27,8 +27,7 @@
 #if HAVE_LIBMCRYPT

 #if PHP_WIN32
-# include <Wincrypt.h>
-# include <Ntsecapi.h>
+# include "win32/winutil.h"
 #endif

 #include "php_mcrypt.h"
@@ -1391,23 +1390,14 @@

        if (source == RANDOM || source == URANDOM) {
 #if PHP_WIN32
-                       /* random/urandom equivalent on Windows */
-                       HCRYPTPROV     hCryptProv;
-                       BYTE *iv_b = (BYTE *) iv;
-
-                       /* It could be done using LoadLibrary but as we rely on 
2k+ for 5.3, cleaner to use a clear dependency (Advapi32) and a
-                               standard API call (no f=getAddr..; f();) */
-                       if(!CryptAcquireContext(&hCryptProv, NULL, NULL, 
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
-                               efree(iv);
-                               php_error_docref(NULL TSRMLS_CC, E_ERROR, 
"Cannot open random device");
-                               RETURN_FALSE;
-                       }
-                       if(!CryptGenRandom(hCryptProv, size,  iv_b)) {
-                               efree(iv);
-                               php_error_docref(NULL TSRMLS_CC, E_ERROR, 
"Could not gather sufficient random data");
-                               RETURN_FALSE;
-                       }
-                       n = size;
+               /* random/urandom equivalent on Windows */
+               BYTE *iv_b = (BYTE *) iv;
+               if (php_win32_get_random_bytes(iv_b, (size_t) size) == FAILURE){
+                       efree(iv);
+                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not 
gather sufficient random data");
+                       RETURN_FALSE;
+               }
+               n = size;
 #else
                int    fd;
                size_t read_bytes = 0;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to