[Mono-list] System.Security.Cryptography.RNGCryptoServiceProvider

Mark Crichton crichton@gimp.org
Fri, 15 Feb 2002 16:11:24 -0500


--5/uDoXvLw7AC5HRs
Content-Type: multipart/mixed; boundary="k+w/mQv8wyuph6w0"
Content-Disposition: inline


--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello,

Attached is a patch to handle the GetBytes and GetNonZeroBytes methods
in S.S.C.RNGCryptoServiceProvider.

As soon as my C# book comes in, I can flesh out the rest of the classes
in corlib.

If anyone has comments on the patch, please let me know.

Thanks,
Mark Crichton

--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="rng.patch"
Content-Transfer-Encoding: quoted-printable

Index: ChangeLog
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/ChangeLog,v
retrieving revision 1.56
diff -u -r1.56 ChangeLog
--- ChangeLog	14 Feb 2002 01:04:34 -0000	1.56
+++ ChangeLog	15 Feb 2002 21:09:15 -0000
@@ -1,3 +1,7 @@
+2002-02-15  Mark Crichton  <crichton@gimp.org>
+
+	* configure.in: Add checks for a system-provided entropy device
+=09
 2002-02-14  Jeffrey Stedfast  <fejj@ximian.com>
=20
 	* configure.in: Add checks to see if we need to link to libsocket,
Index: acconfig.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/acconfig.h,v
retrieving revision 1.6
diff -u -r1.6 acconfig.h
--- acconfig.h	14 Feb 2002 01:04:34 -0000	1.6
+++ acconfig.h	15 Feb 2002 21:09:15 -0000
@@ -7,3 +7,5 @@
 #undef PLATFORM_WIN32
 #undef PLATFORM_WIN32_NATIVE
 #undef HAVE_NEW_ICONV
+#undef NAME_DEV_RANDOM
+#undef HAVE_CRYPT_RNG
Index: configure.in
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/configure.in,v
retrieving revision 1.47
diff -u -r1.47 configure.in
--- configure.in	14 Feb 2002 01:17:20 -0000	1.47
+++ configure.in	15 Feb 2002 21:09:16 -0000
@@ -257,6 +257,71 @@
 	AC_CHECK_LIB(rt, sem_init, LIBS=3D"$LIBS -lrt")
 fi
=20
+dnl ****************************
+dnl *** Look for /dev/random ***
+dnl ****************************
+
+AC_MSG_CHECKING([if usage of random device is requested])
+AC_ARG_ENABLE(dev-random,
+[  --disable-dev-random    disable the use of the random device],
+try_dev_random=3D$enableval, try_dev_random=3Dyes)
+AC_MSG_RESULT($try_dev_random)
+
+case "{$target}" in
+    *-openbsd*)
+    NAME_DEV_RANDOM=3D"/dev/srandom"
+    ;;
+
+dnl Win32 does not have /dev/random, they have their own method...
+
+    *-*-mingw*|*-*-cygwin*)
+    ac_cv_have_dev_random =3D no
+    ;;
+
+dnl Everywhere else, it's /dev/random
+
+    *)
+    NAME_DEV_RANDOM=3D"/dev/random"
+    ;;
+esac
+
+AC_DEFINE_UNQUOTED(NAME_DEV_RANDOM, "$NAME_DEV_RANDOM")
+
+dnl Now check if the device actually exists
+
+if test "x$try_dev_random" =3D "xyes"; then
+    AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
+    [if test -r "$NAME_DEV_RANDOM" ; then
+        ac_cv_have_dev_random=3Dyes; else ac_cv_have_dev_random=3Dno; fi])
+    if test "x$ac_cv_have_dev_random" =3D "xyes"; then
+        AC_DEFINE(HAVE_CRYPT_RNG)
+    fi
+else
+    AC_MSG_CHECKING(for random device)
+    ac_cv_have_dev_random=3Dno
+    AC_MSG_RESULT(has been disabled)
+fi
+
+if test "x$platform_win32" =3D "xyes"; then
+    AC_DEFINE(HAVE_CRYPT_RNG)
+fi
+
+if test "x$ac_cv_have_dev_random" =3D "xno" \
+    && test "x$platform_win32" =3D "xno"; then
+    AC_MSG_WARN([[
+***
+*** A system-provided entropy source was not found on this system.
+*** Because of this, the System.Security.Cryptography random number genera=
tor
+*** will throw a NotImplemented exception.
+***
+*** If you are seeing this message, and you know your system DOES have an
+*** entropy collection in place, please contact <crichton@gimp.org> and
+*** provide information about the system and how to access the random devi=
ce.
+***
+*** For those systems who lack a random device, EGD support is forthcoming.
+***]])
+fi
+=20
 if test "x$cross_compiling" =3D "xno"; then
 # check for new iconv version
 AC_MSG_CHECKING(for new iconv)
