pajoye          Tue Jul 15 17:05:02 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/mcrypt config.w32 mcrypt.c 
  Log:
  - MFH: Port mcrypt_create_iv to windows (aka fix it on windows)
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mcrypt/config.w32?r1=1.2&r2=1.2.8.1&diff_format=u
Index: php-src/ext/mcrypt/config.w32
diff -u php-src/ext/mcrypt/config.w32:1.2 php-src/ext/mcrypt/config.w32:1.2.8.1
--- php-src/ext/mcrypt/config.w32:1.2   Sun Jan 18 19:21:23 2004
+++ php-src/ext/mcrypt/config.w32       Tue Jul 15 17:05:02 2008
@@ -1,4 +1,4 @@
-// $Id: config.w32,v 1.2 2004/01/18 19:21:23 derick Exp $
+// $Id: config.w32,v 1.2.8.1 2008/07/15 17:05:02 pajoye Exp $
 // vim:ft=javascript
 
 ARG_WITH("mcrypt", "mcrypt support", "no");
@@ -6,7 +6,9 @@
 if (PHP_MCRYPT != "no") {
 
        if (CHECK_HEADER_ADD_INCLUDE('mcrypt.h', 'CFLAGS_MCRYPT') &&
-                       CHECK_LIB('libmcrypt.lib', 'mcrypt')) {
+                       CHECK_LIB('libmcrypt.lib', 'mcrypt') &&
+                       CHECK_LIB('Advapi32.lib', 'mcrypt')
+                       ) {
                EXTENSION('mcrypt', 'mcrypt.c');
                AC_DEFINE('HAVE_LIBMCRYPT', 1);
                AC_DEFINE('HAVE_LIBMCRYPT24', 1);
@@ -14,4 +16,3 @@
                WARNING("mcrypt not enabled; libraries and headers not found");
        }
 }
-
http://cvs.php.net/viewvc.cgi/php-src/ext/mcrypt/mcrypt.c?r1=1.91.2.3.2.11.2.9&r2=1.91.2.3.2.11.2.10&diff_format=u
Index: php-src/ext/mcrypt/mcrypt.c
diff -u php-src/ext/mcrypt/mcrypt.c:1.91.2.3.2.11.2.9 
php-src/ext/mcrypt/mcrypt.c:1.91.2.3.2.11.2.10
--- php-src/ext/mcrypt/mcrypt.c:1.91.2.3.2.11.2.9       Fri Jul  4 07:47:18 2008
+++ php-src/ext/mcrypt/mcrypt.c Tue Jul 15 17:05:02 2008
@@ -16,7 +16,7 @@
    |          Derick Rethans <[EMAIL PROTECTED]>                    |
    +----------------------------------------------------------------------+
  */
-/* $Id: mcrypt.c,v 1.91.2.3.2.11.2.9 2008/07/04 07:47:18 derick Exp $ */
+/* $Id: mcrypt.c,v 1.91.2.3.2.11.2.10 2008/07/15 17:05:02 pajoye Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -26,6 +26,11 @@
 
 #if HAVE_LIBMCRYPT
 
+#if PHP_WIN32
+# include <Wincrypt.h>
+# include <Ntsecapi.h>
+#endif
+
 #include "php_mcrypt.h"
 #include "fcntl.h"
 
@@ -1452,6 +1457,23 @@
        iv = ecalloc(size + 1, 1);
        
        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)) {
+                               php_error_docref(NULL TSRMLS_CC, E_ERROR, 
"Cannot open random device");
+                               RETURN_FALSE;
+                       }
+                       if(!CryptGenRandom(hCryptProv, size,  iv_b)) {
+                               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;
 
@@ -1475,6 +1497,7 @@
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not 
gather sufficient random data");
                        RETURN_FALSE;
                }
+#endif
        } else {
                n = size;
                while (size) {



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

Reply via email to