#include <mono/metadata/rand.h>
#include <mono/metadata/exception.h>
-#if defined(__native_client__)
-#include <errno.h>
-
-static void
-get_entropy_from_server (const char *path, guchar *buf, int len)
-{
- return;
-}
-
-#else /* defined(__native_client__) */
-
-#if !defined(HOST_WIN32)
+#if !defined(__native_client__) && !defined(HOST_WIN32)
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
close (file);
}
#endif
-#endif /* __native_client__ */
#if defined (HOST_WIN32)
CryptReleaseContext ((HCRYPTPROV) handle, 0);
}
+#elif defined (__native_client__)
+
+#include <time.h>
+
+MonoBoolean
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen (void)
+{
+ srand (time (NULL));
+ return TRUE;
+}
+
+gpointer
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (MonoArray *seed)
+{
+ return -1;
+}
+
+gpointer
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpointer handle, MonoArray *arry)
+{
+ guint32 len = mono_array_length (arry);
+ guchar *buf = mono_array_addr (arry, guchar, 0);
+
+ /* Read until the buffer is filled. This may block if using NAME_DEV_RANDOM. */
+ gint count = 0;
+ gint err;
+
+ do {
+ if (len - count >= sizeof (long))
+ {
+ *(long*)buf = rand();
+ count += sizeof (long);
+ }
+ else if (len - count >= sizeof (short))
+ {
+ *(short*)buf = rand();
+ count += sizeof (short);
+ }
+ else if (len - count >= sizeof (char))
+ {
+ *buf = rand();
+ count += sizeof (char);
+ }
+ } while (count < len);
+
+ return (gpointer)-1L;
+}
+
+void
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpointer handle)
+{
+}
#else
#ifndef NAME_DEV_URANDOM