From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com []) by mx.groups.io with SMTP id smtpd.web12.14679.1594709372852380864 for ; Mon, 13 Jul 2020 23:49:52 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: qi1.zhang@intel.com) IronPort-SDR: 42RcAne0wf/TARPHS8QmBKEG5yDBhz0snXUytGkGCScsM3z8zo/CbeTzin+flpPD22tjruoZq7 OHyUfHPB+gxQ== X-IronPort-AV: E=McAfee;i="6000,8403,9681"; a="136287738" X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="136287738" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2020 23:49:52 -0700 IronPort-SDR: c6EN6n2Vfl43wa3cOZvp1YmfjLxBQyMLczH34DWvayLytoZqhYtdDYXSwQeIIJ3gpW5mfcBJnI SFnazmBd48hg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="360292115" Received: from shwdesssddpdqi.ccr.corp.intel.com ([10.239.9.10]) by orsmga001.jf.intel.com with ESMTP; 13 Jul 2020 23:49:49 -0700 From: Qi Zhang To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Chao Zhang Subject: [PATCH 5/6] SecurityPkg/PeiTpmMeasurementLib: Add PEI instance. Date: Tue, 14 Jul 2020 14:49:21 +0800 Message-Id: <20200714064922.7025-6-qi1.zhang@intel.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20200714064922.7025-1-qi1.zhang@intel.com> References: <20200714064922.7025-1-qi1.zhang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jiewen Yao REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2841 Cc: Jiewen Yao Cc: Jian J Wang Cc: Chao Zhang Signed-off-by: Jiewen Yao --- .../PeiTpmMeasurementLib.c | 73 +++++++++++++++++++ .../PeiTpmMeasurementLib.inf | 50 +++++++++++++ .../PeiTpmMeasurementLib.uni | 17 +++++ 3 files changed, 140 insertions(+) create mode 100644 SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurem= entLib.c create mode 100644 SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurem= entLib.inf create mode 100644 SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurem= entLib.uni diff --git a/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.= c b/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.c new file mode 100644 index 0000000000..7db22c568e --- /dev/null +++ b/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.c @@ -0,0 +1,73 @@ +/** @file=0D + This library is used by other modules to measure data to TPM.=0D +=0D +Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#include =0D +#include =0D +=0D +/**=0D + Tpm measure and log data, and extend the measurement result into a speci= fic PCR.=0D +=0D + @param[in] PcrIndex PCR Index.=0D + @param[in] EventType Event type.=0D + @param[in] EventLog Measurement event log.=0D + @param[in] LogLen Event log length in bytes.=0D + @param[in] HashData The start of the data buffer to be hashed, = extended.=0D + @param[in] HashDataLen The length, in bytes, of the buffer referen= ced by HashData=0D +=0D + @retval EFI_SUCCESS Operation completed successfully.=0D + @retval EFI_UNSUPPORTED TPM device not available.=0D + @retval EFI_OUT_OF_RESOURCES Out of memory.=0D + @retval EFI_DEVICE_ERROR The operation was unsuccessful.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TpmMeasureAndLogData (=0D + IN UINT32 PcrIndex,=0D + IN UINT32 EventType,=0D + IN VOID *EventLog,=0D + IN UINT32 LogLen,=0D + IN VOID *HashData,=0D + IN UINT64 HashDataLen=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EDKII_TCG_PPI *TcgPpi;=0D + TCG_PCR_EVENT_HDR TcgEventHdr;=0D +=0D + Status =3D PeiServicesLocatePpi(=0D + &gEdkiiTcgPpiGuid,=0D + 0,=0D + NULL,=0D + (VOID**)&TcgPpi=0D + );=0D + if (EFI_ERROR(Status)) {=0D + return Status;=0D + }=0D +=0D + TcgEventHdr.PCRIndex =3D PcrIndex;=0D + TcgEventHdr.EventType =3D EventType;=0D + TcgEventHdr.EventSize =3D LogLen;=0D +=0D + Status =3D TcgPpi->HashLogExtendEvent (=0D + TcgPpi,=0D + HashData,=0D + (UINTN)HashDataLen,=0D + &TcgEventHdr,=0D + EventLog=0D + );=0D + return Status;=0D +}=0D diff --git a/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.= inf b/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.inf new file mode 100644 index 0000000000..6625d0fd01 --- /dev/null +++ b/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.inf @@ -0,0 +1,50 @@ +## @file=0D +# Provides TPM measurement functions for TPM1.2 and TPM 2.0=0D +#=0D +# This library provides TpmMeasureAndLogData() to measure and log data, a= nd=0D +# extend the measurement result into a specific PCR.=0D +#=0D +# Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D PeiTpmMeasurementLib=0D + FILE_GUID =3D 9A62C49D-C45A-4322-9F3C-45958DF0056B= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D TpmMeasurementLib|PEIM=0D + MODULE_UNI_FILE =3D PeiTpmMeasurementLib.uni=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[Sources]=0D + PeiTpmMeasurementLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + SecurityPkg/SecurityPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + BaseMemoryLib=0D + HobLib=0D + DebugLib=0D + PcdLib=0D + PrintLib=0D + PeiServicesLib=0D + PeiServicesTablePointerLib=0D +=0D +[Ppis]=0D + gEdkiiTcgPpiGuid ## = CONSUMES=0D +=0D +[Depex]=0D + gEfiPeiMasterBootModePpiGuid AND=0D + gEfiTpmDeviceSelectedGuid=0D diff --git a/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.= uni b/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.uni new file mode 100644 index 0000000000..7b4341b449 --- /dev/null +++ b/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.uni @@ -0,0 +1,17 @@ +// /** @file=0D +// Provides TPM measurement functions for TPM1.2 and TPM 2.0=0D +//=0D +// This library provides TpmMeasureAndLogData() to to measure and log data= , and=0D +// extend the measurement result into a specific PCR.=0D +//=0D +// Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +// **/=0D +=0D +=0D +#string STR_MODULE_ABSTRACT #language en-US "Provides TPM meas= urement functions for TPM1.2 and TPM 2.0"=0D +=0D +#string STR_MODULE_DESCRIPTION #language en-US "This library prov= ides TpmMeasureAndLogData() to to measure and log data, and extend the meas= urement result into a specific PCR."=0D +=0D --=20 2.26.2.windows.1