mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:30:53 +01:00
[PR #2381] bcrypt_rng: BCryptGenRandom refuses flags the host does not take (BCRYPT-GEN-RANDOM-FLAGS) #2381
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#2381
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/2381
Author: @syfyra
Created: 11/26/2026
Status: 🔄 Open
Base:
main← Head:fix/bcrypt-gen-random-flags📝 Commits (1)
2a3bababcrypt_rng: BCryptGenRandom refuses flags the host does not take (BCRYPT-GEN-RANDOM-FLAGS)📊 Changes
2 files changed (+32 additions, -0 deletions)
View changed files
📝
runtime/shims/bcrypt_rng.cpp(+7 -0)📝
runtime/test/bcrypt_rng_test.cpp(+25 -0)📄 Description
Claimed in the coordination issue as: BCRYPT-GEN-RANDOM-FLAGS
What and why
BCryptGenRandomtakes two flags:BCRYPT_RNG_USE_ENTROPY_IN_BUFFER(ignored since Windows 7) andBCRYPT_USE_SYSTEM_PREFERRED_RNG. The host refuses any other flag withSTATUS_INVALID_PARAMETER. The shim passed the flags on, and when the host refused them,gen_randomfell through to itsSystemFunction036fallback, which takes no flags. The call came back asSTATUS_SUCCESS, with random bytes in the buffer. WithLEONIDA_RNG_SEEDset, the seeded stream ignored the flags as well. A call Windows refuses succeeded under the shim.Measured on Windows 11 against the in-box
bcrypt.dllwith a small probe:0x4,0x10or0x80000000STATUS_INVALID_PARAMETER0x4STATUS_INVALID_PARAMETERBCRYPT_USE_SYSTEM_PREFERRED_RNG | 0x4STATUS_INVALID_PARAMETER0x4STATUS_INVALID_HANDLE(the handle is checked first)BCRYPT_RNG_USE_ENTROPY_IN_BUFFERBCRYPT_USE_SYSTEM_PREFERRED_RNG | BCRYPT_RNG_USE_ENTROPY_IN_BUFFERgen_randomnow refuses any other flag withSTATUS_INVALID_PARAMETER. The check sits where the host makes it: after the handle checks and before a zero-byte call is answered, and before the seeded and fallback paths. Valid calls are unchanged.Tested
Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:
bcrypt_rng_testgets five checks in the part that runs in both modes, matching the table above: the three unknown flags are refused and leave the buffer untouched, a zero-byte call with an unknown flag is refused, so is an unknown flag next toBCRYPT_USE_SYSTEM_PREFERRED_RNG, a null handle with an unknown flag is stillSTATUS_INVALID_HANDLE, andBCRYPT_RNG_USE_ENTROPY_IN_BUFFERstill succeeds.main:bcrypt_rngandbcrypt_rng_seededeach fail 3 of 26 checks. All three unknown flags returnSTATUS_SUCCESSand write the buffer.scripts/pr_overlap.pyfrom #2349).scripts/check_no_game_data.pyon both files.The check comes before the host is called, so it behaves the same under Wine; not run there.
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.