TianoCore EDK2 master
Loading...
Searching...
No Matches
RngDxe.c
Go to the documentation of this file.
1
24#include <Library/BaseLib.h>
26#include <Library/RngLib.h>
27
28#include "RngDxeInternals.h"
29
30//
31// Count of Rng algorithms.
32//
33#define RNG_ALGORITHM_COUNT 2
34
42EFIAPI
44 VOID
45 )
46{
47 UINT64 RngTest;
48
49 if (GetRandomNumber64 (&RngTest)) {
50 mAvailableAlgoArrayCount = RNG_ALGORITHM_COUNT;
51 }
52
53 return EFI_SUCCESS;
54}
55
58VOID
59EFIAPI
61 VOID
62 )
63{
64 mAvailableAlgoArrayCount = 0;
65 return;
66}
67
91EFIAPI
93 IN EFI_RNG_PROTOCOL *This,
94 IN EFI_RNG_ALGORITHM *RNGAlgorithm OPTIONAL,
95 IN UINTN RNGValueLength,
96 OUT UINT8 *RNGValue
97 )
98{
99 EFI_STATUS Status;
100
101 if ((This == NULL) || (RNGValueLength == 0) || (RNGValue == NULL)) {
102 return EFI_INVALID_PARAMETER;
103 }
104
105 Status = EFI_UNSUPPORTED;
106 if (RNGAlgorithm == NULL) {
107 //
108 // Use the default RNG algorithm if RNGAlgorithm is NULL.
109 //
110 RNGAlgorithm = &gEfiRngAlgorithmSp80090Ctr256Guid;
111 }
112
113 //
114 // NIST SP800-90-AES-CTR-256 supported by RDRAND
115 //
116 if (CompareGuid (RNGAlgorithm, &gEfiRngAlgorithmSp80090Ctr256Guid)) {
117 Status = RngGetBytes (RNGValueLength, RNGValue);
118 return Status;
119 }
120
121 //
122 // The "raw" algorithm is intended to provide entropy directly
123 //
124 if (CompareGuid (RNGAlgorithm, &gEfiRngAlgorithmRaw)) {
125 Status = GenerateEntropy (RNGValueLength, RNGValue);
126 return Status;
127 }
128
129 //
130 // Other algorithms were unsupported by this driver.
131 //
132 return Status;
133}
134
159EFIAPI
161 IN EFI_RNG_PROTOCOL *This,
162 IN OUT UINTN *RNGAlgorithmListSize,
163 OUT EFI_RNG_ALGORITHM *RNGAlgorithmList
164 )
165{
166 UINTN RequiredSize;
167
168 if ((This == NULL) || (RNGAlgorithmListSize == NULL)) {
169 return EFI_INVALID_PARAMETER;
170 }
171
172 RequiredSize = RNG_ALGORITHM_COUNT * sizeof (EFI_RNG_ALGORITHM);
173
174 if (*RNGAlgorithmListSize < RequiredSize) {
175 *RNGAlgorithmListSize = RequiredSize;
176 return EFI_BUFFER_TOO_SMALL;
177 }
178
179 if (RNGAlgorithmList == NULL) {
180 return EFI_INVALID_PARAMETER;
181 }
182
183 CopyMem (&RNGAlgorithmList[0], &gEfiRngAlgorithmSp80090Ctr256Guid, sizeof (EFI_RNG_ALGORITHM));
184
185 // x86 platforms also support EFI_RNG_ALGORITHM_RAW via RDSEED
186 CopyMem (&RNGAlgorithmList[1], &gEfiRngAlgorithmRaw, sizeof (EFI_RNG_ALGORITHM));
187
188 *RNGAlgorithmListSize = RequiredSize;
189 return EFI_SUCCESS;
190}
UINT64 UINTN
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
BOOLEAN EFIAPI GetRandomNumber64(OUT UINT64 *Rand)
Definition: RngLibTimer.c:142
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI GetAvailableAlgorithms(VOID)
Definition: RngDxe.c:43
VOID EFIAPI FreeAvailableAlgorithms(VOID)
Definition: RngDxe.c:60
EFI_STATUS EFIAPI RngGetInfo(IN EFI_RNG_PROTOCOL *This, IN OUT UINTN *RNGAlgorithmListSize, OUT EFI_RNG_ALGORITHM *RNGAlgorithmList)
Definition: RngDxe.c:160
EFI_STATUS EFIAPI RngGetRNG(IN EFI_RNG_PROTOCOL *This, IN EFI_RNG_ALGORITHM *RNGAlgorithm OPTIONAL, IN UINTN RNGValueLength, OUT UINT8 *RNGValue)
Definition: RngDxe.c:92
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