]>
Commit | Line | Data |
---|---|---|
a332cfd3 | 1 | /** @file\r |
2 | This library is used by other modules to measure data to TPM.\r | |
3 | \r | |
4 | Copyright (c) 2012, Intel Corporation. All rights reserved. <BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT 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 | |
a332cfd3 | 45 | EFI_STATUS\r |
46 | Tpm12MeasureAndLogData (\r | |
47 | IN UINT32 PcrIndex,\r | |
48 | IN UINT32 EventType,\r | |
49 | IN VOID *EventLog,\r | |
50 | IN UINT32 LogLen,\r | |
51 | IN VOID *HashData,\r | |
52 | IN UINT64 HashDataLen\r | |
53 | )\r | |
54 | {\r | |
55 | EFI_STATUS Status;\r | |
56 | EFI_TCG_PROTOCOL *TcgProtocol;\r | |
57 | TCG_PCR_EVENT *TcgEvent;\r | |
58 | EFI_PHYSICAL_ADDRESS EventLogLastEntry;\r | |
59 | UINT32 EventNumber;\r | |
60 | \r | |
61 | TcgEvent = NULL;\r | |
62 | \r | |
63 | //\r | |
64 | // Tpm active/deactive state is checked in HashLogExtendEvent\r | |
65 | //\r | |
66 | Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);\r | |
67 | if (EFI_ERROR(Status)){\r | |
68 | return Status;\r | |
69 | }\r | |
70 | \r | |
71 | TcgEvent = (TCG_PCR_EVENT *)AllocateZeroPool (sizeof (TCG_PCR_EVENT_HDR) + LogLen);\r | |
72 | if(TcgEvent == NULL) {\r | |
73 | return EFI_OUT_OF_RESOURCES;\r | |
74 | }\r | |
75 | \r | |
76 | TcgEvent->PCRIndex = PcrIndex;\r | |
77 | TcgEvent->EventType = EventType;\r | |
78 | TcgEvent->EventSize = LogLen;\r | |
79 | CopyMem (&TcgEvent->Event[0], EventLog, LogLen);\r | |
80 | EventNumber = 1;\r | |
81 | Status = TcgProtocol->HashLogExtendEvent (\r | |
82 | TcgProtocol,\r | |
83 | (EFI_PHYSICAL_ADDRESS)(UINTN)HashData,\r | |
84 | HashDataLen,\r | |
85 | TPM_ALG_SHA,\r | |
86 | TcgEvent,\r | |
87 | &EventNumber,\r | |
88 | &EventLogLastEntry\r | |
89 | );\r | |
90 | \r | |
91 | FreePool (TcgEvent);\r | |
92 | \r | |
93 | return Status;\r | |
94 | }\r | |
95 | \r | |
96 | /**\r | |
97 | Tpm measure and log data, and extend the measurement result into a specific PCR.\r | |
98 | \r | |
99 | @param[in] PcrIndex PCR Index.\r | |
100 | @param[in] EventType Event type.\r | |
101 | @param[in] EventLog Measurement event log.\r | |
102 | @param[in] LogLen Event log length in bytes.\r | |
103 | @param[in] HashData The start of the data buffer to be hashed, extended.\r | |
104 | @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r | |
105 | \r | |
106 | @retval EFI_SUCCESS Operation completed successfully.\r | |
107 | @retval EFI_UNSUPPORTED TPM device not available.\r | |
108 | @retval EFI_OUT_OF_RESOURCES Out of memory.\r | |
109 | @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r | |
110 | **/\r | |
a332cfd3 | 111 | EFI_STATUS\r |
112 | EFIAPI \r | |
113 | TpmMeasureAndLogData (\r | |
114 | IN UINT32 PcrIndex,\r | |
115 | IN UINT32 EventType,\r | |
116 | IN VOID *EventLog,\r | |
117 | IN UINT32 LogLen,\r | |
118 | IN VOID *HashData,\r | |
119 | IN UINT64 HashDataLen\r | |
120 | )\r | |
121 | {\r | |
122 | EFI_STATUS Status;\r | |
123 | \r | |
124 | //\r | |
125 | // Try to measure using Tpm1.2 protocol\r | |
126 | //\r | |
127 | Status = Tpm12MeasureAndLogData(\r | |
128 | PcrIndex,\r | |
129 | EventType,\r | |
130 | EventLog,\r | |
131 | LogLen,\r | |
132 | HashData,\r | |
133 | HashDataLen\r | |
134 | );\r | |
135 | \r | |
136 | return Status;\r | |
137 | }\r |