]> git.proxmox.com Git - mirror_edk2.git/blob - 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
1 /** @file
2 This library is used by other modules to measure data to TPM.
3
4 Copyright (c) 2012, 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
9
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.
12
13 **/
14
15 #include <PiDxe.h>
16
17 #include <Protocol/TcgService.h>
18
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/TpmMeasurementLib.h>
24
25 #include <Guid/Acpi.h>
26 #include <IndustryStandard/Acpi.h>
27
28
29
30 /**
31 Tpm12 measure and log data, and extend the measurement result into a specific PCR.
32
33 @param[in] PcrIndex PCR Index.
34 @param[in] EventType Event type.
35 @param[in] EventLog Measurement event log.
36 @param[in] LogLen Event log length in bytes.
37 @param[in] HashData The start of the data buffer to be hashed, extended.
38 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
39
40 @retval EFI_SUCCESS Operation completed successfully.
41 @retval EFI_UNSUPPORTED TPM device not available.
42 @retval EFI_OUT_OF_RESOURCES Out of memory.
43 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
44 **/
45
46 EFI_STATUS
47 Tpm12MeasureAndLogData (
48 IN UINT32 PcrIndex,
49 IN UINT32 EventType,
50 IN VOID *EventLog,
51 IN UINT32 LogLen,
52 IN VOID *HashData,
53 IN UINT64 HashDataLen
54 )
55 {
56 EFI_STATUS Status;
57 EFI_TCG_PROTOCOL *TcgProtocol;
58 TCG_PCR_EVENT *TcgEvent;
59 EFI_PHYSICAL_ADDRESS EventLogLastEntry;
60 UINT32 EventNumber;
61
62 TcgEvent = NULL;
63
64 //
65 // Tpm active/deactive state is checked in HashLogExtendEvent
66 //
67 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);
68 if (EFI_ERROR(Status)){
69 return Status;
70 }
71
72 TcgEvent = (TCG_PCR_EVENT *)AllocateZeroPool (sizeof (TCG_PCR_EVENT_HDR) + LogLen);
73 if(TcgEvent == NULL) {
74 return EFI_OUT_OF_RESOURCES;
75 }
76
77 TcgEvent->PCRIndex = PcrIndex;
78 TcgEvent->EventType = EventType;
79 TcgEvent->EventSize = LogLen;
80 CopyMem (&TcgEvent->Event[0], EventLog, LogLen);
81 EventNumber = 1;
82 Status = TcgProtocol->HashLogExtendEvent (
83 TcgProtocol,
84 (EFI_PHYSICAL_ADDRESS)(UINTN)HashData,
85 HashDataLen,
86 TPM_ALG_SHA,
87 TcgEvent,
88 &EventNumber,
89 &EventLogLastEntry
90 );
91
92 FreePool (TcgEvent);
93
94 return Status;
95 }
96
97 /**
98 Tpm measure and log data, and extend the measurement result into a specific PCR.
99
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
106
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.
111 **/
112
113 EFI_STATUS
114 EFIAPI
115 TpmMeasureAndLogData (
116 IN UINT32 PcrIndex,
117 IN UINT32 EventType,
118 IN VOID *EventLog,
119 IN UINT32 LogLen,
120 IN VOID *HashData,
121 IN UINT64 HashDataLen
122 )
123 {
124 EFI_STATUS Status;
125
126 //
127 // Try to measure using Tpm1.2 protocol
128 //
129 Status = Tpm12MeasureAndLogData(
130 PcrIndex,
131 EventType,
132 EventLog,
133 LogLen,
134 HashData,
135 HashDataLen
136 );
137
138 return Status;
139 }