2 Provides services to initialize and process authenticated variables.
4 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _AUTH_VARIABLE_LIB_H_
10 #define _AUTH_VARIABLE_LIB_H_
12 #include <Protocol/VarCheck.h>
15 /// Size of AuthInfo prior to the data payload.
17 #define AUTHINFO_SIZE ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION, AuthInfo)) + \
18 (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)) + \
19 sizeof (EFI_CERT_BLOCK_RSA_2048_SHA256))
21 #define AUTHINFO2_SIZE(VarAuth2) ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \
22 (UINTN) ((EFI_VARIABLE_AUTHENTICATION_2 *) (VarAuth2))->AuthInfo.Hdr.dwLength)
24 #define OFFSET_OF_AUTHINFO2_CERT_DATA ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \
25 (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)))
34 UINT64 MonotonicCount
;
39 Finds variable in storage blocks of volatile and non-volatile storage areas.
41 This code finds variable in storage blocks of volatile and non-volatile storage areas.
42 If VariableName is an empty string, then we just return the first
43 qualified variable without comparing VariableName and VendorGuid.
45 @param[in] VariableName Name of the variable to be found.
46 @param[in] VendorGuid Variable vendor GUID to be found.
47 @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for
48 output of the variable found.
50 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
51 while VendorGuid is NULL.
52 @retval EFI_SUCCESS Variable successfully found.
53 @retval EFI_NOT_FOUND Variable not found
58 (EFIAPI
*AUTH_VAR_LIB_FIND_VARIABLE
) (
59 IN CHAR16
*VariableName
,
60 IN EFI_GUID
*VendorGuid
,
61 OUT AUTH_VARIABLE_INFO
*AuthVariableInfo
65 Finds next variable in storage blocks of volatile and non-volatile storage areas.
67 This code finds next variable in storage blocks of volatile and non-volatile storage areas.
68 If VariableName is an empty string, then we just return the first
69 qualified variable without comparing VariableName and VendorGuid.
71 @param[in] VariableName Name of the variable to be found.
72 @param[in] VendorGuid Variable vendor GUID to be found.
73 @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for
74 output of the next variable.
76 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
77 while VendorGuid is NULL.
78 @retval EFI_SUCCESS Variable successfully found.
79 @retval EFI_NOT_FOUND Variable not found
84 (EFIAPI
*AUTH_VAR_LIB_FIND_NEXT_VARIABLE
) (
85 IN CHAR16
*VariableName
,
86 IN EFI_GUID
*VendorGuid
,
87 OUT AUTH_VARIABLE_INFO
*AuthVariableInfo
91 Update the variable region with Variable information.
93 @param[in] AuthVariableInfo Pointer AUTH_VARIABLE_INFO structure for
94 input of the variable.
96 @retval EFI_SUCCESS The update operation is success.
97 @retval EFI_INVALID_PARAMETER Invalid parameter.
98 @retval EFI_WRITE_PROTECTED Variable is write-protected.
99 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
104 (EFIAPI
*AUTH_VAR_LIB_UPDATE_VARIABLE
) (
105 IN AUTH_VARIABLE_INFO
*AuthVariableInfo
111 @param[in, out] ScratchBufferSize Scratch buffer size. If input size is greater than
112 the maximum supported buffer size, this value contains
113 the maximum supported buffer size as output.
114 @param[out] ScratchBuffer Pointer to scratch buffer address.
116 @retval EFI_SUCCESS Get scratch buffer successfully.
117 @retval EFI_UNSUPPORTED If input size is greater than the maximum supported buffer size.
122 (EFIAPI
*AUTH_VAR_LIB_GET_SCRATCH_BUFFER
) (
123 IN OUT UINTN
*ScratchBufferSize
,
124 OUT VOID
**ScratchBuffer
128 This function is to check if the remaining variable space is enough to set
129 all Variables from argument list successfully. The purpose of the check
130 is to keep the consistency of the Variables to be in variable storage.
132 Note: Variables are assumed to be in same storage.
133 The set sequence of Variables will be same with the sequence of VariableEntry from argument list,
134 so follow the argument sequence to check the Variables.
136 @param[in] Attributes Variable attributes for Variable entries.
137 @param ... The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.
138 A NULL terminates the list. The VariableSize of
139 VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.
140 It will be changed to variable total size as output.
142 @retval TRUE Have enough variable space to set the Variables successfully.
143 @retval FALSE No enough variable space to set the Variables successfully.
148 (EFIAPI
*AUTH_VAR_LIB_CHECK_REMAINING_SPACE
) (
149 IN UINT32 Attributes
,
154 Return TRUE if at OS runtime.
156 @retval TRUE If at OS runtime.
157 @retval FALSE If at boot time.
162 (EFIAPI
*AUTH_VAR_LIB_AT_RUNTIME
) (
166 #define AUTH_VAR_LIB_CONTEXT_IN_STRUCT_VERSION 0x01
172 // Reflect the overhead associated with the saving
173 // of a single EFI authenticated variable with the exception
174 // of the overhead associated with the length
175 // of the string name of the EFI variable.
177 UINTN MaxAuthVariableSize
;
178 AUTH_VAR_LIB_FIND_VARIABLE FindVariable
;
179 AUTH_VAR_LIB_FIND_NEXT_VARIABLE FindNextVariable
;
180 AUTH_VAR_LIB_UPDATE_VARIABLE UpdateVariable
;
181 AUTH_VAR_LIB_GET_SCRATCH_BUFFER GetScratchBuffer
;
182 AUTH_VAR_LIB_CHECK_REMAINING_SPACE CheckRemainingSpaceForConsistency
;
183 AUTH_VAR_LIB_AT_RUNTIME AtRuntime
;
184 } AUTH_VAR_LIB_CONTEXT_IN
;
186 #define AUTH_VAR_LIB_CONTEXT_OUT_STRUCT_VERSION 0x01
192 // Caller needs to set variable property for the variables.
194 VARIABLE_ENTRY_PROPERTY
*AuthVarEntry
;
195 UINTN AuthVarEntryCount
;
197 // Caller needs to ConvertPointer() for the pointers.
199 VOID
***AddressPointer
;
200 UINTN AddressPointerCount
;
201 } AUTH_VAR_LIB_CONTEXT_OUT
;
204 Initialization for authenticated varibale services.
205 If this initialization returns error status, other APIs will not work
206 and expect to be not called then.
208 @param[in] AuthVarLibContextIn Pointer to input auth variable lib context.
209 @param[out] AuthVarLibContextOut Pointer to output auth variable lib context.
211 @retval EFI_SUCCESS Function successfully executed.
212 @retval EFI_INVALID_PARAMETER If AuthVarLibContextIn == NULL or AuthVarLibContextOut == NULL.
213 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough resource.
214 @retval EFI_UNSUPPORTED Unsupported to process authenticated variable.
219 AuthVariableLibInitialize (
220 IN AUTH_VAR_LIB_CONTEXT_IN
*AuthVarLibContextIn
,
221 OUT AUTH_VAR_LIB_CONTEXT_OUT
*AuthVarLibContextOut
225 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.
227 @param[in] VariableName Name of the variable.
228 @param[in] VendorGuid Variable vendor GUID.
229 @param[in] Data Data pointer.
230 @param[in] DataSize Size of Data.
231 @param[in] Attributes Attribute value of the variable.
233 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
234 defined by the Attributes.
235 @retval EFI_INVALID_PARAMETER Invalid parameter.
236 @retval EFI_WRITE_PROTECTED Variable is write-protected.
237 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
238 @retval EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS
239 set, but the AuthInfo does NOT pass the validation
240 check carried out by the firmware.
241 @retval EFI_UNSUPPORTED Unsupported to process authenticated variable.
246 AuthVariableLibProcessVariable (
247 IN CHAR16
*VariableName
,
248 IN EFI_GUID
*VendorGuid
,