Skip to content

rand: use BCryptGenRandom() in UWP builds#20983

Closed
vszakats wants to merge 2 commits intocurl:masterfrom
vszakats:uwp-use-bcrypt
Closed

rand: use BCryptGenRandom() in UWP builds#20983
vszakats wants to merge 2 commits intocurl:masterfrom
vszakats:uwp-use-bcrypt

Conversation

@vszakats
Copy link
Copy Markdown
Member

@vszakats vszakats commented Mar 18, 2026

Also:

  • fix build configuration to correctly set Win10 target in the mingw-w64
    CI build, to enable the BCryptGenRandom() prototype in v6+ SDK
    headers.

Ref: https://learn.microsoft.com/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom

Issue raised by Codex Security


https://github.com/curl/curl/pull/20983/files?w=1

@vszakats vszakats changed the title rand: try using BCryptGenRandom() in UWP builds rand: try using BCryptGenRandom() in UWP builds Mar 18, 2026
@vszakats vszakats added the Windows Windows-specific label Mar 18, 2026
CMAKE_SYSTEM_VERSION is only effective for MSVC, and we also need to
set this for autotools, so just stick with _WIN32_WINNT.

Necessary to enable BCryptGenRandom() in mingw-w64 headers since mingw-w64 v6.0.

```
D:/a/curl/curl/lib/rand.c:49:6: error: implicit declaration of function 'BCryptGenRandom' [-Wimplicit-function-declaration]
   49 |   if(BCryptGenRandom(NULL, entropy, (ULONG)length,
      |      ^~~~~~~~~~~~~~~
D:/a/curl/curl/lib/rand.c:49:6: error: nested extern declaration of 'BCryptGenRandom' [-Werror=nested-externs]
D:/a/curl/curl/lib/rand.c:50:22: error: 'BCRYPT_USE_SYSTEM_PREFERRED_RNG' undeclared (first use in this function)
   50 |                      BCRYPT_USE_SYSTEM_PREFERRED_RNG) != STATUS_SUCCESS)
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/a/curl/curl/lib/rand.c:50:22: note: each undeclared identifier is reported only once for each function it appears in
D:/a/curl/curl/lib/rand.c:42:26: error: 'NTSTATUS' undeclared (first use in this function); did you mean 'LSTATUS'?
   42 | #define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
      |                          ^~~~~~~~
D:/a/curl/curl/lib/rand.c:50:58: note: in expansion of macro 'STATUS_SUCCESS'
   50 |                      BCRYPT_USE_SYSTEM_PREFERRED_RNG) != STATUS_SUCCESS)
      |                                                          ^~~~~~~~~~~~~~
D:/a/curl/curl/lib/rand.c:42:35: error: expected ')' before numeric constant
   42 | #define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
      |                        ~          ^~~~~~~~~~~
D:/a/curl/curl/lib/rand.c:50:58: note: in expansion of macro 'STATUS_SUCCESS'
   50 |                      BCRYPT_USE_SYSTEM_PREFERRED_RNG) != STATUS_SUCCESS)
      |                                                          ^~~~~~~~~~~~~~
cc1.exe: all warnings being treated as errors
```
https://github.com/curl/curl/actions/runs/23246552140/job/67576489473?pr=20983
@github-actions github-actions bot added the CI Continuous Integration label Mar 18, 2026
@vszakats vszakats changed the title rand: try using BCryptGenRandom() in UWP builds rand: use BCryptGenRandom() in UWP builds Mar 18, 2026
@vszakats vszakats closed this in d986b89 Mar 18, 2026
@vszakats vszakats deleted the uwp-use-bcrypt branch March 18, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous Integration cryptography Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant