SecurityPkg/RngDxe: Add Arm support of RngDxe
Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668) Add RngDxe support for Arm. This implementation uses the ArmTrngLib to support the RawAlgorithm and doens't support the RNDR instruction. To re-use the RngGetRNG(), RngGetInfo() and FreeAvailableAlgorithms() functions, create Arm/AArch64 files which implement the arch specific function GetAvailableAlgorithms(). Indeed, FEAT_RNG instruction is not supported on Arm. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> Acked-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
parent
ff29cdb968
commit
9eb5ccda50
@ -0,0 +1,72 @@
|
|||||||
|
/** @file
|
||||||
|
Aarch64 specific code.
|
||||||
|
|
||||||
|
Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
|
||||||
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <Library/BaseLib.h>
|
||||||
|
#include <Library/BaseMemoryLib.h>
|
||||||
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/MemoryAllocationLib.h>
|
||||||
|
#include <Library/ArmTrngLib.h>
|
||||||
|
|
||||||
|
#include "RngDxeInternals.h"
|
||||||
|
|
||||||
|
// Maximum number of Rng algorithms.
|
||||||
|
#define RNG_AVAILABLE_ALGO_MAX 2
|
||||||
|
|
||||||
|
/** Allocate and initialize mAvailableAlgoArray with the available
|
||||||
|
Rng algorithms. Also update mAvailableAlgoArrayCount.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The function completed successfully.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES Could not allocate memory.
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
GetAvailableAlgorithms (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINT64 DummyRand;
|
||||||
|
UINT16 MajorRevision;
|
||||||
|
UINT16 MinorRevision;
|
||||||
|
|
||||||
|
// Rng algorithms 2 times, one for the allocation, one to populate.
|
||||||
|
mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX);
|
||||||
|
if (mAvailableAlgoArray == NULL) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm.
|
||||||
|
if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) {
|
||||||
|
CopyMem (
|
||||||
|
&mAvailableAlgoArray[mAvailableAlgoArrayCount],
|
||||||
|
PcdGetPtr (PcdCpuRngSupportedAlgorithm),
|
||||||
|
sizeof (EFI_RNG_ALGORITHM)
|
||||||
|
);
|
||||||
|
mAvailableAlgoArrayCount++;
|
||||||
|
|
||||||
|
DEBUG_CODE_BEGIN ();
|
||||||
|
if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) {
|
||||||
|
DEBUG ((
|
||||||
|
DEBUG_WARN,
|
||||||
|
"PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_CODE_END ();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw algorithm (Trng)
|
||||||
|
if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {
|
||||||
|
CopyMem (
|
||||||
|
&mAvailableAlgoArray[mAvailableAlgoArrayCount],
|
||||||
|
&gEfiRngAlgorithmRaw,
|
||||||
|
sizeof (EFI_RNG_ALGORITHM)
|
||||||
|
);
|
||||||
|
mAvailableAlgoArrayCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
51
SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c
Normal file
51
SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/** @file
|
||||||
|
Arm specific code.
|
||||||
|
|
||||||
|
Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
|
||||||
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <Library/BaseLib.h>
|
||||||
|
#include <Library/BaseMemoryLib.h>
|
||||||
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/MemoryAllocationLib.h>
|
||||||
|
#include <Library/ArmTrngLib.h>
|
||||||
|
|
||||||
|
#include "RngDxeInternals.h"
|
||||||
|
|
||||||
|
// Maximum number of Rng algorithms.
|
||||||
|
#define RNG_AVAILABLE_ALGO_MAX 1
|
||||||
|
|
||||||
|
/** Allocate and initialize mAvailableAlgoArray with the available
|
||||||
|
Rng algorithms. Also update mAvailableAlgoArrayCount.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The function completed successfully.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES Could not allocate memory.
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
GetAvailableAlgorithms (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINT16 MajorRevision;
|
||||||
|
UINT16 MinorRevision;
|
||||||
|
|
||||||
|
// Rng algorithms 2 times, one for the allocation, one to populate.
|
||||||
|
mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX);
|
||||||
|
if (mAvailableAlgoArray == NULL) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw algorithm (Trng)
|
||||||
|
if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {
|
||||||
|
CopyMem (
|
||||||
|
&mAvailableAlgoArray[mAvailableAlgoArrayCount],
|
||||||
|
&gEfiRngAlgorithmRaw,
|
||||||
|
sizeof (EFI_RNG_ALGORITHM)
|
||||||
|
);
|
||||||
|
mAvailableAlgoArrayCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
@ -28,70 +28,10 @@
|
|||||||
#include <Library/MemoryAllocationLib.h>
|
#include <Library/MemoryAllocationLib.h>
|
||||||
#include <Library/UefiBootServicesTableLib.h>
|
#include <Library/UefiBootServicesTableLib.h>
|
||||||
#include <Library/RngLib.h>
|
#include <Library/RngLib.h>
|
||||||
#include <Library/DebugLib.h>
|
|
||||||
#include <Library/ArmTrngLib.h>
|
|
||||||
#include <Protocol/Rng.h>
|
#include <Protocol/Rng.h>
|
||||||
|
|
||||||
#include "RngDxeInternals.h"
|
#include "RngDxeInternals.h"
|
||||||
|
|
||||||
// Maximum number of Rng algorithms.
|
|
||||||
#define RNG_AVAILABLE_ALGO_MAX 2
|
|
||||||
|
|
||||||
/** Allocate and initialize mAvailableAlgoArray with the available
|
|
||||||
Rng algorithms. Also update mAvailableAlgoArrayCount.
|
|
||||||
|
|
||||||
@retval EFI_SUCCESS The function completed successfully.
|
|
||||||
@retval EFI_OUT_OF_RESOURCES Could not allocate memory.
|
|
||||||
**/
|
|
||||||
EFI_STATUS
|
|
||||||
EFIAPI
|
|
||||||
GetAvailableAlgorithms (
|
|
||||||
VOID
|
|
||||||
)
|
|
||||||
{
|
|
||||||
UINT64 DummyRand;
|
|
||||||
UINT16 MajorRevision;
|
|
||||||
UINT16 MinorRevision;
|
|
||||||
|
|
||||||
// Rng algorithms 2 times, one for the allocation, one to populate.
|
|
||||||
mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX);
|
|
||||||
if (mAvailableAlgoArray == NULL) {
|
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm.
|
|
||||||
if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) {
|
|
||||||
CopyMem (
|
|
||||||
&mAvailableAlgoArray[mAvailableAlgoArrayCount],
|
|
||||||
PcdGetPtr (PcdCpuRngSupportedAlgorithm),
|
|
||||||
sizeof (EFI_RNG_ALGORITHM)
|
|
||||||
);
|
|
||||||
mAvailableAlgoArrayCount++;
|
|
||||||
|
|
||||||
DEBUG_CODE_BEGIN ();
|
|
||||||
if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) {
|
|
||||||
DEBUG ((
|
|
||||||
DEBUG_WARN,
|
|
||||||
"PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG_CODE_END ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Raw algorithm (Trng)
|
|
||||||
if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {
|
|
||||||
CopyMem (
|
|
||||||
&mAvailableAlgoArray[mAvailableAlgoArrayCount],
|
|
||||||
&gEfiRngAlgorithmRaw,
|
|
||||||
sizeof (EFI_RNG_ALGORITHM)
|
|
||||||
);
|
|
||||||
mAvailableAlgoArrayCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Free mAvailableAlgoArray.
|
/** Free mAvailableAlgoArray.
|
||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#
|
#
|
||||||
# The following information is for reference only and not required by the build tools.
|
# The following information is for reference only and not required by the build tools.
|
||||||
#
|
#
|
||||||
# VALID_ARCHITECTURES = IA32 X64 AARCH64
|
# VALID_ARCHITECTURES = IA32 X64 AARCH64 ARM
|
||||||
#
|
#
|
||||||
|
|
||||||
[Sources.common]
|
[Sources.common]
|
||||||
@ -41,10 +41,16 @@
|
|||||||
Rand/AesCore.c
|
Rand/AesCore.c
|
||||||
Rand/AesCore.h
|
Rand/AesCore.h
|
||||||
|
|
||||||
[Sources.AARCH64]
|
[Sources.AARCH64, Sources.ARM]
|
||||||
ArmRngDxe.c
|
ArmRngDxe.c
|
||||||
ArmTrng.c
|
ArmTrng.c
|
||||||
|
|
||||||
|
[Sources.AARCH64]
|
||||||
|
AArch64/AArch64Algo.c
|
||||||
|
|
||||||
|
[Sources.ARM]
|
||||||
|
Arm/ArmAlgo.c
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdeModulePkg/MdeModulePkg.dec
|
MdeModulePkg/MdeModulePkg.dec
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
@ -59,7 +65,7 @@
|
|||||||
TimerLib
|
TimerLib
|
||||||
RngLib
|
RngLib
|
||||||
|
|
||||||
[LibraryClasses.AARCH64]
|
[LibraryClasses.AARCH64, LibraryClasses.ARM]
|
||||||
ArmTrngLib
|
ArmTrngLib
|
||||||
|
|
||||||
[Guids]
|
[Guids]
|
||||||
|
@ -291,7 +291,7 @@
|
|||||||
SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf
|
SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf
|
||||||
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
|
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
|
||||||
|
|
||||||
[Components.IA32, Components.X64, Components.AARCH64]
|
[Components.IA32, Components.X64, Components.AARCH64, Components.ARM]
|
||||||
#
|
#
|
||||||
# Random Number Generator
|
# Random Number Generator
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user