|
| 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 |
0 commit comments