3232#endif
3333
3434#include < windows.h>
35- #include < wincrypt .h>
35+ #include < bcrypt .h>
3636#include < objbase.h>
3737#include < stdio.h>
3838
@@ -45,33 +45,8 @@ namespace Firebird {
4545
4646void GenerateRandomBytes (void * buffer, FB_SIZE_T size)
4747{
48- HCRYPTPROV hProv;
49-
50- // Acquire crypto-provider context handle.
51- if (! CryptAcquireContext (&hProv, NULL , NULL , PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
52- {
53- if (GetLastError () == NTE_BAD_KEYSET)
54- {
55- // A common cause of this error is that the key container does not exist.
56- // To create a key container, call CryptAcquireContext
57- // using the CRYPT_NEWKEYSET flag.
58- if (! CryptAcquireContext (&hProv, NULL , NULL , PROV_RSA_FULL,
59- CRYPT_VERIFYCONTEXT | CRYPT_NEWKEYSET))
60- {
61- Firebird::system_call_failed::raise (" CryptAcquireContext" );
62- }
63- }
64- else
65- {
66- Firebird::system_call_failed::raise (" CryptAcquireContext" );
67- }
68- }
69-
70- if (! CryptGenRandom (hProv, size, static_cast <UCHAR*>(buffer)))
71- {
72- Firebird::system_call_failed::raise (" CryptGenRandom" );
73- }
74- CryptReleaseContext (hProv, 0 );
48+ if (BCryptGenRandom (nullptr , static_cast <UCHAR*>(buffer), size, BCRYPT_USE_SYSTEM_PREFERRED_RNG) != S_OK)
49+ Firebird::system_call_failed::raise (" BCryptGenRandom" );
7550}
7651
7752void GenerateGuid (UUID* guid)
0 commit comments