TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeRngLib.c File Reference

Go to the source code of this file.

Data Structures

struct  SECURE_RNG_ALGO_ARRAY
 

Functions

EFI_STATUS EFIAPI DxeRngLibConstructor (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 
STATIC EFI_STATUS GenerateRandomNumberViaNist800Algorithm (OUT UINT8 *Buffer, IN UINTN BufferSize)
 
BOOLEAN EFIAPI GetRandomNumber16 (OUT UINT16 *Rand)
 
BOOLEAN EFIAPI GetRandomNumber32 (OUT UINT32 *Rand)
 
BOOLEAN EFIAPI GetRandomNumber64 (OUT UINT64 *Rand)
 
BOOLEAN EFIAPI GetRandomNumber128 (OUT UINT64 *Rand)
 
EFI_STATUS EFIAPI GetRngGuid (GUID *RngGuid)
 

Variables

STATIC EFI_RNG_PROTOCOLmRngProtocol
 
STATIC UINTN mFirstAlgo = MAX_UINTN
 

Detailed Description

Provides an implementation of the library class RngLib that uses the Rng protocol.

Copyright (c) 2023 - 2024, Arm Limited. All rights reserved. Copyright (c) Microsoft Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file DxeRngLib.c.

Function Documentation

◆ DxeRngLibConstructor()

EFI_STATUS EFIAPI DxeRngLibConstructor ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

Constructor routine to probe the available secure Rng algorithms.

Parameters
ImageHandleThe firmware allocated handle for the EFI image.
SystemTableA pointer to the EFI System Table.
Return values
EFI_SUCCESSSuccess.
EFI_NOT_FOUNDNot found.
EFI_INVALID_PARAMETERInvalid parameter.

Definition at line 77 of file DxeRngLib.c.

◆ GenerateRandomNumberViaNist800Algorithm()

STATIC EFI_STATUS GenerateRandomNumberViaNist800Algorithm ( OUT UINT8 *  Buffer,
IN UINTN  BufferSize 
)

Routine Description:

Generates a random number via the NIST 800-9A algorithm. Refer to http://csrc.nist.gov/groups/STM/cavp/documents/drbg/DRBGVS.pdf for more information.

Parameters
[out]BufferBuffer to receive the random number.
[in]BufferSizeNumber of bytes in Buffer.
Return values
EFI_SUCCESSor underlying failure code.

Definition at line 149 of file DxeRngLib.c.

◆ GetRandomNumber128()

BOOLEAN EFIAPI GetRandomNumber128 ( OUT UINT64 *  Rand)

Generates a 128-bit random number.

if Rand is NULL, return FALSE.

Parameters
[out]RandBuffer pointer to store the 128-bit random value.
Return values
TRUERandom number generated successfully.
FALSEFailed to generate the random number.

Definition at line 328 of file DxeRngLib.c.

◆ GetRandomNumber16()

BOOLEAN EFIAPI GetRandomNumber16 ( OUT UINT16 *  Rand)

Generates a 16-bit random number.

if Rand is NULL, return FALSE.

Parameters
[out]RandBuffer pointer to store the 16-bit random value.
Return values
TRUERandom number generated successfully.
FALSEFailed to generate the random number.

Definition at line 235 of file DxeRngLib.c.

◆ GetRandomNumber32()

BOOLEAN EFIAPI GetRandomNumber32 ( OUT UINT32 *  Rand)

Generates a 32-bit random number.

if Rand is NULL, return FALSE.

Parameters
[out]RandBuffer pointer to store the 32-bit random value.
Return values
TRUERandom number generated successfully.
FALSEFailed to generate the random number.

Definition at line 266 of file DxeRngLib.c.

◆ GetRandomNumber64()

BOOLEAN EFIAPI GetRandomNumber64 ( OUT UINT64 *  Rand)

Generates a 64-bit random number.

if Rand is NULL, return FALSE.

Parameters
[out]RandBuffer pointer to store the 64-bit random value.
Return values
TRUERandom number generated successfully.
FALSEFailed to generate the random number.

Definition at line 297 of file DxeRngLib.c.

◆ GetRngGuid()

EFI_STATUS EFIAPI GetRngGuid ( GUID RngGuid)

Get a GUID identifying the RNG algorithm implementation.

Parameters
[out]RngGuidIf success, contains the GUID identifying the RNG algorithm implementation.
Return values
EFI_SUCCESSSuccess.
EFI_UNSUPPORTEDNot supported.
EFI_INVALID_PARAMETERInvalid parameter.

Definition at line 358 of file DxeRngLib.c.

Variable Documentation

◆ mFirstAlgo

STATIC UINTN mFirstAlgo = MAX_UINTN

Definition at line 18 of file DxeRngLib.c.

◆ mRngProtocol

STATIC EFI_RNG_PROTOCOL* mRngProtocol

Definition at line 17 of file DxeRngLib.c.