TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeCrc32GuidedSectionExtractLib.c
Go to the documentation of this file.
1
12#include <PiDxe.h>
16#include <Library/DebugLib.h>
19
23typedef struct {
27
28typedef struct {
32
50EFIAPI
52 IN CONST VOID *InputSection,
53 OUT UINT32 *OutputBufferSize,
54 OUT UINT32 *ScratchBufferSize,
55 OUT UINT16 *SectionAttribute
56 )
57{
58 if (IS_SECTION2 (InputSection)) {
59 //
60 // Check whether the input guid section is recognized.
61 //
62 if (!CompareGuid (
63 &gEfiCrc32GuidedSectionExtractionGuid,
64 &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)
65 ))
66 {
67 return EFI_INVALID_PARAMETER;
68 }
69
70 //
71 // Retrieve the size and attribute of the input section data.
72 //
73 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->Attributes;
74 *ScratchBufferSize = 0;
75 *OutputBufferSize = SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset;
76 } else {
77 //
78 // Check whether the input guid section is recognized.
79 //
80 if (!CompareGuid (
81 &gEfiCrc32GuidedSectionExtractionGuid,
82 &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)
83 ))
84 {
85 return EFI_INVALID_PARAMETER;
86 }
87
88 //
89 // Retrieve the size and attribute of the input section data.
90 //
91 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *)InputSection)->Attributes;
92 *ScratchBufferSize = 0;
93 *OutputBufferSize = SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset;
94 }
95
96 return EFI_SUCCESS;
97}
98
117EFIAPI
119 IN CONST VOID *InputSection,
120 OUT VOID **OutputBuffer,
121 IN VOID *ScratchBuffer OPTIONAL,
122 OUT UINT32 *AuthenticationStatus
123 )
124{
125 EFI_STATUS Status;
126 UINT32 SectionCrc32Checksum;
127 UINT32 Crc32Checksum;
128 UINT32 OutputBufferSize;
129 VOID *DummyInterface;
130
131 if (IS_SECTION2 (InputSection)) {
132 //
133 // Check whether the input guid section is recognized.
134 //
135 if (!CompareGuid (
136 &gEfiCrc32GuidedSectionExtractionGuid,
137 &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)
138 ))
139 {
140 return EFI_INVALID_PARAMETER;
141 }
142
143 //
144 // Get section Crc32 checksum.
145 //
146 SectionCrc32Checksum = ((CRC32_SECTION2_HEADER *)InputSection)->CRC32Checksum;
147 *OutputBuffer = (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset;
148 OutputBufferSize = SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset;
149
150 //
151 // Implicitly CRC32 GUIDed section should have STATUS_VALID bit set
152 //
153 ASSERT (((EFI_GUID_DEFINED_SECTION2 *)InputSection)->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);
154 *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;
155 } else {
156 //
157 // Check whether the input guid section is recognized.
158 //
159 if (!CompareGuid (
160 &gEfiCrc32GuidedSectionExtractionGuid,
161 &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)
162 ))
163 {
164 return EFI_INVALID_PARAMETER;
165 }
166
167 //
168 // Get section Crc32 checksum.
169 //
170 SectionCrc32Checksum = ((CRC32_SECTION_HEADER *)InputSection)->CRC32Checksum;
171 *OutputBuffer = (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset;
172 OutputBufferSize = SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset;
173
174 //
175 // Implicitly CRC32 GUIDed section should have STATUS_VALID bit set
176 //
177 ASSERT (((EFI_GUID_DEFINED_SECTION *)InputSection)->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);
178 *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;
179 }
180
181 //
182 // Init Checksum value to Zero.
183 //
184 Crc32Checksum = 0;
185
186 //
187 // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.
188 //
189 Status = gBS->LocateProtocol (&gEfiSecurityPolicyProtocolGuid, NULL, &DummyInterface);
190 if (!EFI_ERROR (Status)) {
191 //
192 // If SecurityPolicy Protocol exist, AUTH platform override bit is set.
193 //
194 *AuthenticationStatus |= EFI_AUTH_STATUS_PLATFORM_OVERRIDE;
195 } else {
196 //
197 // Calculate CRC32 Checksum of Image
198 //
199 Status = gBS->CalculateCrc32 (*OutputBuffer, OutputBufferSize, &Crc32Checksum);
200 if (Status == EFI_SUCCESS) {
201 if (Crc32Checksum != SectionCrc32Checksum) {
202 //
203 // If Crc32 checksum is not matched, AUTH tested failed bit is set.
204 //
205 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
206 }
207 } else {
208 //
209 // If Crc32 checksum is not calculated, AUTH not tested bit is set.
210 //
211 *AuthenticationStatus |= EFI_AUTH_STATUS_NOT_TESTED;
212 }
213 }
214
215 return EFI_SUCCESS;
216}
217
228EFIAPI
230 IN EFI_HANDLE ImageHandle,
231 IN EFI_SYSTEM_TABLE *SystemTable
232 )
233{
235 &gEfiCrc32GuidedSectionExtractionGuid,
238 );
239}
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS EFIAPI DxeCrc32GuidedSectionExtractLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI Crc32GuidedSectionHandler(IN CONST VOID *InputSection, OUT VOID **OutputBuffer, IN VOID *ScratchBuffer OPTIONAL, OUT UINT32 *AuthenticationStatus)
EFI_STATUS EFIAPI Crc32GuidedSectionGetInfo(IN CONST VOID *InputSection, OUT UINT32 *OutputBufferSize, OUT UINT32 *ScratchBufferSize, OUT UINT16 *SectionAttribute)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define SECTION_SIZE(SectionHeaderPtr)
#define EFI_AUTH_STATUS_PLATFORM_OVERRIDE
Definition: PiMultiPhase.h:91
RETURN_STATUS EFIAPI ExtractGuidedSectionRegisterHandlers(IN CONST GUID *SectionGuid, IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler, IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
UINT32 CRC32Checksum
32bit CRC check sum
EFI_GUID_DEFINED_SECTION2 GuidedSectionHeader
EFI guided section header.
EFI_GUID_DEFINED_SECTION GuidedSectionHeader
EFI guided section header.
UINT32 CRC32Checksum
32bit CRC check sum