Repository navigation
Conversation
…YPT-GEN-RANDOM-FLAGS) BCryptGenRandom passed any flags to the host, and the host's refusal (STATUS_INVALID_PARAMETER for every flag but BCRYPT_RNG_USE_ENTROPY_IN_BUFFER and BCRYPT_USE_SYSTEM_PREFERRED_RNG, measured on Windows 11 for 0x4, 0x10 and 0x80000000) fell through to the SystemFunction036 fallback, which ignores flags: the call returned STATUS_SUCCESS with random bytes. The seeded stream ignored them too. The flags are now checked where the host checks them, after the handle and before a zero-byte call is answered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 scripts: pr_overlap.py lists the open pull requests that change the same files (PR-OVERLAP-CHECK) #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