Index: mono/metadata/ChangeLog
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/mono/metadata/ChangeLog,v
retrieving revision 1.162
diff -u -r1.162 ChangeLog
--- mono/metadata/ChangeLog	15 Feb 2002 13:24:35 -0000	1.162
+++ mono/metadata/ChangeLog	15 Feb 2002 21:09:17 -0000
@@ -1,4 +1,12 @@
+2002-02-15  Mark Crichton  <crichton@gimp.org>
=20
+	* rand.c, rand.h: Added random number generator for
+	System.Security.Cryptography classes.
+
+	* exception.c, exception.h: Added mono_get_exception_not_implemeted.
+
+	* icall.c: Added System.Security.Cryptography calls.
+=09
 Fri Feb 15 18:15:44 CET 2002 Paolo Molaro <lupus@ximian.com>
=20
 	* reflection.c: handle finally clauses.
Index: mono/metadata/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/mono/metadata/Makefile.am,v
retrieving revision 1.38
diff -u -r1.38 Makefile.am
--- mono/metadata/Makefile.am	8 Feb 2002 07:37:21 -0000	1.38
+++ mono/metadata/Makefile.am	15 Feb 2002 21:09:17 -0000
@@ -38,7 +38,9 @@
 	unicode.c	\
 	unicode.h	\
 	appdomain.h	\
-	appdomain.c
+	appdomain.c	\
+	rand.h		\
+	rand.c
=20
 libmetadataincludedir =3D $(includedir)/mono/metadata
=20
@@ -60,7 +62,8 @@
 	class.h		\
 	object.h	\
 	exception.h	\
-	appdomain.h
+	appdomain.h	\
+	rand.h
=20
 pedump_SOURCES =3D		\
 	pedump.c $(libmetadata_a_SOURCES)
Index: mono/metadata/exception.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/mono/metadata/exception.c,v
retrieving revision 1.6
diff -u -r1.6 exception.c
--- mono/metadata/exception.c	13 Feb 2002 07:44:58 -0000	1.6
+++ mono/metadata/exception.c	15 Feb 2002 21:09:18 -0000
@@ -102,6 +102,13 @@
 }
=20
 MonoException *
+mono_get_exception_not_implemented ()
+{
+	return mono_exception_from_name (mono_defaults.corlib, "System",
+					 "NotImplementedException");
+}
+
+MonoException *
 mono_get_exception_missing_method ()
 {
 	return mono_exception_from_name (mono_defaults.corlib, "System",
Index: mono/metadata/exception.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/mono/metadata/exception.h,v
retrieving revision 1.4
diff -u -r1.4 exception.h
--- mono/metadata/exception.h	13 Feb 2002 07:44:58 -0000	1.4
+++ mono/metadata/exception.h	15 Feb 2002 21:09:18 -0000
@@ -49,6 +49,9 @@
 MonoException *
 mono_get_exception_missing_method      (void);
=20
+MonoException *
+mono_get_exception_not_implemented     (void);
+
 MonoException*
 mono_get_exception_argument_null       (MonoDomain *domain, const guchar *=
arg);
=20
Index: mono/metadata/icall.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mono/mono/metadata/icall.c,v
retrieving revision 1.59
diff -u -r1.59 icall.c
--- mono/metadata/icall.c	14 Feb 2002 14:16:19 -0000	1.59
+++ mono/metadata/icall.c	15 Feb 2002 21:09:21 -0000
@@ -26,6 +26,7 @@
 #include <mono/metadata/tokentype.h>
 #include <mono/metadata/unicode.h>
 #include <mono/metadata/appdomain.h>
+#include <mono/metadata/rand.h>
 #include <mono/io-layer/io-layer.h>
 #include "decimal.h"
=20
@@ -1148,6 +1149,14 @@
 	"System.Text.Encoding::IConvGetChars", ves_icall_iconv_get_chars,
=20
 	"System.DateTime::GetNow", ves_icall_System_DateTime_GetNow,
+
+	/*
+	 * System.Security.Cryptography calls
+	 */
+
+	 "System.Security.Cryptography.RNGCryptoServiceProvider::GetBytes", ves_i=
call_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes,
+	 "System.Security.Cryptography.RNG_CryptoServiceProvider::GetNonZeroBytes=
", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZe=
roBytes,
+
 	/*
 	 * add other internal calls here
 	 */

--k+w/mQv8wyuph6w0--

--5/uDoXvLw7AC5HRs
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (SunOS)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjxteXsACgkQOfj2Ja/u/oCENACdEmYjEpBgtNOQGC7du2LTX1w4
KHIAoJGMF4IhBHMdfIrg2M7JEibhGq26
=xPpy
-----END PGP SIGNATURE-----

--5/uDoXvLw7AC5HRs--