Skip to content

Commit 94bfc6f

Browse files
suncepingmergify[bot]
authored andcommitted
UefiCpuPkg: Add TdxMeasurementLib.h
Add below APIs to UefiCpuPkg. - TdxMeasurementMapPcrToMrIndex - TdxMeasurementHashAndExtendToRtmr - TdxMeasurementBuildGuidHob Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Min Xu <min.m.xu@intel.com> Signed-off-by: Ceping Sun <cepingx.sun@intel.com>
1 parent 8c180ac commit 94bfc6f

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/** @file
2+
TdxMeasurementLib header file
3+
Copyright (c) 2025, Intel Corporation. All rights reserved.<BR>
4+
SPDX-License-Identifier: BSD-2-Clause-Patent
5+
**/
6+
7+
#ifndef TDX_MEASUREMENT_LIB_H
8+
#define TDX_MEASUREMENT_LIB_H
9+
10+
#include <PiPei.h>
11+
12+
#define CC_MR_INDEX_0_MRTD 0
13+
#define CC_MR_INDEX_1_RTMR0 1
14+
#define CC_MR_INDEX_2_RTMR1 2
15+
#define CC_MR_INDEX_3_RTMR2 3
16+
#define CC_MR_INDEX_INVALID 4
17+
18+
/**
19+
According to UEFI Spec 2.10 Section 38.4.1:
20+
The following table shows the TPM PCR index mapping and CC event log measurement
21+
register index interpretation for Intel TDX, where MRTD means Trust Domain Measurement
22+
Register and RTMR means Runtime Measurement Register
23+
// TPM PCR Index | CC Measurement Register Index | TDX-measurement register
24+
// ------------------------------------------------------------------------
25+
// 0 | 0 | MRTD
26+
// 1, 7 | 1 | RTMR[0]
27+
// 2~6 | 2 | RTMR[1]
28+
// 8~15 | 3 | RTMR[2]
29+
@param[in] PCRIndex Index of the TPM PCR
30+
@retval UINT32 Index of the CC Event Log Measurement Register Index
31+
@retval CC_MR_INDEX_INVALID Invalid MR Index
32+
**/
33+
UINT32
34+
EFIAPI
35+
TdxMeasurementMapPcrToMrIndex (
36+
IN UINT32 PCRIndex
37+
);
38+
39+
/**
40+
* Build GuidHob for Tdx CC measurement event.
41+
*
42+
* @param RtmrIndex RTMR index
43+
* @param EventType Event type
44+
* @param EventData Event data
45+
* @param EventSize Size of event data
46+
* @param HashValue Hash value
47+
* @param HashSize Size of hash
48+
*
49+
* @retval EFI_SUCCESS Successfully build the GuidHobs
50+
* @retval Others Other error as indicated
51+
*/
52+
EFI_STATUS
53+
EFIAPI
54+
TdxMeasurementBuildGuidHob (
55+
UINT32 RtmrIndex,
56+
UINT32 EventType,
57+
UINT8 *EventData,
58+
UINT32 EventSize,
59+
UINT8 *HashValue,
60+
UINT32 HashSize
61+
);
62+
63+
/**
64+
* Calculate the sha384 of input Data and extend it to RTMR register.
65+
*
66+
* @param RtmrIndex Index of the RTMR register
67+
* @param DataToHash Data to be hashed
68+
* @param DataToHashLen Length of the data
69+
* @param Digest Hash value of the input data
70+
* @param DigestLen Length of the hash value
71+
*
72+
* @retval EFI_SUCCESS Successfully hash and extend to RTMR
73+
* @retval Others Other errors as indicated
74+
*/
75+
EFI_STATUS
76+
EFIAPI
77+
TdxMeasurementHashAndExtendToRtmr (
78+
IN UINT32 RtmrIndex,
79+
IN VOID *DataToHash,
80+
IN UINTN DataToHashLen,
81+
OUT UINT8 *Digest,
82+
IN UINTN DigestLen
83+
);
84+
85+
#endif

UefiCpuPkg/UefiCpuPkg.dec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
## @libraryclass Provides function to support CcExit processing.
5454
CcExitLib|Include/Library/CcExitLib.h
5555

56+
## @libraryclass Provides functions for Tdx Measurement processing
57+
TdxMeasurementLib|Include/Library/TdxMeasurementLib.h
58+
5659
## @libraryclass Provides function to support AmdSvsm processing.
5760
AmdSvsmLib|Include/Library/AmdSvsmLib.h
5861

0 commit comments

Comments
 (0)