Skip to content

Conflicting definitions of BCryptGenRandom(). #26327

@baulig

Description

@baulig

I am currently trying to adapt the random number generators (both the non-cryptographic version and the cryptographic version) to Mono and stumbled upon two different versions of BCryptGenRandom():

There is the version in src/Common/src/CoreLib/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs, which is int BCryptGenRandom(byte*, int) - this class also defines GetRandomBytes(byte*, int).

And then there is the version in src/Common/src/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs, which is NTSTATUS BCryptGenRandom(ref byte, int).

Looking at RandomNumberGeneratorImplementation.Windows.cs, this calls the ref byte version.

Then src/Common/src/CoreLib/System/HashCode.cs calls Interop.GetRandomBytes((byte*)&result, sizeof(uint)).

The problem is that both versions define BCRYPT_USE_SYSTEM_PREFERRED_RNG, so you cannot include both source files at the same time.

Before making a PR to remove / rename one of them, I would like to ask why the two versions exist in the first place and how you would feel about maybe unifying them into just one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.SecurityenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions