MdePkg/Rng: Add GetRngGuid() to RngLib
The EFI_RNG_PROTOCOL can use the RngLib. The RngLib has multiple implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). To allow the RngDxe to detect when such implementation is used, add a GetRngGuid() function to the RngLib. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Ard Biesheuvel <ardb@kernel.org> Tested-by: Kun Qin <kun.qin@microsoft.com>
This commit is contained in:
committed by
mergify[bot]
parent
414c0f2089
commit
5443c2dc31
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user