2005-03-03 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 3 Mar 2005 16:43:22 +0000 (16:43 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 3 Mar 2005 16:43:22 +0000 (16:43 -0000)
* icall.c: Added new icall for RNG.
* rand.c|h: Added new icall to open the RNG. This allows to share a
single handle on Linux to access /dev/urandom and fix #73183.

svn path=/trunk/mono/; revision=41402

mono/metadata/ChangeLog
mono/metadata/icall.c
mono/metadata/rand.c
mono/metadata/rand.h

index ab91321ba7b9927d20e20c3df8542213265def80..8506da50be3919b045f19de61ed4e2d5efdbf306 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-03  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * icall.c: Added new icall for RNG.
+       * rand.c|h: Added new icall to open the RNG. This allows to share a 
+       single handle on Linux to access /dev/urandom and fix #73183.
 
 Thu Mar 3 17:53:17 CET 2005 Paolo Molaro <lupus@ximian.com>
 
index e6ece4219a50308ed19da162f3fe7186cd1e5545..39add280bad84c56fa21cccc1806a04057d55c21 100644 (file)
@@ -6394,7 +6394,8 @@ static const IcallEntry remotingservices_icalls [] = {
 static const IcallEntry rng_icalls [] = {
        {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
        {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
-       {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize}
+       {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize},
+       {"RngOpen", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen}
 };
 
 static const IcallEntry methodhandle_icalls [] = {
index 10bf22a34ea44b66f6ac77e407b2086027d22385..de373f2d6627981e412aaa0984762436b2a15c20 100644 (file)
@@ -7,7 +7,7 @@
  *     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>
@@ -103,6 +103,13 @@ get_entropy_from_server (const char *path, guchar *buf, int len)
 #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)
 {
@@ -173,14 +180,13 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpoint
 #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);
@@ -194,11 +200,17 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (M
        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 
@@ -241,8 +253,6 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpo
 void
 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpointer handle) 
 {
-       if (!egd)
-               close (GPOINTER_TO_INT (handle));
 }
 
 #endif /* OS definition */
index f06cdd1a1f159ef49652515a650dc5dd661348f6..a0b25e5cd4be6c64792ed947f5489d559ef58bc6 100644 (file)
@@ -6,8 +6,7 @@
  *     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)
  */
 
 #ifndef _MONO_METADATA_RAND_H_
@@ -15,6 +14,7 @@
 
 #include <mono/metadata/object.h>
 
+MonoBoolean ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen (void);
 gpointer ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (MonoArray *seed);
 gpointer ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpointer handle, MonoArray *arry);
 void ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpointer handle);