]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / SecurityPkg / RandomNumberGenerator / RngDxe / RngDxeInternals.h
1 /** @file
2 Function prototypes for UEFI Random Number Generator protocol support.
3
4 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef RNGDXE_INTERNALS_H_
11 #define RNGDXE_INTERNALS_H_
12
13 #include <Protocol/Rng.h>
14
15 //
16 // Array containing the validated Rng algorithm.
17 // The entry with the lowest index will be the default algorithm.
18 //
19 extern UINTN mAvailableAlgoArrayCount;
20 extern EFI_RNG_ALGORITHM *mAvailableAlgoArray;
21
22 /** Allocate and initialize mAvailableAlgoArray with the available
23 Rng algorithms. Also update mAvailableAlgoArrayCount.
24
25 @retval EFI_SUCCESS The function completed successfully.
26 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.
27 **/
28 EFI_STATUS
29 EFIAPI
30 GetAvailableAlgorithms (
31 VOID
32 );
33
34 /** Free mAvailableAlgoArray.
35 **/
36 VOID
37 EFIAPI
38 FreeAvailableAlgorithms (
39 VOID
40 );
41
42 /**
43 Returns information about the random number generation implementation.
44
45 @param[in] This A pointer to the EFI_RNG_PROTOCOL instance.
46 @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAlgorithmList.
47 On output with a return code of EFI_SUCCESS, the size
48 in bytes of the data returned in RNGAlgorithmList. On output
49 with a return code of EFI_BUFFER_TOO_SMALL,
50 the size of RNGAlgorithmList required to obtain the list.
51 @param[out] RNGAlgorithmList A caller-allocated memory buffer filled by the driver
52 with one EFI_RNG_ALGORITHM element for each supported
53 RNG algorithm. The list must not change across multiple
54 calls to the same driver. The first algorithm in the list
55 is the default algorithm for the driver.
56
57 @retval EFI_SUCCESS The RNG algorithm list was returned successfully.
58 @retval EFI_UNSUPPORTED The services is not supported by this driver.
59 @retval EFI_DEVICE_ERROR The list of algorithms could not be retrieved due to a
60 hardware or firmware error.
61 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
62 @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too small to hold the result.
63
64 **/
65 EFI_STATUS
66 EFIAPI
67 RngGetInfo (
68 IN EFI_RNG_PROTOCOL *This,
69 IN OUT UINTN *RNGAlgorithmListSize,
70 OUT EFI_RNG_ALGORITHM *RNGAlgorithmList
71 );
72
73 /**
74 Produces and returns an RNG value using either the default or specified RNG algorithm.
75
76 @param[in] This A pointer to the EFI_RNG_PROTOCOL instance.
77 @param[in] RNGAlgorithm A pointer to the EFI_RNG_ALGORITHM that identifies the RNG
78 algorithm to use. May be NULL in which case the function will
79 use its default RNG algorithm.
80 @param[in] RNGValueLength The length in bytes of the memory buffer pointed to by
81 RNGValue. The driver shall return exactly this numbers of bytes.
82 @param[out] RNGValue A caller-allocated memory buffer filled by the driver with the
83 resulting RNG value.
84
85 @retval EFI_SUCCESS The RNG value was returned successfully.
86 @retval EFI_UNSUPPORTED The algorithm specified by RNGAlgorithm is not supported by
87 this driver.
88 @retval EFI_DEVICE_ERROR An RNG value could not be retrieved due to a hardware or
89 firmware error.
90 @retval EFI_NOT_READY There is not enough random data available to satisfy the length
91 requested by RNGValueLength.
92 @retval EFI_INVALID_PARAMETER RNGValue is NULL or RNGValueLength is zero.
93
94 **/
95 EFI_STATUS
96 EFIAPI
97 RngGetRNG (
98 IN EFI_RNG_PROTOCOL *This,
99 IN EFI_RNG_ALGORITHM *RNGAlgorithm OPTIONAL,
100 IN UINTN RNGValueLength,
101 OUT UINT8 *RNGValue
102 );
103
104 /**
105 Runs CPU RNG instruction to fill a buffer of arbitrary size with random bytes.
106
107 @param[in] Length Size of the buffer, in bytes, to fill with.
108 @param[out] RandBuffer Pointer to the buffer to store the random result.
109
110 @retval EFI_SUCCESS Random bytes generation succeeded.
111 @retval EFI_NOT_READY Failed to request random bytes.
112
113 **/
114 EFI_STATUS
115 EFIAPI
116 RngGetBytes (
117 IN UINTN Length,
118 OUT UINT8 *RandBuffer
119 );
120
121 /**
122 Generate high-quality entropy source using a TRNG or through RDRAND.
123
124 @param[in] Length Size of the buffer, in bytes, to fill with.
125 @param[out] Entropy Pointer to the buffer to store the entropy data.
126
127 @retval EFI_SUCCESS Entropy generation succeeded.
128 @retval EFI_NOT_READY Failed to request random data.
129
130 **/
131 EFI_STATUS
132 EFIAPI
133 GenerateEntropy (
134 IN UINTN Length,
135 OUT UINT8 *Entropy
136 );
137
138 #endif // RNGDXE_INTERNALS_H_