3 * UWP rand support for Mono.
5 * Copyright 2016 Microsoft
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
10 #include "mono/utils/mono-compiler.h"
12 #if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT)
14 #include "mono/utils/mono-rand-windows-internals.h"
16 MONO_WIN32_CRYPT_PROVIDER_HANDLE
17 mono_rand_win_open_provider (void)
19 MONO_WIN32_CRYPT_PROVIDER_HANDLE provider
= 0;
21 if (!BCRYPT_SUCCESS (BCryptOpenAlgorithmProvider (&provider
, BCRYPT_RNG_ALGORITHM
, NULL
, 0)))
28 mono_rand_win_gen (MONO_WIN32_CRYPT_PROVIDER_HANDLE provider
, guchar
*buffer
, size_t buffer_size
)
30 g_assert (provider
!= 0 && buffer
!= 0);
31 return (BCRYPT_SUCCESS (BCryptGenRandom (provider
, buffer
, (ULONG
) buffer_size
, 0))) ? TRUE
: FALSE
;
35 mono_rand_win_seed (MONO_WIN32_CRYPT_PROVIDER_HANDLE provider
, guchar
*seed
, size_t seed_size
)
37 g_assert (provider
!= 0 && seed
!= 0);
38 return (BCRYPT_SUCCESS (BCryptGenRandom (provider
, seed
, (ULONG
) seed_size
, BCRYPT_RNG_USE_ENTROPY_IN_BUFFER
))) ? TRUE
: FALSE
;
42 mono_rand_win_close_provider (MONO_WIN32_CRYPT_PROVIDER_HANDLE provider
)
44 g_assert (provider
!= 0);
45 BCryptCloseAlgorithmProvider (provider
, 0);
48 #else /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */
50 MONO_EMPTY_SOURCE_FILE (mono_rand_windows_uwp
);
51 #endif /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */