TianoCore EDK2 master
Loading...
Searching...
No Matches
AArch64Algo.c
Go to the documentation of this file.
1
8#include <Library/BaseLib.h>
10#include <Library/DebugLib.h>
12#include <Library/ArmTrngLib.h>
13#include <Library/RngLib.h>
14#include <Guid/RngAlgorithm.h>
15
16#include "RngDxeInternals.h"
17
18// Maximum number of Rng algorithms.
19#define RNG_AVAILABLE_ALGO_MAX 2
20
28EFIAPI
30 VOID
31 )
32{
33 EFI_STATUS Status;
34 UINT16 MajorRevision;
35 UINT16 MinorRevision;
36 GUID RngGuid;
37 BOOLEAN UnSafeAlgo;
38
39 UnSafeAlgo = FALSE;
40
41 // Rng algorithms 2 times, one for the allocation, one to populate.
42 mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX * sizeof (EFI_RNG_ALGORITHM));
43 if (mAvailableAlgoArray == NULL) {
44 return EFI_OUT_OF_RESOURCES;
45 }
46
47 // Identify RngLib algorithm.
48 Status = GetRngGuid (&RngGuid);
49 if (!EFI_ERROR (Status)) {
50 if (IsZeroGuid (&RngGuid) ||
51 CompareGuid (&RngGuid, &gEdkiiRngAlgorithmUnSafe))
52 {
53 // Treat zero GUID as an unsafe algorithm
54 DEBUG ((
55 DEBUG_WARN,
56 "RngLib uses an Unsafe algorithm and "
57 "must not be used for production builds.\n"
58 ));
59 // Set the UnSafeAlgo flag to indicate an unsafe algorithm was found
60 // so that it can be added at the end of the algorithm list.
61 UnSafeAlgo = TRUE;
62 } else {
63 CopyMem (
64 &mAvailableAlgoArray[mAvailableAlgoArrayCount],
65 &RngGuid,
66 sizeof (RngGuid)
67 );
68 mAvailableAlgoArrayCount++;
69 }
70 }
71
72 // Raw algorithm (Trng)
73 if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {
74 CopyMem (
75 &mAvailableAlgoArray[mAvailableAlgoArrayCount],
76 &gEfiRngAlgorithmRaw,
77 sizeof (EFI_RNG_ALGORITHM)
78 );
79 mAvailableAlgoArrayCount++;
80 }
81
82 // Add unsafe algorithm at the end of the list.
83 if (UnSafeAlgo) {
84 CopyMem (
85 &mAvailableAlgoArray[mAvailableAlgoArrayCount],
86 &gEdkiiRngAlgorithmUnSafe,
87 sizeof (EFI_RNG_ALGORITHM)
88 );
89 mAvailableAlgoArrayCount++;
90 }
91
92 return EFI_SUCCESS;
93}
EFI_STATUS EFIAPI GetAvailableAlgorithms(VOID)
Definition: AArch64Algo.c:29
RETURN_STATUS EFIAPI GetArmTrngVersion(OUT UINT16 *MajorRevision, OUT UINT16 *MinorRevision)
Definition: ArmTrngLib.c:82
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
BOOLEAN EFIAPI IsZeroGuid(IN CONST GUID *Guid)
Definition: MemLibGuid.c:156
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI GetRngGuid(GUID *RngGuid)
Definition: RngLibTimer.c:210
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213