3 Extends one of the RTMR measurement registers in TDCS with the provided
4 extension data in memory.
6 Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Uefi/UefiBaseType.h>
14 #include <Library/TdxLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <IndustryStandard/Tpm20.h>
17 #include <IndustryStandard/Tdx.h>
20 #define TD_EXTEND_BUFFER_LEN (64 + 48)
22 UINT8 mExtendBuffer
[TD_EXTEND_BUFFER_LEN
];
25 This function extends one of the RTMR measurement register
26 in TDCS with the provided extension data in memory.
27 RTMR extending supports SHA384 which length is 48 bytes.
29 @param[in] Data Point to the data to be extended
30 @param[in] DataLen Length of the data. Must be 48
31 @param[in] Index RTMR index
34 @return EFI_INVALID_PARAMETER
35 @return EFI_DEVICE_ERROR
52 ASSERT (Data
!= NULL
);
53 ASSERT (DataLen
== SHA384_DIGEST_SIZE
);
54 ASSERT (Index
>= 0 && Index
< RTMR_COUNT
);
56 if ((Data
== NULL
) || (DataLen
!= SHA384_DIGEST_SIZE
) || (Index
>= RTMR_COUNT
)) {
57 return EFI_INVALID_PARAMETER
;
60 // TD.RTMR.EXTEND requires 64B-aligned guest physical address of
61 // 48B-extension data. We use ALIGN_POINTER(Pointer, 64) to get
62 // the 64B-aligned guest physical address.
63 ExtendBuffer
= ALIGN_POINTER (mExtendBuffer
, 64);
64 ASSERT (((UINTN
)ExtendBuffer
& 0x3f) == 0);
66 ZeroMem (ExtendBuffer
, SHA384_DIGEST_SIZE
);
67 CopyMem (ExtendBuffer
, Data
, SHA384_DIGEST_SIZE
);
69 TdCallStatus
= TdCall (TDCALL_TDEXTENDRTMR
, (UINT64
)(UINTN
)ExtendBuffer
, Index
, 0, 0);
71 if (TdCallStatus
== TDX_EXIT_REASON_SUCCESS
) {
73 } else if (TdCallStatus
== TDX_EXIT_REASON_OPERAND_INVALID
) {
74 Status
= EFI_INVALID_PARAMETER
;
76 Status
= EFI_DEVICE_ERROR
;
79 if (Status
!= EFI_SUCCESS
) {
80 DEBUG ((DEBUG_ERROR
, "Error returned from TdExtendRtmr call - 0x%lx\n", TdCallStatus
));