* Sebastien Pouliot (sebastien@ximian.com)
*
* (C) 2001 Ximian, Inc.
- * (C) 2004 Novell (http://www.novell.com)
+ * Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
*/
#include <config.h>
#if defined (PLATFORM_WIN32)
-#include <WinCrypt.h>
+#include <windows.h>
+#include <wincrypt.h>
#ifndef PROV_INTEL_SEC
#define PROV_INTEL_SEC 22
#define CRYPT_VERIFY_CONTEXT 0xF0000000
#endif
+MonoBoolean
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen (void)
+{
+ /* FALSE == Local (instance) handle for randomness */
+ return FALSE;
+}
+
gpointer
ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (MonoArray *seed)
{
if (!CryptGenRandom (provider, len, buf)) {
CryptReleaseContext (provider, 0);
/* we may have lost our context with CryptoAPI, but all hope isn't lost yet! */
- provider = ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (NULL);
+ provider = (HCRYPTPROV) ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (NULL);
if (!CryptGenRandom (provider, len, buf)) {
CryptReleaseContext (provider, 0);
provider = 0;
/* exception will be thrown in managed code */
}
- }
+ }
+ return (gpointer) provider;
}
void
#endif
static gboolean egd = FALSE;
+static gint file = -1;
-gpointer
-ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (MonoArray *seed)
+MonoBoolean
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen (void)
{
- gint file = -1;
-
- if (egd)
- return (gpointer) -1;
+ if (egd || (file >= 0))
+ return TRUE;
#if defined (NAME_DEV_URANDOM)
file = open (NAME_DEV_URANDOM, O_RDONLY);
if (file < 0) {
const char *socket_path = g_getenv("MONO_EGD_SOCKET");
egd = (socket_path != NULL);
- return (gpointer) -1;
}
+ /* TRUE == Global handle for randomness */
+ return TRUE;
+}
+
+gpointer
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (MonoArray *seed)
+{
/* if required exception will be thrown in managed code */
- return ((file < 0) ? NULL : GINT_TO_POINTER (file));
+ return ((!egd && (file < 0)) ? NULL : GINT_TO_POINTER (file));
}
gpointer
void
ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpointer handle)
{
- if (!egd)
- close (GPOINTER_TO_INT (handle));
}
#endif /* OS definition */