2 This library is used by other modules to measure data to TPM.
4 Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Protocol/TcgService.h>
18 #include <Protocol/TrEEProtocol.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/TpmMeasurementLib.h>
26 #include <Guid/Acpi.h>
27 #include <IndustryStandard/Acpi.h>
32 Tpm12 measure and log data, and extend the measurement result into a specific PCR.
34 @param[in] PcrIndex PCR Index.
35 @param[in] EventType Event type.
36 @param[in] EventLog Measurement event log.
37 @param[in] LogLen Event log length in bytes.
38 @param[in] HashData The start of the data buffer to be hashed, extended.
39 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
41 @retval EFI_SUCCESS Operation completed successfully.
42 @retval EFI_UNSUPPORTED TPM device not available.
43 @retval EFI_OUT_OF_RESOURCES Out of memory.
44 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
47 Tpm12MeasureAndLogData (
57 EFI_TCG_PROTOCOL
*TcgProtocol
;
58 TCG_PCR_EVENT
*TcgEvent
;
59 EFI_PHYSICAL_ADDRESS EventLogLastEntry
;
65 // Tpm active/deactive state is checked in HashLogExtendEvent
67 Status
= gBS
->LocateProtocol (&gEfiTcgProtocolGuid
, NULL
, (VOID
**) &TcgProtocol
);
68 if (EFI_ERROR(Status
)){
72 TcgEvent
= (TCG_PCR_EVENT
*)AllocateZeroPool (sizeof (TCG_PCR_EVENT_HDR
) + LogLen
);
73 if(TcgEvent
== NULL
) {
74 return EFI_OUT_OF_RESOURCES
;
77 TcgEvent
->PCRIndex
= PcrIndex
;
78 TcgEvent
->EventType
= EventType
;
79 TcgEvent
->EventSize
= LogLen
;
80 CopyMem (&TcgEvent
->Event
[0], EventLog
, LogLen
);
82 Status
= TcgProtocol
->HashLogExtendEvent (
84 (EFI_PHYSICAL_ADDRESS
)(UINTN
)HashData
,
98 Tpm20 measure and log data, and extend the measurement result into a specific PCR.
100 @param[in] PcrIndex PCR Index.
101 @param[in] EventType Event type.
102 @param[in] EventLog Measurement event log.
103 @param[in] LogLen Event log length in bytes.
104 @param[in] HashData The start of the data buffer to be hashed, extended.
105 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
107 @retval EFI_SUCCESS Operation completed successfully.
108 @retval EFI_UNSUPPORTED TPM device not available.
109 @retval EFI_OUT_OF_RESOURCES Out of memory.
110 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
113 Tpm20MeasureAndLogData (
119 IN UINT64 HashDataLen
123 EFI_TREE_PROTOCOL
*TreeProtocol
;
124 TrEE_EVENT
*TreeEvent
;
127 // TrEEPresentFlag is checked in HashLogExtendEvent
129 Status
= gBS
->LocateProtocol (&gEfiTrEEProtocolGuid
, NULL
, (VOID
**) &TreeProtocol
);
130 if (EFI_ERROR (Status
)) {
134 TreeEvent
= (TrEE_EVENT
*) AllocateZeroPool (LogLen
+ sizeof (TrEE_EVENT
));
135 if(TreeEvent
== NULL
) {
136 return EFI_OUT_OF_RESOURCES
;
139 TreeEvent
->Size
= (UINT32
)LogLen
+ sizeof (TrEE_EVENT
) - sizeof(TreeEvent
->Event
);
140 TreeEvent
->Header
.HeaderSize
= sizeof(TrEE_EVENT_HEADER
);
141 TreeEvent
->Header
.HeaderVersion
= TREE_EVENT_HEADER_VERSION
;
142 TreeEvent
->Header
.PCRIndex
= PcrIndex
;
143 TreeEvent
->Header
.EventType
= EventType
;
144 CopyMem (&TreeEvent
->Event
[0], EventLog
, LogLen
);
146 Status
= TreeProtocol
->HashLogExtendEvent (
149 (EFI_PHYSICAL_ADDRESS
)(UINTN
)HashData
,
153 FreePool (TreeEvent
);
159 Tpm measure and log data, and extend the measurement result into a specific PCR.
161 @param[in] PcrIndex PCR Index.
162 @param[in] EventType Event type.
163 @param[in] EventLog Measurement event log.
164 @param[in] LogLen Event log length in bytes.
165 @param[in] HashData The start of the data buffer to be hashed, extended.
166 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
168 @retval EFI_SUCCESS Operation completed successfully.
169 @retval EFI_UNSUPPORTED TPM device not available.
170 @retval EFI_OUT_OF_RESOURCES Out of memory.
171 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
175 TpmMeasureAndLogData (
181 IN UINT64 HashDataLen
187 // Try to measure using Tpm1.2 protocol
189 Status
= Tpm12MeasureAndLogData(
197 if (EFI_ERROR (Status
)) {
199 // Try to measure using Tpm20 protocol
201 Status
= Tpm20MeasureAndLogData(