1 /**
2  * \file
3  * System.Security.Cryptography.RNGCryptoServiceProvider support
4  *
5  * Authors:
6  *      Mark Crichton (crichton@gimp.org)
7  *      Patrik Torstensson (p@rxc.se)
8  *	Sebastien Pouliot (sebastien@ximian.com)
9  *
10  * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
11  * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
12  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
13  */
14 
15 #include <config.h>
16 #include <glib.h>
17 
18 #include "object.h"
19 #include "object-internals.h"
20 #include "rand.h"
21 #include "utils/mono-rand.h"
22 
23 MonoBoolean
ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen(void)24 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen (void)
25 {
26 	return (MonoBoolean) mono_rand_open ();
27 }
28 
29 gpointer
ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize(MonoArray * seed)30 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (MonoArray *seed)
31 {
32 
33 	return mono_rand_init (seed ? mono_array_addr (seed, guchar, 0) : NULL, seed ? mono_array_length (seed) : 0);
34 }
35 
36 gpointer
ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes(gpointer handle,MonoArray * arry)37 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpointer handle, MonoArray *arry)
38 {
39 	MonoError error;
40 	g_assert (arry);
41 	mono_rand_try_get_bytes (&handle, mono_array_addr (arry, guchar, 0), mono_array_length (arry), &error);
42 	mono_error_set_pending_exception (&error);
43 	return handle;
44 }
45 
46 void
ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose(gpointer handle)47 ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpointer handle)
48 {
49 	mono_rand_close (handle);
50 }
51