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