OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcRngLib.c File Reference
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcCryptoLib.h>
#include <Library/OcRngLib.h>
#include <Register/Intel/Cpuid.h>
#include "OcRngInternals.h"

Go to the source code of this file.

Functions

STATIC VOID ChaChaRngStir (IN UINT32 BytesNeeded)
 
STATIC VOID ChaChaRngGenerate (OUT UINT8 *Data, IN UINT32 Size)
 
STATIC UINT64 GetEntropyBits (IN UINTN Bits)
 
EFI_STATUS EFIAPI OcRngLibConstructor (VOID)
 
BOOLEAN EFIAPI GetRandomNumber16 (OUT UINT16 *Rand)
 
BOOLEAN EFIAPI GetRandomNumber32 (OUT UINT32 *Rand)
 
BOOLEAN EFIAPI GetRandomNumber64 (OUT UINT64 *Rand)
 
BOOLEAN EFIAPI GetRandomNumber128 (OUT UINT64 *Rand)
 
UINT16 EFIAPI GetPseudoRandomNumber16 (VOID)
 
UINT32 EFIAPI GetPseudoRandomNumber32 (VOID)
 
UINT64 EFIAPI GetPseudoRandomNumber64 (VOID)
 

Variables

STATIC OC_RNG_CONTEXT mRng
 

Detailed Description

Random number generator services that uses RdRand instruction access to provide high-quality random numbers. In addition to that we provide interfaces that generate pseudo random numbers through TSC, which can be used when RdRand is not available.

Copyright (c) 2015, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Copyright (c) 2019, vit9696

All rights reserved.

This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

Definition in file OcRngLib.c.

Function Documentation

◆ ChaChaRngGenerate()

STATIC VOID ChaChaRngGenerate ( OUT UINT8 * Data,
IN UINT32 Size )

Definition at line 122 of file OcRngLib.c.

◆ ChaChaRngStir()

STATIC VOID ChaChaRngStir ( IN UINT32 BytesNeeded)

Definition at line 38 of file OcRngLib.c.

◆ GetEntropyBits()

STATIC UINT64 GetEntropyBits ( IN UINTN Bits)

Definition at line 163 of file OcRngLib.c.

◆ GetPseudoRandomNumber16()

UINT16 EFIAPI GetPseudoRandomNumber16 ( VOID )

Generates a 16-bit pseudo random number.

Return values
16-bitpseudo random number.

Definition at line 372 of file OcRngLib.c.

◆ GetPseudoRandomNumber32()

UINT32 EFIAPI GetPseudoRandomNumber32 ( VOID )

Generates a 32-bit pseudo random number.

Return values
32-bitpseudo random number.

Definition at line 390 of file OcRngLib.c.

◆ GetPseudoRandomNumber64()

UINT64 EFIAPI GetPseudoRandomNumber64 ( VOID )

Generates a 64-bit pseudo random number.

Return values
64-bitpseudo random number.

Definition at line 408 of file OcRngLib.c.

◆ GetRandomNumber128()

BOOLEAN EFIAPI GetRandomNumber128 ( OUT UINT64 * Rand)

Generates a 128-bit random number.

if Rand is NULL, then ASSERT().

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 343 of file OcRngLib.c.

◆ GetRandomNumber16()

BOOLEAN EFIAPI GetRandomNumber16 ( OUT UINT16 * Rand)

Generates a 16-bit random number.

if Rand is NULL, then ASSERT().

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 OcRngLib.c.

◆ GetRandomNumber32()

BOOLEAN EFIAPI GetRandomNumber32 ( OUT UINT32 * Rand)

Generates a 32-bit random number.

if Rand is NULL, then ASSERT().

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 271 of file OcRngLib.c.

◆ GetRandomNumber64()

BOOLEAN EFIAPI GetRandomNumber64 ( OUT UINT64 * Rand)

Generates a 64-bit random number.

if Rand is NULL, then ASSERT().

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 307 of file OcRngLib.c.

◆ OcRngLibConstructor()

EFI_STATUS EFIAPI OcRngLibConstructor ( VOID )

The constructor function checks whether or not RDRAND instruction is supported by the host hardware.

The constructor function checks whether or not RDRAND instruction is supported. It will ASSERT() if RDRAND instruction is not supported. It will always return EFI_SUCCESS.

Return values
EFI_SUCCESSThe constructor always returns EFI_SUCCESS.

Definition at line 201 of file OcRngLib.c.

Variable Documentation

◆ mRng

STATIC OC_RNG_CONTEXT mRng

Definition at line 34 of file OcRngLib.c.