]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c
1.Measure ACPI table data comes from flash event type EV_POST_CODE ACPI DATA to PCR[0]
[mirror_edk2.git] / SecurityPkg / Library / DxeTpmMeasurementLib / DxeTpmMeasurementLib.c
CommitLineData
a332cfd3 1/** @file\r
2 This library is used by other modules to measure data to TPM.\r
3\r
4Copyright (c) 2012, Intel Corporation. All rights reserved. <BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiDxe.h>\r
16\r
17#include <Protocol/TcgService.h>\r
18\r
19#include <Library/BaseMemoryLib.h>\r
20#include <Library/MemoryAllocationLib.h>\r
21#include <Library/UefiBootServicesTableLib.h>\r
22#include <Library/DebugLib.h>\r
23#include <Library/TpmMeasurementLib.h>\r
24\r
25#include <Guid/Acpi.h>\r
26#include <IndustryStandard/Acpi.h>\r
27\r
28\r
29\r
30/**\r
31 Tpm12 measure and log data, and extend the measurement result into a specific PCR.\r
32\r
33 @param[in] PcrIndex PCR Index.\r
34 @param[in] EventType Event type.\r
35 @param[in] EventLog Measurement event log.\r
36 @param[in] LogLen Event log length in bytes.\r
37 @param[in] HashData The start of the data buffer to be hashed, extended.\r
38 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r
39\r
40 @retval EFI_SUCCESS Operation completed successfully.\r
41 @retval EFI_UNSUPPORTED TPM device not available.\r
42 @retval EFI_OUT_OF_RESOURCES Out of memory.\r
43 @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
44**/\r
45\r
46EFI_STATUS\r
47Tpm12MeasureAndLogData (\r
48 IN UINT32 PcrIndex,\r
49 IN UINT32 EventType,\r
50 IN VOID *EventLog,\r
51 IN UINT32 LogLen,\r
52 IN VOID *HashData,\r
53 IN UINT64 HashDataLen\r
54 )\r
55{\r
56 EFI_STATUS Status;\r
57 EFI_TCG_PROTOCOL *TcgProtocol;\r
58 TCG_PCR_EVENT *TcgEvent;\r
59 EFI_PHYSICAL_ADDRESS EventLogLastEntry;\r
60 UINT32 EventNumber;\r
61\r
62 TcgEvent = NULL;\r
63\r
64 //\r
65 // Tpm active/deactive state is checked in HashLogExtendEvent\r
66 //\r
67 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);\r
68 if (EFI_ERROR(Status)){\r
69 return Status;\r
70 }\r
71\r
72 TcgEvent = (TCG_PCR_EVENT *)AllocateZeroPool (sizeof (TCG_PCR_EVENT_HDR) + LogLen);\r
73 if(TcgEvent == NULL) {\r
74 return EFI_OUT_OF_RESOURCES;\r
75 }\r
76\r
77 TcgEvent->PCRIndex = PcrIndex;\r
78 TcgEvent->EventType = EventType;\r
79 TcgEvent->EventSize = LogLen;\r
80 CopyMem (&TcgEvent->Event[0], EventLog, LogLen);\r
81 EventNumber = 1;\r
82 Status = TcgProtocol->HashLogExtendEvent (\r
83 TcgProtocol,\r
84 (EFI_PHYSICAL_ADDRESS)(UINTN)HashData,\r
85 HashDataLen,\r
86 TPM_ALG_SHA,\r
87 TcgEvent,\r
88 &EventNumber,\r
89 &EventLogLastEntry\r
90 );\r
91\r
92 FreePool (TcgEvent);\r
93\r
94 return Status;\r
95}\r
96\r
97/**\r
98 Tpm measure and log data, and extend the measurement result into a specific PCR.\r
99\r
100 @param[in] PcrIndex PCR Index.\r
101 @param[in] EventType Event type.\r
102 @param[in] EventLog Measurement event log.\r
103 @param[in] LogLen Event log length in bytes.\r
104 @param[in] HashData The start of the data buffer to be hashed, extended.\r
105 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r
106\r
107 @retval EFI_SUCCESS Operation completed successfully.\r
108 @retval EFI_UNSUPPORTED TPM device not available.\r
109 @retval EFI_OUT_OF_RESOURCES Out of memory.\r
110 @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
111**/\r
112\r
113EFI_STATUS\r
114EFIAPI \r
115TpmMeasureAndLogData (\r
116 IN UINT32 PcrIndex,\r
117 IN UINT32 EventType,\r
118 IN VOID *EventLog,\r
119 IN UINT32 LogLen,\r
120 IN VOID *HashData,\r
121 IN UINT64 HashDataLen\r
122 )\r
123{\r
124 EFI_STATUS Status;\r
125\r
126 //\r
127 // Try to measure using Tpm1.2 protocol\r
128 //\r
129 Status = Tpm12MeasureAndLogData(\r
130 PcrIndex,\r
131 EventType,\r
132 EventLog,\r
133 LogLen,\r
134 HashData,\r
135 HashDataLen\r
136 );\r
137\r
138 return Status;\r
139}\r