TianoCore EDK2 master
Loading...
Searching...
No Matches
Rndr.c
Go to the documentation of this file.
1
13#include <Uefi.h>
14#include <Library/BaseLib.h>
16#include <Library/DebugLib.h>
17#include <Library/RngLib.h>
18
19#include "ArmRng.h"
20#include "BaseRngLibInternals.h"
21
22STATIC BOOLEAN mRndrSupported;
23
36EFIAPI
38 VOID
39 )
40{
41 UINT64 Isar0;
42
43 //
44 // Determine RNDR support by examining bits 63:60 of the ISAR0 register returned by
45 // MSR. A non-zero value indicates that the processor supports the RNDR instruction.
46 //
47 Isar0 = ArmReadIdAA64Isar0Reg ();
48 mRndrSupported = !!((Isar0 >> ARM_ID_AA64ISAR0_EL1_RNDR_SHIFT) & ARM_ID_AA64ISAR0_EL1_RNDR_MASK);
49
50 return EFI_SUCCESS;
51}
52
62BOOLEAN
63EFIAPI
65 OUT UINT16 *Rand
66 )
67{
68 UINT64 Rand64;
69
70 if (ArchGetRandomNumber64 (&Rand64)) {
71 *Rand = Rand64 & MAX_UINT16;
72 return TRUE;
73 }
74
75 return FALSE;
76}
77
87BOOLEAN
88EFIAPI
90 OUT UINT32 *Rand
91 )
92{
93 UINT64 Rand64;
94
95 if (ArchGetRandomNumber64 (&Rand64)) {
96 *Rand = Rand64 & MAX_UINT32;
97 return TRUE;
98 }
99
100 return FALSE;
101}
102
112BOOLEAN
113EFIAPI
115 OUT UINT64 *Rand
116 )
117{
118 return ArmRndr (Rand);
119}
120
128BOOLEAN
129EFIAPI
131 VOID
132 )
133{
134 return mRndrSupported;
135}
136
148EFIAPI
150 GUID *RngGuid
151 )
152{
153 GUID *RngLibGuid;
154
155 if (RngGuid == NULL) {
156 return EFI_INVALID_PARAMETER;
157 }
158
159 if (!mRndrSupported) {
160 return EFI_UNSUPPORTED;
161 }
162
163 //
164 // If the platform advertises the algorithm behind RNDR instruction,
165 // use it. Otherwise use gEfiRngAlgorithmArmRndr.
166 //
167 RngLibGuid = PcdGetPtr (PcdCpuRngSupportedAlgorithm);
168 if (!IsZeroGuid (RngLibGuid)) {
169 CopyMem (RngGuid, RngLibGuid, sizeof (*RngGuid));
170 } else {
171 CopyMem (RngGuid, &gEfiRngAlgorithmArmRndr, sizeof (*RngGuid));
172 }
173
174 return EFI_SUCCESS;
175}
BOOLEAN EFIAPI ArmRndr(OUT UINT64 *Rand)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI IsZeroGuid(IN CONST GUID *Guid)
Definition: MemLibGuid.c:156
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define OUT
Definition: Base.h:284
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
BOOLEAN EFIAPI ArchGetRandomNumber16(OUT UINT16 *Rand)
Definition: Rndr.c:64
EFI_STATUS EFIAPI BaseRngLibConstructor(VOID)
Definition: Rndr.c:37
BOOLEAN EFIAPI ArchGetRandomNumber64(OUT UINT64 *Rand)
Definition: Rndr.c:114
BOOLEAN EFIAPI ArchGetRandomNumber32(OUT UINT32 *Rand)
Definition: Rndr.c:89
EFI_STATUS EFIAPI GetRngGuid(GUID *RngGuid)
Definition: Rndr.c:149
BOOLEAN EFIAPI ArchIsRngSupported(VOID)
Definition: Rndr.c:130
UINTN Rand(VOID)
Definition: Support.c:39
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213