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)
27 void ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes(MonoArray *arry)
34 len = mono_array_length(arry);
35 buf = mono_array_addr(arry, guchar, 0);
37 file = open(NAME_DEV_RANDOM, O_RDONLY);
40 g_warning("Entropy problem! Can't open %s", NAME_DEV_RANDOM);
42 /* This needs to be a crypto exception */
43 mono_raise_exception(mono_get_exception_not_implemented());
46 /* A little optimization.... */
47 err = read(file, buf, len);
50 g_warning("Entropy error! Error in read.");
51 mono_raise_exception(mono_get_exception_not_implemented());
55 g_warning("Entropy error! Length != bytes read");
56 mono_raise_exception(mono_get_exception_not_implemented());
62 void ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes(MonoArray *arry)
69 len = mono_array_length(arry);
71 file = open(NAME_DEV_RANDOM, O_RDONLY);
74 g_warning("Entropy problem! Can't open %s", NAME_DEV_RANDOM);
76 /* This needs to be a crypto exception */
77 mono_raise_exception(mono_get_exception_not_implemented());
80 for (i = 0; i < len; i++) {
83 err = read(file, &byte, 1);
87 g_warning("Entropy error! Error in read.");
88 mono_raise_exception(mono_get_exception_not_implemented());
91 mono_array_set(arry, guchar, i, byte);
97 /* This needs to change when I do the Win32 support... */
99 #warning "No Entropy Source Found"
100 void ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes(MonoArray *arry)
102 g_warning("0K problem. We have no entropy. Badness will occur.");
103 mono_raise_exception(mono_get_exception_not_implemented());
106 void ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes(MonoArray *arry)
108 g_warning("0K problem. We have no entropy. Badness will occur.");
109 mono_raise_exception(mono_get_exception_not_implemented());