-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new RngLib that will try to get an RNG from the ARM TRNG Library or falls back to the timer-based library if the TRNG service isn't implemented in ATF. Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com> Reviewed-by: Jeff Brasen <jbrasen@nvidia.com> Reviewed-by: Jake Garver <jake@nvidia.com> Tested-by: Jake Garver <jake@nvidia.com>
- Loading branch information
1 parent
c3d171d
commit f4d4ea4
Showing
12 changed files
with
781 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** @file | ||
Rng Lib that gets the RNG from a secure RNG driver in StMM or from a Non-Safe | ||
Rng Source if MM isn't present. | ||
SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include "NvRngProto.h" | ||
|
||
STATIC NVIDIA_NVRNG_PROTOCOL *RngOps = NULL; | ||
|
||
/** | ||
Generates a 16-bit random number. | ||
if Rand is NULL, then ASSERT(). | ||
@param[out] Rand Buffer pointer to store the 16-bit random value. | ||
@retval TRUE Random number generated successfully. | ||
@retval FALSE Failed to generate the random number. | ||
**/ | ||
BOOLEAN | ||
EFIAPI | ||
GetRandomNumber16 ( | ||
OUT UINT16 *Rand | ||
) | ||
{ | ||
return RngOps->NvGetRng16 (Rand); | ||
} | ||
|
||
/** | ||
Generates a 32-bit random number. | ||
if Rand is NULL, then ASSERT(). | ||
@param[out] Rand Buffer pointer to store the 32-bit random value. | ||
@retval TRUE Random number generated successfully. | ||
@retval FALSE Failed to generate the random number. | ||
**/ | ||
BOOLEAN | ||
EFIAPI | ||
GetRandomNumber32 ( | ||
OUT UINT32 *Rand | ||
) | ||
{ | ||
return RngOps->NvGetRng32 (Rand); | ||
} | ||
|
||
/** | ||
Generates a 64-bit random number. | ||
if Rand is NULL, then ASSERT(). | ||
@param[out] Rand Buffer pointer to store the 64-bit random value. | ||
@retval TRUE Random number generated successfully. | ||
@retval FALSE Failed to generate the random number. | ||
**/ | ||
BOOLEAN | ||
EFIAPI | ||
GetRandomNumber64 ( | ||
OUT UINT64 *Rand | ||
) | ||
{ | ||
return RngOps->NvGetRng64 (Rand); | ||
} | ||
|
||
/** | ||
Generates a 128-bit random number. | ||
if Rand is NULL, then ASSERT(). | ||
@param[out] Rand Buffer pointer to store the 128-bit random value. | ||
@retval TRUE Random number generated successfully. | ||
@retval FALSE Failed to generate the random number. | ||
**/ | ||
BOOLEAN | ||
EFIAPI | ||
GetRandomNumber128 ( | ||
OUT UINT64 *Rand | ||
) | ||
{ | ||
return RngOps->NvGetRng128 (Rand); | ||
} | ||
|
||
/** | ||
Get a GUID identifying the RNG algorithm implementation. | ||
@param [out] RngGuid If success, contains the GUID identifying | ||
the RNG algorithm implementation. | ||
@retval EFI_SUCCESS Success. | ||
@retval EFI_UNSUPPORTED Not supported. | ||
@retval EFI_INVALID_PARAMETER Invalid parameter. | ||
**/ | ||
EFI_STATUS | ||
EFIAPI | ||
GetRngGuid ( | ||
GUID *RngGuid | ||
) | ||
{ | ||
return RngOps->NvGetRngGuid (RngGuid); | ||
} | ||
|
||
EFI_STATUS | ||
EFIAPI | ||
NvRngLibConstructor ( | ||
VOID | ||
) | ||
{ | ||
RngOps = HwRngGetOps (); | ||
if (RngOps == NULL) { | ||
RngOps = NonHwRngGetOps (); | ||
DEBUG ((DEBUG_ERROR, "%a: No StMM Using NonHW RngLib\n", __FUNCTION__)); | ||
} else { | ||
DEBUG ((DEBUG_INFO, "%a: Using HW RngLib\n", __FUNCTION__)); | ||
} | ||
|
||
return EFI_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
## @file | ||
# Rng Lib that gets the RNG from a secure RNG driver in StMM or from a Non-Safe | ||
# Rng Source if MM isn't present. | ||
# | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
## | ||
|
||
[Defines] | ||
INF_VERSION = 0x00010029 | ||
BASE_NAME = NvRngLib | ||
MODULE_UNI_FILE = NvRngLib.uni | ||
FILE_GUID = 979ff860-9401-4757-b990-1f2a43b8aaab | ||
MODULE_TYPE = BASE | ||
VERSION_STRING = 1.0 | ||
CONSTRUCTOR = NvRngLibConstructor | ||
LIBRARY_CLASS = RngLib | ||
|
||
# | ||
# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 EBC | ||
# | ||
|
||
[Sources] | ||
NvRngLib.c | ||
NvRngLibHw.c | ||
NvRngLibNonHw.c | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
MdeModulePkg/MdeModulePkg.dec | ||
Silicon/NVIDIA/NVIDIA.dec | ||
ArmPkg/ArmPkg.dec | ||
|
||
[LibraryClasses] | ||
MemoryAllocationLib | ||
BaseLib | ||
UefiBootServicesTableLib | ||
DebugLib | ||
ArmTrngLib | ||
|
||
[Protocols] | ||
|
||
[Guids] | ||
gEdkiiRngAlgorithmUnSafe | ||
gEfiRngAlgorithmRaw | ||
|
||
[Depex] | ||
TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// /** @file | ||
// Null Instance of RNG (Random Number Generator) Library. | ||
// | ||
// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause-Patent | ||
// | ||
// **/ | ||
|
||
|
||
#string STR_MODULE_ABSTRACT #language en-US "NVIDIA's instance of RNG Library" | ||
|
||
#string STR_MODULE_DESCRIPTION #language en-US "This library instance should be used with modules that inherit an (indirect) dependency on the RngLib class, but never actually call RngLib APIs for consuming randomness." | ||
|
Oops, something went wrong.