TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptRand.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include <Library/RngLib.h>
11
28BOOLEAN
29EFIAPI
31 IN CONST UINT8 *Seed OPTIONAL,
32 IN UINTN SeedSize
33 )
34{
35 return TRUE;
36}
37
50BOOLEAN
51EFIAPI
53 OUT UINT8 *Output,
54 IN UINTN Size
55 )
56{
57 BOOLEAN Ret;
58 volatile UINT64 TempRand;
59
60 //
61 // Check input parameters.
62 //
63 if ((Output == NULL) || (Size > INT_MAX)) {
64 return FALSE;
65 }
66
67 Ret = FALSE;
68
69 while (Size > 0) {
70 // Use RngLib to get random number
71 Ret = GetRandomNumber64 ((UINT64 *)&TempRand);
72
73 if (!Ret) {
74 TempRand = 0;
75 return Ret;
76 }
77
78 if (Size >= sizeof (TempRand)) {
79 *((UINT64 *)Output) = TempRand;
80 Output += sizeof (UINT64);
81 Size -= sizeof (TempRand);
82 } else {
83 CopyMem (Output, (VOID *)&TempRand, Size);
84 Size = 0;
85 }
86 }
87
88 TempRand = 0;
89 return Ret;
90}
91
102INT32
104 VOID *RngState,
105 UINT8 *Output,
106 UINTN Len
107 )
108{
109 BOOLEAN Result;
110
111 Result = RandomBytes (Output, Len);
112
113 return Result ? 0 : -1;
114}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI GetRandomNumber64(OUT UINT64 *Rand)
Definition: RngLibTimer.c:142
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
BOOLEAN EFIAPI RandomBytes(OUT UINT8 *Output, IN UINTN Size)
Definition: CryptRand.c:76
BOOLEAN EFIAPI RandomSeed(IN CONST UINT8 *Seed OPTIONAL, IN UINTN SeedSize)
Definition: CryptRand.c:36
INT32 MbedtlsRand(VOID *RngState, UINT8 *Output, UINTN Len)
Definition: CryptRand.c:103