]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c
SecurityPkg: Fix spelling errors
[mirror_edk2.git] / SecurityPkg / Library / DxeTpmMeasurementLib / DxeTpmMeasurementLib.c
index b4732bc6fb50ca82e0f58e4899d2bf34fe362adf..061136ee786075592dd2b634e54b57122941049f 100644 (file)
@@ -1,20 +1,15 @@
 /** @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
+Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved. <BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include <PiDxe.h>\r
 \r
 #include <Protocol/TcgService.h>\r
+#include <Protocol/Tcg2Protocol.h>\r
 \r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
@@ -61,7 +56,7 @@ Tpm12MeasureAndLogData (
   TcgEvent = NULL;\r
 \r
   //\r
-  // Tpm active/deactive state is checked in HashLogExtendEvent\r
+  // Tpm activation state is checked in HashLogExtendEvent\r
   //\r
   Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);\r
   if (EFI_ERROR(Status)){\r
@@ -93,6 +88,67 @@ Tpm12MeasureAndLogData (
   return Status;\r
 }\r
 \r
+/**\r
+  Tpm20 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
+EFI_STATUS\r
+Tpm20MeasureAndLogData (\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_TCG2_PROTOCOL         *Tcg2Protocol;\r
+  EFI_TCG2_EVENT            *Tcg2Event;\r
+\r
+  //\r
+  // TPMPresentFlag is checked in HashLogExtendEvent\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &Tcg2Protocol);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Tcg2Event = (EFI_TCG2_EVENT *) AllocateZeroPool (LogLen + sizeof (EFI_TCG2_EVENT));\r
+  if(Tcg2Event == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Tcg2Event->Size = (UINT32)LogLen + sizeof (EFI_TCG2_EVENT) - sizeof(Tcg2Event->Event);\r
+  Tcg2Event->Header.HeaderSize    = sizeof(EFI_TCG2_EVENT_HEADER);\r
+  Tcg2Event->Header.HeaderVersion = EFI_TCG2_EVENT_HEADER_VERSION;\r
+  Tcg2Event->Header.PCRIndex      = PcrIndex;\r
+  Tcg2Event->Header.EventType     = EventType;\r
+  CopyMem (&Tcg2Event->Event[0], EventLog, LogLen);\r
+\r
+  Status = Tcg2Protocol->HashLogExtendEvent (\r
+                           Tcg2Protocol,\r
+                           0,\r
+                           (EFI_PHYSICAL_ADDRESS)(UINTN)HashData,\r
+                           HashDataLen,\r
+                           Tcg2Event\r
+                           );\r
+  FreePool (Tcg2Event);\r
+\r
+  return Status;\r
+}\r
+\r
 /**\r
   Tpm measure and log data, and extend the measurement result into a specific PCR.\r
 \r
@@ -109,7 +165,7 @@ Tpm12MeasureAndLogData (
   @retval EFI_DEVICE_ERROR      The operation was unsuccessful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI \r
+EFIAPI\r
 TpmMeasureAndLogData (\r
   IN UINT32             PcrIndex,\r
   IN UINT32             EventType,\r
@@ -122,9 +178,22 @@ TpmMeasureAndLogData (
   EFI_STATUS  Status;\r
 \r
   //\r
-  // Try to measure using Tpm1.2 protocol\r
+  // Try to measure using Tpm20 protocol\r
   //\r
-  Status = Tpm12MeasureAndLogData(\r
+  Status = Tpm20MeasureAndLogData(\r
+             PcrIndex,\r
+             EventType,\r
+             EventLog,\r
+             LogLen,\r
+             HashData,\r
+             HashDataLen\r
+             );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Try to measure using Tpm1.2 protocol\r
+    //\r
+    Status = Tpm12MeasureAndLogData(\r
                PcrIndex,\r
                EventType,\r
                EventLog,\r
@@ -132,6 +201,7 @@ TpmMeasureAndLogData (
                HashData,\r
                HashDataLen\r
                );\r
+  }\r
 \r
   return Status;\r
 }\r