--- /dev/null
+/** @file\r
+ This library is used by other modules to measure data to TPM.\r
+\r
+Copyright (c) 2012, Intel Corporation. All rights reserved. <BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _TPM_MEASUREMENT_LIB_H_\r
+#define _TPM_MEASUREMENT_LIB_H_\r
+\r
+/**\r
+ Tpm measure and log data, and extend the measurement result into a specific PCR.\r
+\r
+ @param[in] PcrIndex PCR Index.\r
+ @param[in] EventType Event type.\r
+ @param[in] EventLog Measurement event log.\r
+ @param[in] LogLen Event log length in bytes.\r
+ @param[in] HashData The start of the data buffer to be hashed, extended.\r
+ @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r
+\r
+ @retval EFI_SUCCESS Operation completed successfully.\r
+ @retval EFI_UNSUPPORTED TPM device not available.\r
+ @retval EFI_OUT_OF_RESOURCES Out of memory.\r
+ @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
+**/\r
+\r
+EFI_STATUS\r
+EFIAPI \r
+TpmMeasureAndLogData (\r
+ IN UINT32 PcrIndex,\r
+ IN UINT32 EventType,\r
+ IN VOID *EventLog,\r
+ IN UINT32 LogLen,\r
+ IN VOID *HashData,\r
+ IN UINT64 HashDataLen\r
+ );\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+ This library is used by other modules to measure data to TPM.\r
+\r
+Copyright (c) 2012, Intel Corporation. All rights reserved. <BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Protocol/TcgService.h>\r
+\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/TpmMeasurementLib.h>\r
+\r
+#include <Guid/Acpi.h>\r
+#include <IndustryStandard/Acpi.h>\r
+\r
+\r
+\r
+/**\r
+ Tpm12 measure and log data, and extend the measurement result into a specific PCR.\r
+\r
+ @param[in] PcrIndex PCR Index.\r
+ @param[in] EventType Event type.\r
+ @param[in] EventLog Measurement event log.\r
+ @param[in] LogLen Event log length in bytes.\r
+ @param[in] HashData The start of the data buffer to be hashed, extended.\r
+ @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r
+\r
+ @retval EFI_SUCCESS Operation completed successfully.\r
+ @retval EFI_UNSUPPORTED TPM device not available.\r
+ @retval EFI_OUT_OF_RESOURCES Out of memory.\r
+ @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
+**/\r
+\r
+EFI_STATUS\r
+Tpm12MeasureAndLogData (\r
+ IN UINT32 PcrIndex,\r
+ IN UINT32 EventType,\r
+ IN VOID *EventLog,\r
+ IN UINT32 LogLen,\r
+ IN VOID *HashData,\r
+ IN UINT64 HashDataLen\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_TCG_PROTOCOL *TcgProtocol;\r
+ TCG_PCR_EVENT *TcgEvent;\r
+ EFI_PHYSICAL_ADDRESS EventLogLastEntry;\r
+ UINT32 EventNumber;\r
+\r
+ TcgEvent = NULL;\r
+\r
+ //\r
+ // Tpm active/deactive state is checked in HashLogExtendEvent\r
+ //\r
+ Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);\r
+ if (EFI_ERROR(Status)){\r
+ return Status;\r
+ }\r
+\r
+ TcgEvent = (TCG_PCR_EVENT *)AllocateZeroPool (sizeof (TCG_PCR_EVENT_HDR) + LogLen);\r
+ if(TcgEvent == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ TcgEvent->PCRIndex = PcrIndex;\r
+ TcgEvent->EventType = EventType;\r
+ TcgEvent->EventSize = LogLen;\r
+ CopyMem (&TcgEvent->Event[0], EventLog, LogLen);\r
+ EventNumber = 1;\r
+ Status = TcgProtocol->HashLogExtendEvent (\r
+ TcgProtocol,\r
+ (EFI_PHYSICAL_ADDRESS)(UINTN)HashData,\r
+ HashDataLen,\r
+ TPM_ALG_SHA,\r
+ TcgEvent,\r
+ &EventNumber,\r
+ &EventLogLastEntry\r
+ );\r
+\r
+ FreePool (TcgEvent);\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Tpm measure and log data, and extend the measurement result into a specific PCR.\r
+\r
+ @param[in] PcrIndex PCR Index.\r
+ @param[in] EventType Event type.\r
+ @param[in] EventLog Measurement event log.\r
+ @param[in] LogLen Event log length in bytes.\r
+ @param[in] HashData The start of the data buffer to be hashed, extended.\r
+ @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r
+\r
+ @retval EFI_SUCCESS Operation completed successfully.\r
+ @retval EFI_UNSUPPORTED TPM device not available.\r
+ @retval EFI_OUT_OF_RESOURCES Out of memory.\r
+ @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
+**/\r
+\r
+EFI_STATUS\r
+EFIAPI \r
+TpmMeasureAndLogData (\r
+ IN UINT32 PcrIndex,\r
+ IN UINT32 EventType,\r
+ IN VOID *EventLog,\r
+ IN UINT32 LogLen,\r
+ IN VOID *HashData,\r
+ IN UINT64 HashDataLen\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Try to measure using Tpm1.2 protocol\r
+ //\r
+ Status = Tpm12MeasureAndLogData(\r
+ PcrIndex,\r
+ EventType,\r
+ EventLog,\r
+ LogLen,\r
+ HashData,\r
+ HashDataLen\r
+ );\r
+\r
+ return Status;\r
+}\r
--- /dev/null
+## @file\r
+# This library is used by other modules to measure data to TPM 1.2.\r
+#\r
+# Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = DxeTpmMeasurementLib\r
+ FILE_GUID = 30930D10-AF5B-4abf-80E6-EB4FFC0AE9D1\r
+ MODULE_TYPE = UEFI_DRIVER\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = TpmMeasurementLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+ DxeTpmMeasurementLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ SecurityPkg/SecurityPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ BaseMemoryLib\r
+ DebugLib\r
+ MemoryAllocationLib\r
+ UefiBootServicesTableLib\r
+\r
+[Protocols]\r
+ gEfiTcgProtocolGuid
\ No newline at end of file
TpmCommLib|SecurityPkg/Library/TpmCommLib/TpmCommLib.inf\r
PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf\r
TcgPhysicalPresenceLib|SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.inf\r
+ TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf\r
\r
[LibraryClasses.common.PEIM]\r
PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
+\r
+ //\r
+ // Measure to PCR[0] with event EV_POST_CODE ACPI DATA\r
+ //\r
+ TpmMeasureAndLogData(\r
+ 0,\r
+ EV_POST_CODE,\r
+ EV_POSTCODE_INFO_ACPI_DATA,\r
+ ACPI_DATA_LEN,\r
+ Table,\r
+ TableSize\r
+ );\r
+\r
+\r
ASSERT (Table->OemTableId == SIGNATURE_64 ('T', 'c', 'g', 'T', 'a', 'b', 'l', 'e'));\r
mTcgNvs = AssignOpRegion (Table, SIGNATURE_32 ('T', 'N', 'V', 'S'), (UINT16) sizeof (TCG_NVS));\r
ASSERT (mTcgNvs != NULL);\r
\r
#include <PiDxe.h>\r
#include <IndustryStandard/Acpi.h>\r
+#include <IndustryStandard/UefiTcgPlatform.h>\r
+\r
#include <Guid/PhysicalPresenceData.h>\r
#include <Guid/MemoryOverwriteControl.h>\r
+\r
#include <Protocol/SmmSwDispatch2.h>\r
#include <Protocol/AcpiTable.h>\r
#include <Protocol/SmmVariable.h>\r
#include <Library/UefiDriverEntryPoint.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
#include <Library/DxeServicesLib.h>\r
+#include <Library/TpmMeasurementLib.h>\r
\r
#pragma pack(1)\r
typedef struct {\r
UefiBootServicesTableLib\r
DebugLib\r
DxeServicesLib\r
+ TpmMeasurementLib\r
\r
[Guids]\r
gEfiPhysicalPresenceGuid\r