2 TdxHelper Functions which are used in SEC phase
4 Copyright (c) 2022 - 2023, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/HobLib.h>
14 #include <Library/BaseCryptLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <IndustryStandard/Tdx.h>
17 #include <IndustryStandard/IntelTdx.h>
18 #include <IndustryStandard/Tpm20.h>
19 #include <Library/TdxLib.h>
20 #include <Pi/PrePiHob.h>
22 #include <ConfidentialComputingGuestAttr.h>
23 #include <Library/TdxHelperLib.h>
26 Build the GuidHob for tdx measurements which were done in SEC phase.
27 The measurement values are stored in WorkArea.
29 @retval EFI_SUCCESS The GuidHob is built successfully
30 @retval Others Other errors as indicated
33 InternalBuildGuidHobForTdxMeasurement (
38 In Tdx guest, some information need to be passed from host VMM to guest
39 firmware. For example, the memory resource, etc. These information are
40 prepared by host VMM and put in TdHob which is described in TdxMetadata.
41 TDVF processes the TdHob to accept memories.
43 @retval EFI_SUCCESS Successfully process the TdHob
44 @retval Others Other error as indicated
48 TdxHelperProcessTdHob (
52 return EFI_UNSUPPORTED
;
56 * Calculate the sha384 of input Data and extend it to RTMR register.
58 * @param RtmrIndex Index of the RTMR register
59 * @param DataToHash Data to be hashed
60 * @param DataToHashLen Length of the data
61 * @param Digest Hash value of the input data
62 * @param DigestLen Length of the hash value
64 * @retval EFI_SUCCESS Successfully hash and extend to RTMR
65 * @retval Others Other errors as indicated
72 IN UINTN DataToHashLen
,
79 if ((DataToHash
== NULL
) || (DataToHashLen
== 0)) {
80 return EFI_INVALID_PARAMETER
;
83 if ((Digest
== NULL
) || (DigestLen
!= SHA384_DIGEST_SIZE
)) {
84 return EFI_INVALID_PARAMETER
;
88 // Calculate the sha384 of the data
90 if (!Sha384HashAll (DataToHash
, DataToHashLen
, Digest
)) {
97 Status
= TdExtendRtmr (
103 ASSERT (!EFI_ERROR (Status
));
108 In Tdx guest, TdHob is passed from host VMM to guest firmware and it contains
109 the information of the memory resource. From the security perspective before
110 it is consumed, it should be measured and extended.
112 * @retval EFI_SUCCESS Successfully measure the TdHob
113 * @retval Others Other error as indicated
117 TdxHelperMeasureTdHob (
121 EFI_PEI_HOB_POINTERS Hob
;
123 UINT8 Digest
[SHA384_DIGEST_SIZE
];
124 OVMF_WORK_AREA
*WorkArea
;
127 TdHob
= (VOID
*)(UINTN
)FixedPcdGet32 (PcdOvmfSecGhcbBase
);
128 Hob
.Raw
= (UINT8
*)TdHob
;
131 // Walk thru the TdHob list until end of list.
133 while (!END_OF_HOB_LIST (Hob
)) {
134 Hob
.Raw
= GET_NEXT_HOB (Hob
);
137 Status
= HashAndExtendToRtmr (
140 (UINTN
)((UINT8
*)Hob
.Raw
- (UINT8
*)TdHob
),
145 if (EFI_ERROR (Status
)) {
150 // This function is called in SEC phase and at that moment the Hob service
151 // is not available. So the TdHob measurement value is stored in workarea.
153 WorkArea
= (OVMF_WORK_AREA
*)FixedPcdGet32 (PcdOvmfWorkAreaBase
);
154 if (WorkArea
== NULL
) {
155 return EFI_DEVICE_ERROR
;
158 WorkArea
->TdxWorkArea
.SecTdxWorkArea
.TdxMeasurementsData
.MeasurementsBitmap
|= TDX_MEASUREMENT_TDHOB_BITMASK
;
159 CopyMem (WorkArea
->TdxWorkArea
.SecTdxWorkArea
.TdxMeasurementsData
.TdHobHashValue
, Digest
, SHA384_DIGEST_SIZE
);
165 * In Tdx guest, Configuration FV (CFV) is treated as external input because it
166 * may contain the data provided by VMM. From the sucurity perspective Cfv image
167 * should be measured before it is consumed.
169 * @retval EFI_SUCCESS Successfully measure the CFV image
170 * @retval Others Other error as indicated
174 TdxHelperMeasureCfvImage (
178 return EFI_UNSUPPORTED
;
182 Build the GuidHob for tdx measurements which were done in SEC phase.
183 The measurement values are stored in WorkArea.
185 @retval EFI_SUCCESS The GuidHob is built successfully
186 @retval Others Other errors as indicated
190 TdxHelperBuildGuidHobForTdxMeasurement (
194 #ifdef TDX_PEI_LESS_BOOT
195 return InternalBuildGuidHobForTdxMeasurement ();
197 return EFI_UNSUPPORTED
;