Skip to content

Provide native Windows system randomness for std::random #786

Closed

Description

@LunaStev

Motivation

Windows is a supported native target, but std::sys::random returns false from sys_random_available and -38 for every nonempty read. The portable random_fill API therefore remains unavailable on both Windows architectures. #383 implemented Linux/macOS and explicitly deferred Windows; #385 is the umbrella.

Starting points: std/sys/random.wave, std/random/fill.wave, llvm/src/msvc/runtime.rs.

Scope

Implement the existing provider contract with the Windows system RNG, such as BCryptGenRandom, through a narrow system-ABI binding. Preserve the portable partial-fill/error contract and handle the OS API's length width. Include the required native link dependency. No libc binding or weak fallback is needed.

Difficulty: medium.

Completion criteria

  • random_available and nonempty random_fill work on Windows amd64 and ARM64.
  • Cover zero length, invalid arguments, OS failure, length chunking and valid-prefix reporting.
  • Use mocked failure/length tests and a bounded native smoke that detects an unchanged buffer; do not assert specific random bytes.
  • The Windows package links the provider without manually supplied application libraries.

Activity

  1. added
    enhancement
    help wanted
    os support
    cross-platform
    on Sep 26, 2026
  2. self-assigned this
    on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cross-platformenhancementhelp wantedos support

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions