summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/BaseRngLib
diff options
context:
space:
mode:
Diffstat (limited to 'MdePkg/Library/BaseRngLib')
-rw-r--r--MdePkg/Library/BaseRngLib/AArch64/Rndr.c42
-rw-r--r--MdePkg/Library/BaseRngLib/BaseRngLib.inf10
-rw-r--r--MdePkg/Library/BaseRngLib/Rand/RdRand.c26
3 files changed, 78 insertions, 0 deletions
diff --git a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
index 20811bf3eb..d39db62153 100644
--- a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
+++ b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
@@ -2,6 +2,7 @@
Random number generator service that uses the RNDR instruction
to provide pseudorandom numbers.
+ Copyright (c) 2023, Arm Limited. All rights reserved.<BR>
Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
@@ -11,6 +12,7 @@
#include <Uefi.h>
#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/RngLib.h>
@@ -138,3 +140,43 @@ ArchIsRngSupported (
{
return mRndrSupported;
}
+
+/**
+ 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
+ )
+{
+ GUID *RngLibGuid;
+
+ if (RngGuid == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (!mRndrSupported) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // If the platform advertises the algorithm behind RNDR instruction,
+ // use it. Otherwise use gEfiRngAlgorithmArmRndr.
+ //
+ RngLibGuid = PcdGetPtr (PcdCpuRngSupportedAlgorithm);
+ if (!IsZeroGuid (RngLibGuid)) {
+ CopyMem (RngGuid, RngLibGuid, sizeof (*RngGuid));
+ } else {
+ CopyMem (RngGuid, &gEfiRngAlgorithmArmRndr, sizeof (*RngGuid));
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/MdePkg/Library/BaseRngLib/BaseRngLib.inf b/MdePkg/Library/BaseRngLib/BaseRngLib.inf
index 1fcceb9414..49503b139b 100644
--- a/MdePkg/Library/BaseRngLib/BaseRngLib.inf
+++ b/MdePkg/Library/BaseRngLib/BaseRngLib.inf
@@ -4,6 +4,7 @@
# BaseRng Library that uses CPU RNG instructions (e.g. RdRand) to
# provide random numbers.
#
+# Copyright (c) 2023, Arm Limited. All rights reserved.<BR>
# Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
#
@@ -43,9 +44,18 @@
AArch64/ArmReadIdIsar0.asm | MSFT
AArch64/ArmRng.asm | MSFT
+[Guids.AARCH64]
+ gEfiRngAlgorithmArmRndr
+
+[Guids.Ia32, Guids.X64]
+ gEfiRngAlgorithmSp80090Ctr256Guid
+
[Packages]
MdePkg/MdePkg.dec
+[Pcd.AARCH64]
+ gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm
+
[LibraryClasses]
BaseLib
DebugLib
diff --git a/MdePkg/Library/BaseRngLib/Rand/RdRand.c b/MdePkg/Library/BaseRngLib/Rand/RdRand.c
index 070d41e255..9bd68352f9 100644
--- a/MdePkg/Library/BaseRngLib/Rand/RdRand.c
+++ b/MdePkg/Library/BaseRngLib/Rand/RdRand.c
@@ -2,6 +2,7 @@
Random number generator services that uses RdRand instruction access
to provide high-quality random numbers.
+Copyright (c) 2023, Arm Limited. All rights reserved.<BR>
Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
@@ -11,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Uefi.h>
#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include "BaseRngLibInternals.h"
@@ -128,3 +130,27 @@ ArchIsRngSupported (
*/
return TRUE;
}
+
+/**
+ 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
+ )
+{
+ if (RngGuid == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ CopyMem (RngGuid, &gEfiRngAlgorithmSp80090Ctr256Guid, sizeof (*RngGuid));
+ return EFI_SUCCESS;
+}