From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BFEFE81F0F for ; Thu, 17 Nov 2016 21:57:49 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 17 Nov 2016 21:57:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,655,1473145200"; d="scan'208";a="1086940586" Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.9]) by fmsmga002.fm.intel.com with ESMTP; 17 Nov 2016 21:57:53 -0800 From: Star Zeng To: edk2-devel@lists.01.org Cc: Star Zeng , Jiewen Yao , Chao Zhang Date: Fri, 18 Nov 2016 13:57:46 +0800 Message-Id: <1479448668-68452-3-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1479448668-68452-1-git-send-email-star.zeng@intel.com> References: <1479448668-68452-1-git-send-email-star.zeng@intel.com> Subject: [PATCH V2 2/4] SecurityPkg TPM2: Add GetHashMaskFromAlgo() into Tpm2CommandLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Nov 2016 05:57:49 -0000 Add GetHashMaskFromAlgo() into Tpm2CommandLib for coming consumer. Cc: Jiewen Yao Cc: Chao Zhang Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng --- 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