TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptRand.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include <openssl/rand.h>
11#include <openssl/evp.h>
12
13//
14// Default seed for UEFI Crypto Library
15//
16CONST UINT8 DefaultSeed[] = "UEFI Crypto Library default seed";
17
34BOOLEAN
35EFIAPI
37 IN CONST UINT8 *Seed OPTIONAL,
38 IN UINTN SeedSize
39 )
40{
41 if (SeedSize > INT_MAX) {
42 return FALSE;
43 }
44
45 //
46 // Seed the pseudorandom number generator with user-supplied value.
47 // NOTE: A cryptographic PRNG must be seeded with unpredictable data.
48 //
49 if (Seed != NULL) {
50 RAND_seed (Seed, (UINT32)SeedSize);
51 } else {
52 RAND_seed (DefaultSeed, sizeof (DefaultSeed));
53 }
54
55 if (RAND_status () == 1) {
56 return TRUE;
57 }
58
59 return FALSE;
60}
61
74BOOLEAN
75EFIAPI
77 OUT UINT8 *Output,
78 IN UINTN Size
79 )
80{
81 //
82 // Check input parameters.
83 //
84 if ((Output == NULL) || (Size > INT_MAX)) {
85 return FALSE;
86 }
87
88 //
89 // Generate random data.
90 //
91 if (RAND_bytes (Output, (UINT32)Size) != 1) {
92 return FALSE;
93 }
94
95 return TRUE;
96}
UINT64 UINTN
#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