wrowe 02/05/29 15:07:59
Modified: misc/win32 rand.c
Log:
Fix apr_generate_random_bytes() for Win32 on Win NT or 9x by
dropping the 0x40 bit (CRYPT_SILENT) for earlier OS'es.
Thanks for nagging Mr. Trawick :)
PR: 9286
Revision Changes Path
1.14 +6 -2 apr/misc/win32/rand.c
Index: rand.c
===================================================================
RCS file: /home/cvs/apr/misc/win32/rand.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- rand.c 13 Mar 2002 20:39:23 -0000 1.13
+++ rand.c 29 May 2002 22:07:58 -0000 1.14
@@ -54,6 +54,7 @@
#include "apr_private.h"
#include "apr_general.h"
+#include "misc.h"
#include <wincrypt.h>
APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf,
@@ -63,9 +64,12 @@
apr_status_t res = APR_SUCCESS;
/* 0x40 bit = CRYPT_SILENT, only introduced in more recent PSDKs
+ * and will only work for Win2K and later.
*/
- if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
- CRYPT_VERIFYCONTEXT | 0x40)) {
+ DWORD flags = CRYPT_VERIFYCONTEXT
+ | ((apr_os_level >= APR_WIN_2000) ? 0x40 : 0);
+
+ if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, flags)) {
return apr_get_os_error();
}
if (!CryptGenRandom(hProv, length, buf)) {