Skip to content

Commit 6b4bcc1

Browse files
committed
1 parent 31d3eeb commit 6b4bcc1

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

contrib/guix/symbol-check.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@
153153
}
154154

155155
PE_ALLOWED_LIBRARIES = {
156-
'ADVAPI32.dll', # security & registry
156+
'ADVAPI32.dll', # legacy security & registry
157+
'bcrypt.dll', # newer security and identity API
157158
'IPHLPAPI.DLL', # IP helper API
158159
'KERNEL32.dll', # win32 base APIs
159160
'msvcrt.dll', # C standard library for MSVC

src/kernel/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ target_link_libraries(bitcoinkernel
8787
bitcoin_crypto
8888
leveldb
8989
secp256k1
90+
$<$<PLATFORM_ID:Windows>:bcrypt>
9091
$<TARGET_NAME_IF_EXISTS:USDT::headers>
9192
PUBLIC
9293
Boost::headers

src/random.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
#include <thread>
2828

2929
#ifdef WIN32
30-
#include <windows.h>
31-
#include <wincrypt.h>
30+
#include <bcrypt.h>
3231
#else
3332
#include <fcntl.h>
3433
#include <sys/time.h>
@@ -287,16 +286,15 @@ void Strengthen(const unsigned char (&seed)[32], SteadyClock::duration dur, CSHA
287286
void GetOSRand(unsigned char *ent32)
288287
{
289288
#if defined(WIN32)
290-
HCRYPTPROV hProvider;
291-
int ret = CryptAcquireContextW(&hProvider, nullptr, nullptr, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
292-
if (!ret) {
293-
RandFailure();
294-
}
295-
ret = CryptGenRandom(hProvider, NUM_OS_RANDOM_BYTES, ent32);
296-
if (!ret) {
289+
constexpr uint32_t STATUS_SUCCESS{0x00000000};
290+
NTSTATUS status = BCryptGenRandom(/*hAlgorithm=*/NULL,
291+
/*pbBuffer=*/ent32,
292+
/*cbBuffer=*/NUM_OS_RANDOM_BYTES,
293+
/*dwFlags=*/BCRYPT_USE_SYSTEM_PREFERRED_RNG);
294+
295+
if (status != STATUS_SUCCESS) {
297296
RandFailure();
298297
}
299-
CryptReleaseContext(hProvider, 0);
300298
#elif defined(HAVE_GETRANDOM)
301299
/* Linux. From the getrandom(2) man page:
302300
* "If the urandom source has been initialized, reads of up to 256 bytes

src/util/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ target_link_libraries(bitcoin_util
4343
bitcoin_crypto
4444
$<$<PLATFORM_ID:Windows>:ws2_32>
4545
$<$<PLATFORM_ID:Windows>:iphlpapi>
46+
$<$<PLATFORM_ID:Windows>:bcrypt>
4647
)

0 commit comments

Comments
 (0)