mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:40:52 +01:00
[PR #2132] bcrypt_rng: accept BCRYPT_RNG_ALG_HANDLE in BCryptGenRandom (BCRYPT-RNG-PSEUDO-HANDLE) #2136
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2136
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2132
Author: @syfyra
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/bcrypt-rng-pseudo-handle📝 Commits (1)
e99a2debcrypt_rng: accept BCRYPT_RNG_ALG_HANDLE in BCryptGenRandom (BCRYPT-RNG-PSEUDO-HANDLE)📊 Changes
2 files changed (+54 additions, -1 deletions)
View changed files
📝
runtime/shims/bcrypt_rng.cpp(+13 -1)📝
runtime/test/bcrypt_rng_test.cpp(+41 -0)📄 Description
Claimed in the coordination issue as: BCRYPT-RNG-PSEUDO-HANDLE (claim comment to follow)
What and why
BCRYPT_RNG_ALG_HANDLE((BCRYPT_ALG_HANDLE)0x81, bcrypt.h for NTDDI_WINTHRESHOLD and later) is the CNG pseudo-handle of the RNG: on Windows 10 and later it can be passed wherever an RNG algorithm handle is, with noBCryptOpenAlgorithmProvider("CNG Algorithm Pseudo-handles").runtime/shims/bcrypt_rng.cppgen_randomlooked every handle up among the ones it had opened itself, found nothing for 0x81 and returnedSTATUS_INVALID_HANDLEwith the buffer left as it was, in theLEONIDA_RNG_SEEDmode too. A caller that does not check the status (common despite_Must_inspect_result_) then uses whatever the buffer held as its random bytes.The pseudo-handle is now an RNG handle: it goes to the host's
BCryptGenRandomas it is, or to the seeded stream underLEONIDA_RNG_SEED, and the fail-closed path (no host RNG) still returnsSTATUS_UNSUCCESSFULwithout touching the buffer. Every other answer is unchanged and matches Windows 11's bcrypt.dll, measured with a small probe:BCryptGenRandom(0x81, buf, 16, 0)STATUS_SUCCESSSTATUS_INVALID_HANDLESTATUS_SUCCESSBCryptGenRandom(BCRYPT_SHA256_ALG_HANDLE, ...)STATUS_INVALID_HANDLEBCryptGenRandom(0x81, ..., BCRYPT_USE_SYSTEM_PREFERRED_RNG)STATUS_INVALID_PARAMETERBCryptCloseAlgorithmProvider(0x81, 0)STATUS_INVALID_HANDLETested
Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:
bcrypt_rng_testandbcrypt_rng_test --seeded(LEONIDA_RNG_SEED=0x123456789abcdef0, as ctest runs it) get five new checks: the pseudo-handle fills the buffer, another algorithm's pseudo-handle and closing 0x81 are refused, 0x81 with the system-RNG flag is an invalid parameter, the fail-closed path leaves the buffer untouched, and with the host RNG switched off the seeded run still serves 0x81 (so the bytes come from the seeded stream). Onmain3 checks fail in each run; with the fix all 27 pass in both. No new/W4warnings.-j 8) passes.scripts/check_no_game_data.pyon both files.GPUs tested: n/a (CPU tests)
AI-assisted: yes (Claude Code, Claude Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.