summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2010-10-21 08:52:46 +0200
committerOndřej Surý <ondrej@sury.org>2010-10-21 08:52:46 +0200
commit01fcdff3849c3691d9aaeaab735846ab6d8895ca (patch)
tree6460876d356113fa7053df36f2aa00baa7db24a9 /win32
parent855a09f4eded707941180c9d90acd17c25e29447 (diff)
downloadphp-01fcdff3849c3691d9aaeaab735846ab6d8895ca.tar.gz
Imported Upstream version 5.3.3upstream/5.3.3
Diffstat (limited to 'win32')
-rw-r--r--win32/winutil.c38
-rw-r--r--win32/winutil.h1
2 files changed, 37 insertions, 2 deletions
diff --git a/win32/winutil.c b/win32/winutil.c
index 7845f8900..0dbcddfc1 100644
--- a/win32/winutil.c
+++ b/win32/winutil.c
@@ -12,13 +12,15 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Author: |
+ | Author: Zeev Suraski <zeev@zend.com> |
+ * Pierre Joye <pierre@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: winutil.c 294726 2010-02-07 20:45:46Z pajoye $ */
+/* $Id: winutil.c 300273 2010-06-08 13:00:11Z pajoye $ */
#include "php.h"
+#include <wincrypt.h>
PHPAPI char *php_win_err(int error)
{
@@ -46,3 +48,35 @@ int php_win32_check_trailing_space(const char * path, const int path_len) {
return 0;
}
}
+
+PHPAPI int php_win32_get_random_bytes(unsigned char *buf, size_t size) { /* {{{ */
+ HCRYPTPROV hCryptProv;
+ int has_context = 0;
+ BOOL ret;
+ size_t i = 0;
+
+ if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)) {
+ /* Could mean that the key container does not exist, let try
+ again by asking for a new one */
+ if (GetLastError() == NTE_BAD_KEYSET) {
+ if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
+ has_context = 1;
+ } else {
+ return FAILURE;
+ }
+ }
+ }
+
+ ret = CryptGenRandom(hCryptProv, size, buf);
+ CryptReleaseContext(hCryptProv, 0);
+ if (ret) {
+ while (i < size && buf[i] != 0) {
+ i++;
+ }
+ if (i == size) {
+ return SUCCESS;
+ }
+ }
+ return FAILURE;
+}
+/* }}} */
diff --git a/win32/winutil.h b/win32/winutil.h
index 8ee75752d..5f8efe0a9 100644
--- a/win32/winutil.h
+++ b/win32/winutil.h
@@ -20,3 +20,4 @@ PHPAPI char *php_win_err(int error);
#define php_win_err() php_win_err(GetLastError())
int php_win32_check_trailing_space(const char * path, const int path_len);
+PHPAPI php_win32_get_random_bytes(unsigned char *buf, size_t size);