2 * rand.c: System.Security.Cryptography.RNGCryptoServiceProvider support
5 * Mark Crichton (crichton@gimp.org)
7 * (C) 2001 Ximian, Inc.
12 /* Ok, the exception handling is bogus. I need to work on that */
16 #include <sys/types.h>
21 #include <mono/metadata/object.h>
22 #include <mono/metadata/rand.h>
23 #include <mono/metadata/exception.h>
25 #if defined (NAME_DEV_RANDOM) && defined (HAVE_CRYPT_RNG)
28 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes (MonoObject *self, MonoArray *arry)
35 len = mono_array_length(arry);
36 buf = mono_array_addr(arry, guchar, 0);
38 file = open(NAME_DEV_RANDOM, O_RDONLY);
41 g_warning("Entropy problem! Can't open %s", NAME_DEV_RANDOM);
43 /* This needs to be a crypto exception */
44 mono_raise_exception(mono_get_exception_not_implemented());
47 /* A little optimization.... */
48 err = read(file, buf, len);
51 g_warning("Entropy error! Error in read.");
52 mono_raise_exception(mono_get_exception_not_implemented());
56 g_warning("Entropy error! Length != bytes read");
57 mono_raise_exception(mono_get_exception_not_implemented());
64 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes (MonoObject *self, MonoArray *arry)
71 len = mono_array_length(arry);
73 file = open(NAME_DEV_RANDOM, O_RDONLY);
76 g_warning("Entropy problem! Can't open %s", NAME_DEV_RANDOM);
78 /* This needs to be a crypto exception */
79 mono_raise_exception(mono_get_exception_not_implemented());
82 for (i = 0; i < len; i++) {
85 err = read(file, &byte, 1);
89 g_warning("Entropy error! Error in read.");
90 mono_raise_exception(mono_get_exception_not_implemented());
93 mono_array_set(arry, guchar, i, byte);
99 /* This needs to change when I do the Win32 support... */
101 #warning "No Entropy Source Found"
102 void ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes(MonoObject *self, MonoArray *arry)
104 g_warning("0K problem. We have no entropy. Badness will occur.");
105 mono_raise_exception(mono_get_exception_not_implemented());
108 void ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes(MonoObject *self, MonoArray *arry)
110 g_warning("0K problem. We have no entropy. Badness will occur.");
111 mono_raise_exception(mono_get_exception_not_implemented());