32
32
#endif
33
33
34
34
#include < windows.h>
35
- #include < wincrypt .h>
35
+ #include < bcrypt .h>
36
36
#include < objbase.h>
37
37
#include < stdio.h>
38
38
@@ -45,33 +45,8 @@ namespace Firebird {
45
45
46
46
void GenerateRandomBytes (void * buffer, FB_SIZE_T size)
47
47
{
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" );
75
50
}
76
51
77
52
void GenerateGuid (UUID* guid)
0 commit comments