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: Star Zeng <star.zeng@intel.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Chao Zhang <chao.b.zhang@intel.com>
Subject: [PATCH V2 2/4] SecurityPkg TPM2: Add GetHashMaskFromAlgo() into Tpm2CommandLib
Date: Fri, 18 Nov 2016 13:57:46 +0800	[thread overview]
Message-ID: <1479448668-68452-3-git-send-email-star.zeng@intel.com> (raw)
In-Reply-To: <1479448668-68452-1-git-send-email-star.zeng@intel.com>

Add GetHashMaskFromAlgo() into Tpm2CommandLib for coming consumer.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 SecurityPkg/Include/Library/Tpm2CommandLib.h  | 13 ++++++++++
 SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c | 34 +++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/SecurityPkg/Include/Library/Tpm2CommandLib.h b/SecurityPkg/Include/Library/Tpm2CommandLib.h
index 85a4c65e0263..699270f127a1 100644
--- a/SecurityPkg/Include/Library/Tpm2CommandLib.h
+++ b/SecurityPkg/Include/Library/Tpm2CommandLib.h
@@ -1007,6 +1007,19 @@ GetHashSizeFromAlgo (
   );
 
 /**
+  Get hash mask from algorithm.
+
+  @param[in] HashAlgo   Hash algorithm
+
+  @return Hash mask
+**/
+UINT32
+EFIAPI
+GetHashMaskFromAlgo (
+  IN TPMI_ALG_HASH     HashAlgo
+  );
+
+/**
   Return if hash alg is supported in HashAlgorithmMask.
 
   @param HashAlg            Hash algorithm to be checked.
diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
index 95d4f7c84ce9..9aa77af97af1 100644
--- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
+++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
@@ -22,14 +22,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 typedef struct {
   TPMI_ALG_HASH              HashAlgo;
   UINT16                     HashSize;
+  UINT32                     HashMask;
 } INTERNAL_HASH_INFO;
 
 STATIC INTERNAL_HASH_INFO mHashInfo[] = {
-  {TPM_ALG_SHA1,          SHA1_DIGEST_SIZE},
-  {TPM_ALG_SHA256,        SHA256_DIGEST_SIZE},
-  {TPM_ALG_SM3_256,       SM3_256_DIGEST_SIZE},
-  {TPM_ALG_SHA384,        SHA384_DIGEST_SIZE},
-  {TPM_ALG_SHA512,        SHA512_DIGEST_SIZE},
+  {TPM_ALG_SHA1,          SHA1_DIGEST_SIZE,     HASH_ALG_SHA1},
+  {TPM_ALG_SHA256,        SHA256_DIGEST_SIZE,   HASH_ALG_SHA256},
+  {TPM_ALG_SM3_256,       SM3_256_DIGEST_SIZE,  HASH_ALG_SM3_256},
+  {TPM_ALG_SHA384,        SHA384_DIGEST_SIZE,   HASH_ALG_SHA384},
+  {TPM_ALG_SHA512,        SHA512_DIGEST_SIZE,   HASH_ALG_SHA512},
 };
 
 /**
@@ -56,6 +57,29 @@ GetHashSizeFromAlgo (
 }
 
 /**
+  Get hash mask from algorithm.
+
+  @param[in] HashAlgo   Hash algorithm
+
+  @return Hash mask
+**/
+UINT32
+EFIAPI
+GetHashMaskFromAlgo (
+  IN TPMI_ALG_HASH     HashAlgo
+  )
+{
+  UINTN  Index;
+
+  for (Index = 0; Index < sizeof(mHashInfo)/sizeof(mHashInfo[0]); Index++) {
+    if (mHashInfo[Index].HashAlgo == HashAlgo) {
+      return mHashInfo[Index].HashMask;
+    }
+  }
+  return 0;
+}
+
+/**
   Copy AuthSessionIn to TPM2 command buffer.
 
   @param [in]  AuthSessionIn   Input AuthSession data
-- 
2.7.0.windows.1



  parent reply	other threads:[~2016-11-18  5:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18  5:57 [PATCH V2 0/4] Tcg2Dxe: Filter inactive digest in event2 log from PEI HOB Star Zeng
2016-11-18  5:57 ` [PATCH V2 1/4] SecurityPkg TPM2: Make IsHashAlgSupportedInHashAlgorithmMask external Star Zeng
2016-11-18  5:57 ` Star Zeng [this message]
2016-11-18  5:57 ` [PATCH V2 3/4] SecurityPkg TPM2: Update desc for param Buffer of GetDigestListSize() Star Zeng
2016-11-18  5:57 ` [PATCH V2 4/4] SecurityPkg Tcg2Dxe: Filter inactive digest in event2 log from PEI HOB Star Zeng
2016-11-18  7:04 ` [PATCH V2 0/4] " Zhang, Chao B
2016-11-18  7:46 ` 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=1479448668-68452-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