Patch for bug #62532 implemention of a kqueue/kevent based FileSystemWatcher.
[mono.git] / mono / metadata / rand.c
index e4bfab72f5b930dc145c10aed48f80f2ceaf3d57..ebe4d634f6da41876052b8f7ee8ff87e7f820daa 100644 (file)
@@ -96,6 +96,13 @@ get_entropy_from_server (const char *path, guchar *buf, int len)
 
 #include <WinCrypt.h>
 
+#ifndef PROV_INTEL_SEC
+#define PROV_INTEL_SEC         22
+#endif
+#ifndef CRYPT_VERIFY_CONTEXT
+#define CRYPT_VERIFY_CONTEXT   0xF0000000
+#endif
+
 gpointer
 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (MonoArray *seed)
 {
@@ -106,11 +113,11 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (M
           http://blogs.msdn.com/dangriff/archive/2003/11/19/51709.aspx */
 
        /* We first try to use the Intel PIII RNG if drivers are present */
-       if (!CryptAcquireContext (&provider, NULL, NULL, INTEL_DEF_PROV, CRYPT_VERIFY_CONTEXT)) {
-               /* not a PIII or no drivers available, use default RSA CSP */\r
+       if (!CryptAcquireContext (&provider, NULL, NULL, PROV_INTEL_SEC, CRYPT_VERIFY_CONTEXT)) {
+               /* not a PIII or no drivers available, use default RSA CSP */
                if (!CryptAcquireContext (&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFY_CONTEXT)) {
                        provider = 0;
-                       /* exception will be thrown in managed code */\r
+                       /* exception will be thrown in managed code */
                }
        }
 
@@ -131,9 +138,9 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (M
                }
        }
 
-       return (gpointer) provider;     \r
+       return (gpointer) provider;     
 }
-\r
+
 gpointer
 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpointer handle, MonoArray *arry)
 {
@@ -142,13 +149,13 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpo
        guchar *buf = mono_array_addr (arry, guchar, 0);
 
        if (!CryptGenRandom (provider, len, buf)) {
-               CryptReleaseContext (provider);
+               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);
                if (!CryptGenRandom (provider, len, buf)) {
-                       CryptReleaseContext (provider);
+                       CryptReleaseContext (provider, 0);
                        provider = 0;
-                       /* exception will be thrown in managed code */\r
+                       /* exception will be thrown in managed code */
                }
        } 
 }
@@ -156,7 +163,7 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpo
 void
 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpointer handle) 
 {
-       CryptReleaseContext ((HCRYPTPROV) handle);
+       CryptReleaseContext ((HCRYPTPROV) handle, 0);
 }
 
 #else
@@ -190,7 +197,7 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (M
                return -1;
        }
 
-       /* if required exception will be thrown in managed code */\r
+       /* if required exception will be thrown in managed code */
        return ((file < 0) ? NULL : (gpointer) file);
 }
 
@@ -202,7 +209,7 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpo
        guchar *buf = mono_array_addr (arry, guchar, 0);
 
        if (egd) {
-               const char *socket_path = getenv ("MONO_EGD_SOCKET");
+               const char *socket_path = g_getenv ("MONO_EGD_SOCKET");
                /* exception will be thrown in managed code */
                if (socket_path == NULL)
                        return NULL; 
@@ -221,7 +228,7 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpo
 
                if (err < 0) {
                        g_warning("Entropy error! Error in read (%s).", strerror (errno));
-                       /* exception will be thrown in managed code */\r
+                       /* exception will be thrown in managed code */
                        return NULL;
                }
        }