public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Star Zeng <star.zeng@intel.com>
To: edk2-devel@lists.01.org
Cc: Jiewen Yao <jiewen.yao@intel.com>,
	Chao B Zhang <chao.b.zhang@intel.com>,
	Star Zeng <star.zeng@intel.com>
Subject: [PATCH 2/6] SecuriryPkg/TPM2: Move GetDigestFromDigestList() to Tpm2CommandLib
Date: Tue, 20 Sep 2016 18:51:29 +0800	[thread overview]
Message-ID: <1474368693-180984-3-git-send-email-star.zeng@intel.com> (raw)
In-Reply-To: <1474368693-180984-1-git-send-email-star.zeng@intel.com>

From: Jiewen Yao <jiewen.yao@intel.com>

This patch just moves function Tpm2GetDigestFromDigestList() from
drivers to library as GetDigestFromDigestList() and no functionality change.

Cc: Chao B Zhang <chao.b.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 SecurityPkg/Include/Library/Tpm2CommandLib.h  | 18 +++++++++++++
 SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c | 38 ++++++++++++++++++++++++++-
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c             | 37 +-------------------------
 SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c             | 37 +-------------------------
 SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c             | 37 +-------------------------
 SecurityPkg/Tcg/TrEEPei/TrEEPei.c             | 37 +-------------------------
 6 files changed, 59 insertions(+), 145 deletions(-)

diff --git a/SecurityPkg/Include/Library/Tpm2CommandLib.h b/SecurityPkg/Include/Library/Tpm2CommandLib.h
index 162db193cb4f..197d64958634 100644
--- a/SecurityPkg/Include/Library/Tpm2CommandLib.h
+++ b/SecurityPkg/Include/Library/Tpm2CommandLib.h
@@ -988,4 +988,22 @@ GetHashSizeFromAlgo (
   IN TPMI_ALG_HASH    HashAlgo
   );
 
+/**
+  This function get digest from digest list.
+
+  @param HashAlg    digest algorithm
+  @param DigestList digest list
+  @param Digest     digest
+
+  @retval EFI_SUCCESS   Sha1Digest is found and returned.
+  @retval EFI_NOT_FOUND Sha1Digest is not found.
+**/
+EFI_STATUS
+EFIAPI
+GetDigestFromDigestList(
+  IN TPMI_ALG_HASH      HashAlg,
+  IN TPML_DIGEST_VALUES *DigestList,
+  IN VOID               *Digest
+  );
+
 #endif
diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
index 5e24290f7c8a..b40c2ab09d30 100644
--- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
+++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
@@ -1,7 +1,7 @@
 /** @file
   Implement TPM2 help.
 
-Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved. <BR>
+Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -164,3 +164,39 @@ CopyAuthSessionResponse (
 
   return (UINT32)(UINTN)(Buffer - (UINT8 *)AuthSessionIn);
 }
+
+/**
+  This function get digest from digest list.
+
+  @param HashAlg    digest algorithm
+  @param DigestList digest list
+  @param Digest     digest
+
+  @retval EFI_SUCCESS   Sha1Digest is found and returned.
+  @retval EFI_NOT_FOUND Sha1Digest is not found.
+**/
+EFI_STATUS
+EFIAPI
+GetDigestFromDigestList (
+  IN TPMI_ALG_HASH      HashAlg,
+  IN TPML_DIGEST_VALUES *DigestList,
+  IN VOID               *Digest
+  )
+{
+  UINTN  Index;
+  UINT16 DigestSize;
+
+  DigestSize = GetHashSizeFromAlgo (HashAlg);
+  for (Index = 0; Index < DigestList->count; Index++) {
+    if (DigestList->digests[Index].hashAlg == HashAlg) {
+      CopyMem (
+        Digest,
+        &DigestList->digests[Index].digest,
+        DigestSize
+        );
+      return EFI_SUCCESS;
+    }
+  }
+
+  return EFI_NOT_FOUND;
+}
\ No newline at end of file
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
index 319f24544ac3..9080e4703233 100644
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
@@ -864,41 +864,6 @@ TcgDxeLogEvent (
 }
 
 /**
-  This function get digest from digest list.
-
-  @param HashAlg    digest algorithm
-  @param DigestList digest list
-  @param Digest     digest
-
-  @retval EFI_SUCCESS   Sha1Digest is found and returned.
-  @retval EFI_NOT_FOUND Sha1Digest is not found.
-**/
-EFI_STATUS
-Tpm2GetDigestFromDigestList (
-  IN TPMI_ALG_HASH      HashAlg,
-  IN TPML_DIGEST_VALUES *DigestList,
-  IN VOID               *Digest
-  )
-{
-  UINTN  Index;
-  UINT16 DigestSize;
-
-  DigestSize = GetHashSizeFromAlgo (HashAlg);
-  for (Index = 0; Index < DigestList->count; Index++) {
-    if (DigestList->digests[Index].hashAlg == HashAlg) {
-      CopyMem (
-        Digest,
-        &DigestList->digests[Index].digest,
-        DigestSize
-        );
-      return EFI_SUCCESS;
-    }
-  }
-
-  return EFI_NOT_FOUND;
-}
-
-/**
   Get TPML_DIGEST_VALUES data size.
 
   @param[in]     DigestList    TPML_DIGEST_VALUES data.
@@ -1067,7 +1032,7 @@ TcgDxeLogHashEvent (
       DEBUG ((EFI_D_INFO, "  LogFormat - 0x%08x\n", mTcg2EventInfo[Index].LogFormat));
       switch (mTcg2EventInfo[Index].LogFormat) {
       case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2:
-        Status = Tpm2GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest);
+        Status = GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest);
         if (!EFI_ERROR (Status)) {
           //
           // Enter critical region
diff --git a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
index 0d779f1e3b17..adc0350a48e3 100644
--- a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
+++ b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
@@ -135,41 +135,6 @@ EFI_PEI_NOTIFY_DESCRIPTOR           mNotifyList[] = {
 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *mMeasurementExcludedFvPpi;
 
 /**
-  This function get digest from digest list.
-
-  @param HashAlg    digest algorithm
-  @param DigestList digest list
-  @param Digest     digest
-
-  @retval EFI_SUCCESS   Sha1Digest is found and returned.
-  @retval EFI_NOT_FOUND Sha1Digest is not found.
-**/
-EFI_STATUS
-Tpm2GetDigestFromDigestList (
-  IN TPMI_ALG_HASH      HashAlg,
-  IN TPML_DIGEST_VALUES *DigestList,
-  IN VOID               *Digest
-  )
-{
-  UINTN  Index;
-  UINT16 DigestSize;
-
-  DigestSize = GetHashSizeFromAlgo (HashAlg);
-  for (Index = 0; Index < DigestList->count; Index++) {
-    if (DigestList->digests[Index].hashAlg == HashAlg) {
-      CopyMem (
-        Digest,
-        &DigestList->digests[Index].digest,
-        DigestSize
-        );
-      return EFI_SUCCESS;
-    }
-  }
-
-  return EFI_NOT_FOUND;
-}
-
-/**
   Record all measured Firmware Volum Information into a Guid Hob
   Guid Hob payload layout is 
 
@@ -420,7 +385,7 @@ LogHashEvent (
       DEBUG ((EFI_D_INFO, "  LogFormat - 0x%08x\n", mTcg2EventInfo[Index].LogFormat));
       switch (mTcg2EventInfo[Index].LogFormat) {
       case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2:
-        Status = Tpm2GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest);
+        Status = GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest);
         if (!EFI_ERROR (Status)) {
           HobData = BuildGuidHob (
                      &gTcgEventEntryHobGuid,
diff --git a/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c b/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c
index ecafc12efe1c..fb69fa1860e8 100644
--- a/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c
+++ b/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c
@@ -625,41 +625,6 @@ TcgDxeLogEvent (
 }
 
 /**
-  This function get digest from digest list.
-
-  @param HashAlg    digest algorithm
-  @param DigestList digest list
-  @param Digest     digest
-
-  @retval EFI_SUCCESS   Sha1Digest is found and returned.
-  @retval EFI_NOT_FOUND Sha1Digest is not found.
-**/
-EFI_STATUS
-Tpm2GetDigestFromDigestList (
-  IN TPMI_ALG_HASH      HashAlg,
-  IN TPML_DIGEST_VALUES *DigestList,
-  IN VOID               *Digest
-  )
-{
-  UINTN  Index;
-  UINT16 DigestSize;
-
-  DigestSize = GetHashSizeFromAlgo (HashAlg);
-  for (Index = 0; Index < DigestList->count; Index++) {
-    if (DigestList->digests[Index].hashAlg == HashAlg) {
-      CopyMem (
-        Digest,
-        &DigestList->digests[Index].digest,
-        DigestSize
-        );
-      return EFI_SUCCESS;
-    }
-  }
-
-  return EFI_NOT_FOUND;
-}
-
-/**
   Add a new entry to the Event Log.
 
   @param[in]     DigestList    A list of digest.
@@ -686,7 +651,7 @@ TcgDxeLogHashEvent (
       DEBUG ((EFI_D_INFO, "  LogFormat - 0x%08x\n", mTreeEventInfo[Index].LogFormat));
       switch (mTreeEventInfo[Index].LogFormat) {
       case TREE_EVENT_LOG_FORMAT_TCG_1_2:
-        Status = Tpm2GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest);
+        Status = GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest);
         if (!EFI_ERROR (Status)) {
           //
           // Enter critical region
diff --git a/SecurityPkg/Tcg/TrEEPei/TrEEPei.c b/SecurityPkg/Tcg/TrEEPei/TrEEPei.c
index 41edfdd0e6ec..8d8639d271c7 100644
--- a/SecurityPkg/Tcg/TrEEPei/TrEEPei.c
+++ b/SecurityPkg/Tcg/TrEEPei/TrEEPei.c
@@ -133,41 +133,6 @@ EFI_PEI_NOTIFY_DESCRIPTOR           mNotifyList[] = {
 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *mMeasurementExcludedFvPpi;
 
 /**
-  This function get digest from digest list.
-
-  @param HashAlg    digest algorithm
-  @param DigestList digest list
-  @param Digest     digest
-
-  @retval EFI_SUCCESS   Sha1Digest is found and returned.
-  @retval EFI_NOT_FOUND Sha1Digest is not found.
-**/
-EFI_STATUS
-Tpm2GetDigestFromDigestList (
-  IN TPMI_ALG_HASH      HashAlg,
-  IN TPML_DIGEST_VALUES *DigestList,
-  IN VOID               *Digest
-  )
-{
-  UINTN  Index;
-  UINT16 DigestSize;
-
-  DigestSize = GetHashSizeFromAlgo (HashAlg);
-  for (Index = 0; Index < DigestList->count; Index++) {
-    if (DigestList->digests[Index].hashAlg == HashAlg) {
-      CopyMem (
-        Digest,
-        &DigestList->digests[Index].digest,
-        DigestSize
-        );
-      return EFI_SUCCESS;
-    }
-  }
-
-  return EFI_NOT_FOUND;
-}
-
-/**
   Record all measured Firmware Volum Information into a Guid Hob
   Guid Hob payload layout is 
 
@@ -249,7 +214,7 @@ LogHashEvent (
       DEBUG ((EFI_D_INFO, "  LogFormat - 0x%08x\n", mTreeEventInfo[Index].LogFormat));
       switch (mTreeEventInfo[Index].LogFormat) {
       case TREE_EVENT_LOG_FORMAT_TCG_1_2:
-        Status = Tpm2GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest);
+        Status = GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest);
         if (!EFI_ERROR (Status)) {
           HobData = BuildGuidHob (
                      &gTcgEventEntryHobGuid,
-- 
2.7.0.windows.1



  parent reply	other threads:[~2016-09-20 10:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-20 10:51 [PATCH 0/6] Move/Extract generic duplicated code to Tpm2CommandLib Star Zeng
2016-09-20 10:51 ` [PATCH 1/6] SecuriryPkg/TPM2: Move Tpm2PcrAllocateBanks() " Star Zeng
2016-09-20 10:51 ` Star Zeng [this message]
2016-09-20 10:51 ` [PATCH 3/6] SecuriryPkg/TPM2: Update function header of GetDigestFromDigestList() Star Zeng
2016-09-20 10:51 ` [PATCH 4/6] SecuriryPkg/TPM2: Move GetDigestListSize() to Tpm2CommandLib Star Zeng
2016-09-20 10:51 ` [PATCH 5/6] SecuriryPkg/TPM2: Move CopyDigestListToBuffer() " Star Zeng
2016-09-20 10:51 ` [PATCH 6/6] SecuriryPkg/TPM2: Extract GetSupportedAndActivePcrs " Star Zeng
2016-09-21  6:05   ` Zhang, Chao B
2016-09-20 10:58 ` [PATCH 0/6] Move/Extract generic duplicated code " Zeng, Star
2016-09-20 14:47 ` Yao, Jiewen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474368693-180984-3-git-send-email-star.zeng@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox