#include <WinCrypt.h>
+#ifndef PROV_INTEL_SEC
+#define PROV_INTEL_SEC 22
+#endif
+#ifndef CRYPT_VERIFY_CONTEXT
+#define CRYPT_VERIFY_CONTEXT 0xF0000000
+#endif
+
gpointer
ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (MonoArray *seed)
{
http://blogs.msdn.com/dangriff/archive/2003/11/19/51709.aspx */
/* We first try to use the Intel PIII RNG if drivers are present */
- if (!CryptAcquireContext (&provider, NULL, NULL, INTEL_DEF_PROV, CRYPT_VERIFY_CONTEXT)) {
- /* not a PIII or no drivers available, use default RSA CSP */\r
+ if (!CryptAcquireContext (&provider, NULL, NULL, PROV_INTEL_SEC, CRYPT_VERIFY_CONTEXT)) {
+ /* not a PIII or no drivers available, use default RSA CSP */
if (!CryptAcquireContext (&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFY_CONTEXT)) {
provider = 0;
- /* exception will be thrown in managed code */\r
+ /* exception will be thrown in managed code */
}
}
}
}
- return (gpointer) provider; \r
+ return (gpointer) provider;
}
-\r
+
gpointer
ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpointer handle, MonoArray *arry)
{
guchar *buf = mono_array_addr (arry, guchar, 0);
if (!CryptGenRandom (provider, len, buf)) {
- CryptReleaseContext (provider);
+ CryptReleaseContext (provider, 0);
/* we may have lost our context with CryptoAPI, but all hope isn't lost yet! */
provider = ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (NULL);
if (!CryptGenRandom (provider, len, buf)) {
- CryptReleaseContext (provider);
+ CryptReleaseContext (provider, 0);
provider = 0;
- /* exception will be thrown in managed code */\r
+ /* exception will be thrown in managed code */
}
}
}
void
ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpointer handle)
{
- CryptReleaseContext ((HCRYPTPROV) handle);
+ CryptReleaseContext ((HCRYPTPROV) handle, 0);
}
#else
return -1;
}
- /* if required exception will be thrown in managed code */\r
+ /* if required exception will be thrown in managed code */
return ((file < 0) ? NULL : (gpointer) file);
}
guchar *buf = mono_array_addr (arry, guchar, 0);
if (egd) {
- const char *socket_path = getenv ("MONO_EGD_SOCKET");
+ const char *socket_path = g_getenv ("MONO_EGD_SOCKET");
/* exception will be thrown in managed code */
if (socket_path == NULL)
return NULL;
if (err < 0) {
g_warning("Entropy error! Error in read (%s).", strerror (errno));
- /* exception will be thrown in managed code */\r
+ /* exception will be thrown in managed code */
return NULL;
}
}