-
-#else
-
-#ifndef NAME_DEV_URANDOM
-#define NAME_DEV_URANDOM "/dev/urandom"
-#endif
-
-static gboolean egd = FALSE;
-static gint file = -1;
-
-MonoBoolean
-ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen (void)
-{
- if (egd || (file >= 0))
- return TRUE;
-
-#if defined (NAME_DEV_URANDOM)
- file = open (NAME_DEV_URANDOM, O_RDONLY);
-#endif
-
-#if defined (NAME_DEV_RANDOM)
- if (file < 0)
- file = open (NAME_DEV_RANDOM, O_RDONLY);
-#endif
-
- if (file < 0) {
- const char *socket_path = g_getenv("MONO_EGD_SOCKET");
- egd = (socket_path != NULL);
- }
-
- /* 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 ((!egd && (file < 0)) ? NULL : GINT_TO_POINTER (file));
-}
-
-gpointer
-ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpointer handle, MonoArray *arry)
-{
- gint file = GPOINTER_TO_INT (handle);
- guint32 len = mono_array_length (arry);
- guchar *buf = mono_array_addr (arry, guchar, 0);
-
- if (egd) {
- const char *socket_path = g_getenv ("MONO_EGD_SOCKET");
- /* exception will be thrown in managed code */
- if (socket_path == NULL)
- return NULL;
- get_entropy_from_server (socket_path, mono_array_addr (arry, guchar, 0), mono_array_length (arry));
- return (gpointer) -1;
- } else {
- /* Read until the buffer is filled. This may block if using NAME_DEV_RANDOM. */
- gint count = 0;
- gint err;
-
- do {
- err = read (file, buf + count, len - count);
- if (err < 0) {
- if (errno == EINTR)
- continue;
- break;
- }
- count += err;
- } while (count < len);
-
- if (err < 0) {
- g_warning("Entropy error! Error in read (%s).", strerror (errno));
- /* exception will be thrown in managed code */
- return NULL;
- }
- }
-
- /* We do not support PRNG seeding right now but the class library is this */
-
- return handle;
-}
-
-void
-ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpointer handle)
-{
-}
-
-#endif /* OS definition */