From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com []) by mx.groups.io with SMTP id smtpd.web10.6793.1594971201528724190 for ; Fri, 17 Jul 2020 00:33:30 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: qi1.zhang@intel.com) IronPort-SDR: HzXPc7kSfHkoVFQgeydtZ3CDnIWQz30TAKqfryuLzLAD7MZZ0UeYI8xi0C2ZJ3qgycCstmYIQI 9Hoz5H9r9H7Q== X-IronPort-AV: E=McAfee;i="6000,8403,9684"; a="129113501" X-IronPort-AV: E=Sophos;i="5.75,362,1589266800"; d="scan'208";a="129113501" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2020 00:33:29 -0700 IronPort-SDR: 8rtYzSO3xJ274QwaUA6xvCdTdzpdV3CfIZHpiN9q83vUq3MTG9XHR8MFmBXb3MHcaePBP2RLX7 Ecvih2z6fmqg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,362,1589266800"; d="scan'208";a="361273538" Received: from shwdesssddpdqi.ccr.corp.intel.com ([10.239.9.10]) by orsmga001.jf.intel.com with ESMTP; 17 Jul 2020 00:33:27 -0700 From: "Qi Zhang" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Chao Zhang , Qi Zhang Subject: [PATCH v3 5/6] SecurityPkg/PeiTpmMeasurementLib: Add PEI instance. Date: Fri, 17 Jul 2020 15:33:11 +0800 Message-Id: <20200717073312.10594-6-qi1.zhang@intel.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20200717073312.10594-1-qi1.zhang@intel.com> References: <20200717073312.10594-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 Cc: Qi Zhang Signed-off-by: Jiewen Yao --- .../PeiTpmMeasurementLib.c | 74 +++++++++++++++++++ .../PeiTpmMeasurementLib.inf | 50 +++++++++++++ .../PeiTpmMeasurementLib.uni | 17 +++++ 3 files changed, 141 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..1a590e0c9e --- /dev/null +++ b/SecurityPkg/Library/PeiTpmMeasurementLib/PeiTpmMeasurementLib.c @@ -0,0 +1,74 @@ +/** @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 + 0,=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