The BCryptGenRandom function generates a random number.
NTSTATUS BCryptGenRandom(
BCRYPT_ALG_HANDLE hAlgorithm,
PUCHAR pbBuffer,
ULONG cbBuffer,
ULONG dwFlags
)
hAlgorithm
Type: BCRYPT_ALG_HANDLE
[in, optional] The handle of an algorithm provider created by using the BCryptOpenAlgorithmProvider function. The algorithm that was specified when the provider was created must support the random number generator interface.
pbBuffer
Type: PUCHAR
[in, out] The address of a buffer that receives the random number. The size of this buffer is specified by the cbBuffer parameter.
cbBuffer
Type: ULONG
[in] The size, in bytes, of the pbBuffer buffer.
dwFlags
Type: ULONG
[in] A set of flags that modify the behavior of this function. This parameter can be zero or the following value.
Type: NTSTATUS
Returns a status code that indicates the success or failure of the function.
Possible return codes include, but are not limited to, the following.
| Return code | Description |
|---|---|
| STATUS_SUCCESS | The function was successful. |
| STATUS_INVALID_HANDLE | The handle in the hAlgorithm parameter is not valid. |
| STATUS_INVALID_PARAMETER | One or more parameters are not valid. |
The default random number provider implements an algorithm for generating random numbers that complies with the NIST SP800-90 standard, specifically the CTR_DRBG portion of that standard.
Depending on what processor modes a provider supports, BCryptGenRandom can be called either from user mode or kernel mode. Kernel mode callers can execute either at PASSIVE_LEVELIRQL or DISPATCH_LEVEL IRQL. If the current IRQL level is DISPATCH_LEVEL, the handle provided in the hAlgorithm parameter must have been opened by using the BCRYPT_PROV_DISPATCH flag, and any pointers passed to the BCryptGenRandom function must refer to nonpaged (or locked) memory.
Note
The Microsoft provider does not support calling at DISPATCH_LEVEL.
Header: Declared in bcrypt.h.
Library: Use bcrypt.lib.