3 Implements CRC32 guided section handler to parse CRC32 encapsulation section,
4 extract data and authenticate 32 bit CRC value.
6 Copyright (c) 2007 - 2008, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Protocol/Crc32GuidedSectionExtraction.h>
19 #include <Protocol/SecurityPolicy.h>
20 #include <Library/ExtractGuidedSectionLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
26 EFI_GUID_DEFINED_SECTION GuidedSectionHeader
;
28 } CRC32_SECTION_HEADER
;
32 Crc32GuidedSectionGetInfo (
33 IN CONST VOID
*InputSection
,
34 OUT UINT32
*OutputBufferSize
,
35 OUT UINT32
*ScratchBufferSize
,
36 OUT UINT16
*SectionAttribute
42 The implementation of Crc32 guided section GetInfo().
45 InputSection Buffer containing the input GUIDed section to be processed.
46 OutputBufferSize The size of OutputBuffer.
47 ScratchBufferSize The size of ScratchBuffer.
48 SectionAttribute The attribute of the input guided section.
52 EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
53 EFI_INVALID_PARAMETER - The source data is corrupted, or
54 The GUID in InputSection does not match this instance guid.
59 &gEfiCrc32GuidedSectionExtractionProtocolGuid
,
60 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
61 return EFI_INVALID_PARAMETER
;
64 // Retrieve the size and attribute of the input section data.
66 *SectionAttribute
= ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->Attributes
;
67 *ScratchBufferSize
= 0;
68 *OutputBufferSize
= *(UINT32
*) (((EFI_COMMON_SECTION_HEADER
*) InputSection
)->Size
) & 0x00ffffff;
69 *OutputBufferSize
-= ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
;
76 Crc32GuidedSectionHandler (
77 IN CONST VOID
*InputSection
,
78 OUT VOID
**OutputBuffer
,
79 IN VOID
*ScratchBuffer
, OPTIONAL
80 OUT UINT32
*AuthenticationStatus
86 The implementation of Crc32 Guided section extraction.
89 InputSection Buffer containing the input GUIDed section to be processed.
90 OutputBuffer OutputBuffer to point to the start of the section's contents.
91 if guided data is not prcessed. Otherwise,
92 OutputBuffer to contain the output data, which is allocated by the caller.
93 ScratchBuffer A pointer to a caller-allocated buffer for function internal use.
94 AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the
95 authentication status of the output buffer.
99 RETURN_SUCCESS - Decompression is successfull
100 RETURN_INVALID_PARAMETER - The source data is corrupted, or
101 The GUID in InputSection does not match this instance guid.
106 CRC32_SECTION_HEADER
*Crc32SectionHeader
;
107 UINT32 Crc32Checksum
;
108 UINT32 OutputBufferSize
;
109 VOID
*DummyInterface
;
112 &gEfiCrc32GuidedSectionExtractionProtocolGuid
,
113 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
114 return EFI_INVALID_PARAMETER
;
119 // Points to the Crc32 section header
121 Crc32SectionHeader
= (CRC32_SECTION_HEADER
*) InputSection
;
122 *OutputBuffer
= (UINT8
*) InputSection
+ Crc32SectionHeader
->GuidedSectionHeader
.DataOffset
;
123 OutputBufferSize
= *(UINT32
*) (((EFI_COMMON_SECTION_HEADER
*) InputSection
)->Size
) & 0x00ffffff;
124 OutputBufferSize
-= Crc32SectionHeader
->GuidedSectionHeader
.DataOffset
;
127 // Implictly CRC32 GUIDed section should have STATUS_VALID bit set
129 ASSERT (Crc32SectionHeader
->GuidedSectionHeader
.Attributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
);
130 *AuthenticationStatus
= EFI_AUTH_STATUS_IMAGE_SIGNED
;
133 // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.
135 Status
= gBS
->LocateProtocol (&gEfiSecurityPolicyProtocolGuid
, NULL
, &DummyInterface
);
136 if (!EFI_ERROR (Status
)) {
137 *AuthenticationStatus
|= EFI_AUTH_STATUS_PLATFORM_OVERRIDE
;
140 // Calculate CRC32 Checksum of Image
142 Status
= gBS
->CalculateCrc32 (*OutputBuffer
, OutputBufferSize
, &Crc32Checksum
);
143 if (Status
== EFI_SUCCESS
) {
144 if (Crc32Checksum
!= Crc32SectionHeader
->CRC32Checksum
) {
145 *AuthenticationStatus
|= EFI_AUTH_STATUS_TEST_FAILED
;
148 *AuthenticationStatus
|= EFI_AUTH_STATUS_NOT_TESTED
;
156 Register Crc32 section handler.
158 @retval RETURN_SUCCESS Register successfully.
159 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
163 DxeCrc32GuidedSectionExtractLibConstructor (
166 return ExtractGuidedSectionRegisterHandlers (
167 &gEfiCrc32GuidedSectionExtractionProtocolGuid
,
168 Crc32GuidedSectionGetInfo
,
169 Crc32GuidedSectionHandler