2 Function prototypes for UEFI Random Number Generator protocol support.
4 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef RNGDXE_INTERNALS_H_
11 #define RNGDXE_INTERNALS_H_
13 #include <Protocol/Rng.h>
16 // Array containing the validated Rng algorithm.
17 // The entry with the lowest index will be the default algorithm.
19 extern UINTN mAvailableAlgoArrayCount
;
20 extern EFI_RNG_ALGORITHM
*mAvailableAlgoArray
;
22 /** Allocate and initialize mAvailableAlgoArray with the available
23 Rng algorithms. Also update mAvailableAlgoArrayCount.
25 @retval EFI_SUCCESS The function completed successfully.
26 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.
30 GetAvailableAlgorithms (
34 /** Free mAvailableAlgoArray.
38 FreeAvailableAlgorithms (
43 Returns information about the random number generation implementation.
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.
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.
68 IN EFI_RNG_PROTOCOL
*This
,
69 IN OUT UINTN
*RNGAlgorithmListSize
,
70 OUT EFI_RNG_ALGORITHM
*RNGAlgorithmList
74 Produces and returns an RNG value using either the default or specified RNG algorithm.
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
85 @retval EFI_SUCCESS The RNG value was returned successfully.
86 @retval EFI_UNSUPPORTED The algorithm specified by RNGAlgorithm is not supported by
88 @retval EFI_DEVICE_ERROR An RNG value could not be retrieved due to a hardware or
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.
98 IN EFI_RNG_PROTOCOL
*This
,
99 IN EFI_RNG_ALGORITHM
*RNGAlgorithm OPTIONAL
,
100 IN UINTN RNGValueLength
,
105 Runs CPU RNG instruction to fill a buffer of arbitrary size with random bytes.
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.
110 @retval EFI_SUCCESS Random bytes generation succeeded.
111 @retval EFI_NOT_READY Failed to request random bytes.
118 OUT UINT8
*RandBuffer
122 Generate high-quality entropy source using a TRNG or through RDRAND.
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.
127 @retval EFI_SUCCESS Entropy generation succeeded.
128 @retval EFI_NOT_READY Failed to request random data.
138 #endif // RNGDXE_INTERNALS_H_