36 #ifdef MDE_CPU_AARCH64
38 &gEfiRngAlgorithmArmRndr,
44 &gEfiRngAlgorithmSp80090Ctr256Guid,
49 &gEfiRngAlgorithmSp80090Hmac256Guid,
54 &gEfiRngAlgorithmSp80090Hash256Guid,
89 Status =
gBS->LocateProtocol (&gEfiRngProtocolGuid,
NULL, (VOID **)&mRngProtocol);
90 if (EFI_ERROR (Status) || (mRngProtocol ==
NULL)) {
91 DEBUG ((DEBUG_ERROR,
"%a: Could not locate RNG protocol, Status = %r\n", __func__, Status));
97 Status = mRngProtocol->GetInfo (mRngProtocol, &RngArraySize,
NULL);
98 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
100 }
else if (RngArraySize == 0) {
101 return EFI_NOT_FOUND;
104 RngArrayCnt = RngArraySize /
sizeof (*RngArray);
107 if (RngArray ==
NULL) {
108 return EFI_OUT_OF_RESOURCES;
111 Status = mRngProtocol->GetInfo (mRngProtocol, &RngArraySize, RngArray);
112 if (EFI_ERROR (Status)) {
116 for (Index = 0; Index < RngArrayCnt; Index++) {
117 for (Index1 = 0; Index1 <
ARRAY_SIZE (mSecureHashAlgorithms); Index1++) {
118 if (
CompareGuid (&RngArray[Index], mSecureHashAlgorithms[Index1].Guid)) {
120 if (mFirstAlgo == MAX_UINTN) {
158 if (Buffer ==
NULL) {
159 DEBUG ((DEBUG_ERROR,
"%a: Buffer == NULL.\n", __func__));
160 return EFI_INVALID_PARAMETER;
163 if (mRngProtocol ==
NULL) {
164 return EFI_NOT_FOUND;
168 if (mFirstAlgo != MAX_UINTN) {
169 Algo = &mSecureHashAlgorithms[mFirstAlgo];
170 Status = mRngProtocol->GetRNG (mRngProtocol, Algo->
Guid, BufferSize, Buffer);
173 "%a: GetRNG algorithm %a - Status = %r\n",
178 if (!EFI_ERROR (Status)) {
182 Index = mFirstAlgo + 1;
188 for ( ; Index <
ARRAY_SIZE (mSecureHashAlgorithms); Index++) {
189 Algo = &mSecureHashAlgorithms[Index];
194 Status = mRngProtocol->GetRNG (mRngProtocol, Algo->
Guid, BufferSize, Buffer);
197 "%a: GetRNG algorithm %a - Status = %r\n",
202 if (!EFI_ERROR (Status)) {
207 if (!
PcdGetBool (PcdEnforceSecureRngAlgorithms)) {
209 Status = mRngProtocol->GetRNG (mRngProtocol,
NULL, BufferSize, Buffer);
210 DEBUG ((DEBUG_INFO,
"%a: GetRNG algorithm default - Status = %r\n", __func__, Status));
211 if (!EFI_ERROR (Status)) {
217 DEBUG ((DEBUG_ERROR,
"%a: GetRNG() failed, Status = %r\n", __func__, Status));
246 if (EFI_ERROR (Status)) {
277 if (EFI_ERROR (Status)) {
308 if (EFI_ERROR (Status)) {
339 if (EFI_ERROR (Status)) {
370 return EFI_UNSUPPORTED;
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
BOOLEAN EFIAPI GetRandomNumber16(OUT UINT16 *Rand)
EFI_STATUS EFIAPI GetRngGuid(GUID *RngGuid)
BOOLEAN EFIAPI GetRandomNumber32(OUT UINT32 *Rand)
BOOLEAN EFIAPI GetRandomNumber128(OUT UINT64 *Rand)
EFI_STATUS EFIAPI DxeRngLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC EFI_STATUS GenerateRandomNumberViaNist800Algorithm(OUT UINT8 *Buffer, IN UINTN BufferSize)
BOOLEAN EFIAPI GetRandomNumber64(OUT UINT64 *Rand)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define ARRAY_SIZE(Array)
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define DEBUG(Expression)
#define PcdGetBool(TokenName)
BOOLEAN Available
The algorithm is available for use.
CONST CHAR8 * Name
Algorithm name.
EFI_GUID * Guid
Guid of the secure algorithm.