TianoCore EDK2 master
Loading...
Searching...
No Matches
ArmRngDxe.c
Go to the documentation of this file.
1
25#include <Library/BaseLib.h>
27#include <Library/DebugLib.h>
30#include <Library/RngLib.h>
31#include <Protocol/Rng.h>
32
33#include "RngDxeInternals.h"
34
37VOID
38EFIAPI
40 VOID
41 )
42{
43 mAvailableAlgoArrayCount = 0;
44 FreePool (mAvailableAlgoArray);
45 return;
46}
47
71EFIAPI
73 IN EFI_RNG_PROTOCOL *This,
74 IN EFI_RNG_ALGORITHM *RNGAlgorithm OPTIONAL,
75 IN UINTN RNGValueLength,
76 OUT UINT8 *RNGValue
77 )
78{
79 EFI_STATUS Status;
80 GUID RngGuid;
81
82 if ((This == NULL) || (RNGValueLength == 0) || (RNGValue == NULL)) {
83 return EFI_INVALID_PARAMETER;
84 }
85
86 if (RNGAlgorithm == NULL) {
87 //
88 // Use the default RNG algorithm if RNGAlgorithm is NULL.
89 //
90 if (mAvailableAlgoArrayCount != 0) {
91 RNGAlgorithm = &mAvailableAlgoArray[0];
92 } else {
93 return EFI_UNSUPPORTED;
94 }
95 }
96
97 Status = GetRngGuid (&RngGuid);
98 if (!EFI_ERROR (Status) &&
99 CompareGuid (RNGAlgorithm, &RngGuid))
100 {
101 Status = RngGetBytes (RNGValueLength, RNGValue);
102 return Status;
103 }
104
105 // Raw algorithm (Trng)
106 if (CompareGuid (RNGAlgorithm, &gEfiRngAlgorithmRaw)) {
107 return GenerateEntropy (RNGValueLength, RNGValue);
108 }
109
110 //
111 // Other algorithms are unsupported by this driver.
112 //
113 return EFI_UNSUPPORTED;
114}
115
140EFIAPI
142 IN EFI_RNG_PROTOCOL *This,
143 IN OUT UINTN *RNGAlgorithmListSize,
144 OUT EFI_RNG_ALGORITHM *RNGAlgorithmList
145 )
146{
147 UINTN RequiredSize;
148
149 if ((This == NULL) || (RNGAlgorithmListSize == NULL)) {
150 return EFI_INVALID_PARAMETER;
151 }
152
153 RequiredSize = mAvailableAlgoArrayCount * sizeof (EFI_RNG_ALGORITHM);
154
155 if (RequiredSize == 0) {
156 // No supported algorithms found.
157 return EFI_UNSUPPORTED;
158 }
159
160 if (*RNGAlgorithmListSize < RequiredSize) {
161 *RNGAlgorithmListSize = RequiredSize;
162 return EFI_BUFFER_TOO_SMALL;
163 }
164
165 if (RNGAlgorithmList == NULL) {
166 return EFI_INVALID_PARAMETER;
167 }
168
169 // There is no gap in the array, so copy the block.
170 CopyMem (RNGAlgorithmList, mAvailableAlgoArray, RequiredSize);
171 *RNGAlgorithmListSize = RequiredSize;
172 return EFI_SUCCESS;
173}
UINT64 UINTN
VOID EFIAPI FreeAvailableAlgorithms(VOID)
Definition: ArmRngDxe.c:39
EFI_STATUS EFIAPI RngGetInfo(IN EFI_RNG_PROTOCOL *This, IN OUT UINTN *RNGAlgorithmListSize, OUT EFI_RNG_ALGORITHM *RNGAlgorithmList)
Definition: ArmRngDxe.c:141
EFI_STATUS EFIAPI RngGetRNG(IN EFI_RNG_PROTOCOL *This, IN EFI_RNG_ALGORITHM *RNGAlgorithm OPTIONAL, IN UINTN RNGValueLength, OUT UINT8 *RNGValue)
Definition: ArmRngDxe.c:72
EFI_STATUS EFIAPI GenerateEntropy(IN UINTN Length, OUT UINT8 *Entropy)
Definition: ArmTrng.c:35
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
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI GetRngGuid(GUID *RngGuid)
Definition: RngLibTimer.c:210
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_GUID EFI_RNG_ALGORITHM
Definition: Rng.h:30
EFI_STATUS EFIAPI RngGetBytes(IN UINTN Length, OUT UINT8 *RandBuffer)
Definition: RngDxe.c:132
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213