]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm12CommandLib/Tpm12Pcr.c
SecurityPkg/Tpm12CommandLib: Add TPM 1.2 commands used by TCG modules
[mirror_edk2.git] / SecurityPkg / Library / Tpm12CommandLib / Tpm12Pcr.c
diff --git a/SecurityPkg/Library/Tpm12CommandLib/Tpm12Pcr.c b/SecurityPkg/Library/Tpm12CommandLib/Tpm12Pcr.c
new file mode 100644 (file)
index 0000000..321653f
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+  Implement TPM1.2 PCR related commands.\r
+\r
+Copyright (c) 2016, 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 <PiPei.h>\r
+#include <Library/Tpm12CommandLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/Tpm12DeviceLib.h>\r
+\r
+#pragma pack(1)\r
+\r
+typedef struct {\r
+  TPM_RQU_COMMAND_HDR   Hdr;\r
+  TPM_PCRINDEX          PcrIndex;\r
+  TPM_DIGEST            TpmDigest;\r
+} TPM_CMD_EXTEND;\r
+\r
+typedef struct {\r
+  TPM_RSP_COMMAND_HDR   Hdr;\r
+  TPM_DIGEST            TpmDigest;\r
+} TPM_RSP_EXTEND;\r
+\r
+#pragma pack()\r
+\r
+/**\r
+Extend a TPM PCR.\r
+\r
+@param[in]  DigestToExtend    The 160 bit value representing the event to be recorded.\r
+@param[in]  PcrIndex          The PCR to be updated.\r
+@param[out] NewPcrValue       New PCR value after extend.\r
+\r
+@retval EFI_SUCCESS           Operation completed successfully.\r
+@retval EFI_TIMEOUT           The register can't run into the expected status in time.\r
+@retval EFI_BUFFER_TOO_SMALL  Response data buffer is too small.\r
+@retval EFI_DEVICE_ERROR      Unexpected device behavior.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tpm12Extend (\r
+  IN  TPM_DIGEST    *DigestToExtend,\r
+  IN  TPM_PCRINDEX  PcrIndex,\r
+  OUT TPM_DIGEST    *NewPcrValue\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  TPM_CMD_EXTEND  Command;\r
+  TPM_RSP_EXTEND  Response;\r
+  UINT32          Length;\r
+\r
+  //\r
+  // send Tpm command TPM_ORD_Extend\r
+  //\r
+  Command.Hdr.tag       = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r
+  Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));\r
+  Command.Hdr.ordinal   = SwapBytes32 (TPM_ORD_Extend);\r
+  Command.PcrIndex      = SwapBytes32 (PcrIndex);\r
+  CopyMem (&Command.TpmDigest, DigestToExtend, sizeof (Command.TpmDigest));\r
+  Length = sizeof (Response);\r
+  Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (NewPcrValue != NULL) {\r
+    CopyMem (NewPcrValue, &Response.TpmDigest, sizeof (*NewPcrValue));\r
+  }\r
+\r
+  return Status;\r
+}\r