]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c
SecurityPkg/RngDxe: Add Arm support of RngDxe
[mirror_edk2.git] / SecurityPkg / RandomNumberGenerator / RngDxe / AArch64 / AArch64Algo.c
CommitLineData
9eb5ccda
PG
1/** @file\r
2 Aarch64 specific code.\r
3\r
4 Copyright (c) 2022, Arm Limited. All rights reserved.<BR>\r
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6**/\r
7\r
8#include <Library/BaseLib.h>\r
9#include <Library/BaseMemoryLib.h>\r
10#include <Library/DebugLib.h>\r
11#include <Library/MemoryAllocationLib.h>\r
12#include <Library/ArmTrngLib.h>\r
13\r
14#include "RngDxeInternals.h"\r
15\r
16// Maximum number of Rng algorithms.\r
17#define RNG_AVAILABLE_ALGO_MAX 2\r
18\r
19/** Allocate and initialize mAvailableAlgoArray with the available\r
20 Rng algorithms. Also update mAvailableAlgoArrayCount.\r
21\r
22 @retval EFI_SUCCESS The function completed successfully.\r
23 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
24**/\r
25EFI_STATUS\r
26EFIAPI\r
27GetAvailableAlgorithms (\r
28 VOID\r
29 )\r
30{\r
31 UINT64 DummyRand;\r
32 UINT16 MajorRevision;\r
33 UINT16 MinorRevision;\r
34\r
35 // Rng algorithms 2 times, one for the allocation, one to populate.\r
36 mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX);\r
37 if (mAvailableAlgoArray == NULL) {\r
38 return EFI_OUT_OF_RESOURCES;\r
39 }\r
40\r
41 // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm.\r
42 if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) {\r
43 CopyMem (\r
44 &mAvailableAlgoArray[mAvailableAlgoArrayCount],\r
45 PcdGetPtr (PcdCpuRngSupportedAlgorithm),\r
46 sizeof (EFI_RNG_ALGORITHM)\r
47 );\r
48 mAvailableAlgoArrayCount++;\r
49\r
50 DEBUG_CODE_BEGIN ();\r
51 if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) {\r
52 DEBUG ((\r
53 DEBUG_WARN,\r
54 "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n"\r
55 ));\r
56 }\r
57\r
58 DEBUG_CODE_END ();\r
59 }\r
60\r
61 // Raw algorithm (Trng)\r
62 if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {\r
63 CopyMem (\r
64 &mAvailableAlgoArray[mAvailableAlgoArrayCount],\r
65 &gEfiRngAlgorithmRaw,\r
66 sizeof (EFI_RNG_ALGORITHM)\r
67 );\r
68 mAvailableAlgoArrayCount++;\r
69 }\r
70\r
71 return EFI_SUCCESS;\r
72}\r