pajoye Tue Jul 15 17:04:18 2008 UTC
Modified files:
/php-src/ext/mcrypt config.w32 mcrypt.c
Log:
- 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.3&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.3
--- 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:04:17 2008
@@ -1,4 +1,4 @@
-// $Id: config.w32,v 1.2 2004/01/18 19:21:23 derick Exp $
+// $Id: config.w32,v 1.3 2008/07/15 17:04:17 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);
http://cvs.php.net/viewvc.cgi/php-src/ext/mcrypt/mcrypt.c?r1=1.112&r2=1.113&diff_format=u
Index: php-src/ext/mcrypt/mcrypt.c
diff -u php-src/ext/mcrypt/mcrypt.c:1.112 php-src/ext/mcrypt/mcrypt.c:1.113
--- php-src/ext/mcrypt/mcrypt.c:1.112 Tue Jul 1 19:44:18 2008
+++ php-src/ext/mcrypt/mcrypt.c Tue Jul 15 17:04:17 2008
@@ -16,7 +16,7 @@
| Derick Rethans <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: mcrypt.c,v 1.112 2008/07/01 19:44:18 felipe Exp $ */
+/* $Id: mcrypt.c,v 1.113 2008/07/15 17:04:17 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"
@@ -1199,9 +1204,6 @@
/* {{{ php_mcrypt_iv */
int php_mcrypt_iv(php_mcrypt_iv_source source, int size, char **iv_str, int
*iv_len TSRMLS_DC)
{
- int fd, n;
- size_t read_bytes;
-
if (size <= 0 || size >= INT_MAX) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can not create an
IV with a size of less then 1 or greater then %d", INT_MAX);
return FAILURE;
@@ -1211,9 +1213,27 @@
switch (source) {
case PHP_MCRYPT_IV_SOURCE_RANDOM:
- case PHP_MCRYPT_IV_SOURCE_URANDOM:
- read_bytes = 0;
-
+ case PHP_MCRYPT_IV_SOURCE_URANDOM: {
+#if PHP_WIN32
+ /* random/urandom equivalent on Windows */
+ HCRYPTPROV hCryptProv;
+ BYTE *iv = (BYTE *) *iv_str;
+
+ /* 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 FAILURE;
+ }
+ if(!CryptGenRandom(hCryptProv, size, iv)) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
"Could not gather sufficient random data");
+ return FAILURE;
+ }
+ *iv_len = size;
+#else
+ size_t read_bytes = 0;
+ int fd;
+
fd = open(source == PHP_MCRYPT_IV_SOURCE_RANDOM ?
"/dev/random" : "/dev/urandom", O_RDONLY);
if (fd < 0) {
efree(*iv_str);
@@ -1236,7 +1256,9 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"Could not gather sufficient random data");
return FAILURE;
}
+#endif
break;
+ }
case PHP_MCRYPT_IV_SOURCE_RAND:
*iv_len = size;
while (size) {
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php