]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Include/Guid/AuthenticatedVariableFormat.h
SecurityPkg: Implement AuthVariableLib library instance
[mirror_edk2.git] / SecurityPkg / Include / Guid / AuthenticatedVariableFormat.h
1 /** @file
2 The variable data structures are related to EDKII-specific
3 implementation of UEFI authenticated variables.
4 AuthenticatedVariableFormat.h defines variable data headers
5 and variable storage region headers.
6
7 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #ifndef __AUTHENTICATED_VARIABLE_FORMAT_H__
19 #define __AUTHENTICATED_VARIABLE_FORMAT_H__
20
21 #define EFI_AUTHENTICATED_VARIABLE_GUID \
22 { 0xaaf32c78, 0x947b, 0x439a, { 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92 } }
23
24 #define EFI_SECURE_BOOT_ENABLE_DISABLE \
25 { 0xf0a30bc7, 0xaf08, 0x4556, { 0x99, 0xc4, 0x0, 0x10, 0x9, 0xc9, 0x3a, 0x44 } }
26
27
28 extern EFI_GUID gEfiAuthenticatedVariableGuid;
29 extern EFI_GUID gEfiSecureBootEnableDisableGuid;
30 extern EFI_GUID gEfiCertDbGuid;
31 extern EFI_GUID gEfiCustomModeEnableGuid;
32 extern EFI_GUID gEfiVendorKeysNvGuid;
33
34 ///
35 /// "SecureBootEnable" variable for the Secure Boot feature enable/disable.
36 /// This variable is used for allowing a physically present user to disable
37 /// Secure Boot via firmware setup without the possession of PKpriv.
38 ///
39 #define EFI_SECURE_BOOT_ENABLE_NAME L"SecureBootEnable"
40 #define SECURE_BOOT_ENABLE 1
41 #define SECURE_BOOT_DISABLE 0
42
43 ///
44 /// "CustomMode" variable for two Secure Boot modes feature: "Custom" and "Standard".
45 /// Standard Secure Boot mode is the default mode as UEFI Spec's description.
46 /// Custom Secure Boot mode allows for more flexibility as specified in the following:
47 /// Can enroll or delete PK without existing PK's private key.
48 /// Can enroll or delete KEK without existing PK's private key.
49 /// Can enroll or delete signature from DB/DBX without KEK's private key.
50 ///
51 #define EFI_CUSTOM_MODE_NAME L"CustomMode"
52 #define CUSTOM_SECURE_BOOT_MODE 1
53 #define STANDARD_SECURE_BOOT_MODE 0
54
55 ///
56 /// "VendorKeysNv" variable to record the out of band secure boot keys modification.
57 /// This variable is a read-only NV varaible that indicates whether someone other than
58 /// the platform vendor has used a mechanism not defined by the UEFI Specification to
59 /// transition the system to setup mode or to update secure boot keys.
60 ///
61 #define EFI_VENDOR_KEYS_NV_VARIABLE_NAME L"VendorKeysNv"
62 #define VENDOR_KEYS_VALID 1
63 #define VENDOR_KEYS_MODIFIED 0
64
65 ///
66 /// Alignment of variable name and data, according to the architecture:
67 /// * For IA-32 and Intel(R) 64 architectures: 1.
68 /// * For IA-64 architecture: 8.
69 ///
70 #if defined (MDE_CPU_IPF)
71 #define ALIGNMENT 8
72 #else
73 #define ALIGNMENT 1
74 #endif
75
76 //
77 // GET_PAD_SIZE calculates the miminal pad bytes needed to make the current pad size satisfy the alignment requirement.
78 //
79 #if (ALIGNMENT == 1)
80 #define GET_PAD_SIZE(a) (0)
81 #else
82 #define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))
83 #endif
84
85 ///
86 /// Alignment of Variable Data Header in Variable Store region.
87 ///
88 #define HEADER_ALIGNMENT 4
89 #define HEADER_ALIGN(Header) (((UINTN) (Header) + HEADER_ALIGNMENT - 1) & (~(HEADER_ALIGNMENT - 1)))
90
91 ///
92 /// Status of Variable Store Region.
93 ///
94 typedef enum {
95 EfiRaw,
96 EfiValid,
97 EfiInvalid,
98 EfiUnknown
99 } VARIABLE_STORE_STATUS;
100
101 #pragma pack(1)
102
103 #define VARIABLE_STORE_SIGNATURE EFI_AUTHENTICATED_VARIABLE_GUID
104
105 ///
106 /// Variable Store Header Format and State.
107 ///
108 #define VARIABLE_STORE_FORMATTED 0x5a
109 #define VARIABLE_STORE_HEALTHY 0xfe
110
111 ///
112 /// Variable Store region header.
113 ///
114 typedef struct {
115 ///
116 /// Variable store region signature.
117 ///
118 EFI_GUID Signature;
119 ///
120 /// Size of entire variable store,
121 /// including size of variable store header but not including the size of FvHeader.
122 ///
123 UINT32 Size;
124 ///
125 /// Variable region format state.
126 ///
127 UINT8 Format;
128 ///
129 /// Variable region healthy state.
130 ///
131 UINT8 State;
132 UINT16 Reserved;
133 UINT32 Reserved1;
134 } VARIABLE_STORE_HEADER;
135
136 ///
137 /// Variable data start flag.
138 ///
139 #define VARIABLE_DATA 0x55AA
140
141 ///
142 /// Variable State flags.
143 ///
144 #define VAR_IN_DELETED_TRANSITION 0xfe ///< Variable is in obsolete transition.
145 #define VAR_DELETED 0xfd ///< Variable is obsolete.
146 #define VAR_HEADER_VALID_ONLY 0x7f ///< Variable header has been valid.
147 #define VAR_ADDED 0x3f ///< Variable has been completely added.
148
149 ///
150 /// Variable Attribute combinations.
151 ///
152 #define VARIABLE_ATTRIBUTE_NV_BS (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)
153 #define VARIABLE_ATTRIBUTE_BS_RT (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)
154 #define VARIABLE_ATTRIBUTE_AT_AW (EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
155 #define VARIABLE_ATTRIBUTE_NV_BS_RT (VARIABLE_ATTRIBUTE_BS_RT | EFI_VARIABLE_NON_VOLATILE)
156 #define VARIABLE_ATTRIBUTE_NV_BS_RT_HR (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_HARDWARE_ERROR_RECORD)
157 #define VARIABLE_ATTRIBUTE_NV_BS_RT_AT (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
158 #define VARIABLE_ATTRIBUTE_NV_BS_RT_AW (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
159 #define VARIABLE_ATTRIBUTE_NV_BS_RT_HR_AT_AW (VARIABLE_ATTRIBUTE_NV_BS_RT_HR | VARIABLE_ATTRIBUTE_AT_AW)
160
161 /// Single Variable Data Header Structure.
162 ///
163 typedef struct {
164 ///
165 /// Variable Data Start Flag.
166 ///
167 UINT16 StartId;
168 ///
169 /// Variable State defined above.
170 ///
171 UINT8 State;
172 UINT8 Reserved;
173 ///
174 /// Attributes of variable defined in UEFI specification.
175 ///
176 UINT32 Attributes;
177 ///
178 /// Associated monotonic count value against replay attack.
179 ///
180 UINT64 MonotonicCount;
181 ///
182 /// Associated TimeStamp value against replay attack.
183 ///
184 EFI_TIME TimeStamp;
185 ///
186 /// Index of associated public key in database.
187 ///
188 UINT32 PubKeyIndex;
189 ///
190 /// Size of variable null-terminated Unicode string name.
191 ///
192 UINT32 NameSize;
193 ///
194 /// Size of the variable data without this header.
195 ///
196 UINT32 DataSize;
197 ///
198 /// A unique identifier for the vendor that produces and consumes this varaible.
199 ///
200 EFI_GUID VendorGuid;
201 } VARIABLE_HEADER;
202
203 typedef struct {
204 EFI_GUID *Guid;
205 CHAR16 *Name;
206 UINTN VariableSize;
207 } VARIABLE_ENTRY_CONSISTENCY;
208
209 #pragma pack()
210
211 typedef struct _VARIABLE_INFO_ENTRY VARIABLE_INFO_ENTRY;
212
213 ///
214 /// This structure contains the variable list that is put in EFI system table.
215 /// The variable driver collects all variables that were used at boot service time and produces this list.
216 /// This is an optional feature to dump all used variables in shell environment.
217 ///
218 struct _VARIABLE_INFO_ENTRY {
219 VARIABLE_INFO_ENTRY *Next; ///< Pointer to next entry.
220 EFI_GUID VendorGuid; ///< Guid of Variable.
221 CHAR16 *Name; ///< Name of Variable.
222 UINT32 Attributes; ///< Attributes of variable defined in UEFI spec.
223 UINT32 ReadCount; ///< Number of times to read this variable.
224 UINT32 WriteCount; ///< Number of times to write this variable.
225 UINT32 DeleteCount; ///< Number of times to delete this variable.
226 UINT32 CacheCount; ///< Number of times that cache hits this variable.
227 BOOLEAN Volatile; ///< TRUE if volatile, FALSE if non-volatile.
228 };
229
230 #endif // __AUTHENTICATED_VARIABLE_FORMAT_H__