]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg HashLibRouter: Avoid incorrect PcdTcg2HashAlgorithmBitmap
authorStar Zeng <star.zeng@intel.com>
Tue, 17 Jan 2017 09:58:26 +0000 (17:58 +0800)
committerStar Zeng <star.zeng@intel.com>
Wed, 8 Feb 2017 10:52:07 +0000 (18:52 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=244

Currently, when software HashLib (HashLibBaseCryptoRouter) and related
HashInstanceLib instances are used, PcdTcg2HashAlgorithmBitmap is
expected to be configured to 0 in platform dsc.
But PcdTcg2HashAlgorithmBitmap has default value 0xFFFFFFFF in
SecurityPkg.dec, and some platforms forget to configure it to 0 or
still configure it to 0xFFFFFFFF in platform dsc, that will make final
PcdTcg2HashAlgorithmBitmap value incorrect.

This patch is to add CONSTRUCTOR in HashLib (HashLibBaseCryptoRouter)
and PcdTcg2HashAlgorithmBitmap will be set to 0 in the CONSTRUCTOR.

Current HASH_LIB_PEI_ROUTER_GUID HOB created in
HashLibBaseCryptoRouterPei is shared between modules that link
HashLibBaseCryptoRouterPei.
To avoid mutual interference, separated HASH_LIB_PEI_ROUTER_GUID HOBs
with gEfiCallerIdGuid Identifier will be created for those modules.

This patch is also to add check in HashLib (HashLibBaseCryptoRouter)
for the mismatch of supported HashMask between modules that may link
different HashInstanceLib instances, warning will be reported if
mismatch is found.

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>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Chao Zhang <chao.b.zhang@intel.com>
SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c
SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf
SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf
SecurityPkg/SecurityPkg.dec
SecurityPkg/SecurityPkg.uni

index 3250c3a01a0c6c8abcfe9d6090f7b75378963fda..7bb5087550577764f1bcf6c9ef21629da39514ad 100644 (file)
@@ -3,7 +3,7 @@
   hash handler registerd, such as SHA1, SHA256.\r
   Platform can use PcdTpm2HashMask to mask some hash engines.\r
 \r
-Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved. <BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -28,6 +28,30 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 HASH_INTERFACE   mHashInterface[HASH_COUNT] = {{{0}, NULL, NULL, NULL}};\r
 UINTN            mHashInterfaceCount = 0;\r
 \r
+UINT32           mSupportedHashMaskLast = 0;\r
+UINT32           mSupportedHashMaskCurrent = 0;\r
+\r
+/**\r
+  Check mismatch of supported HashMask between modules\r
+  that may link different HashInstanceLib instances.\r
+\r
+**/\r
+VOID\r
+CheckSupportedHashMaskMismatch (\r
+  VOID\r
+  )\r
+{\r
+  if (mSupportedHashMaskCurrent != mSupportedHashMaskLast) {\r
+    DEBUG ((\r
+      DEBUG_WARN,\r
+      "WARNING: There is mismatch of supported HashMask (0x%x - 0x%x) between modules\n",\r
+      mSupportedHashMaskCurrent,\r
+      mSupportedHashMaskLast\r
+      ));\r
+    DEBUG ((DEBUG_WARN, "that are linking different HashInstanceLib instances!\n"));\r
+  }\r
+}\r
+\r
 /**\r
   Start hash sequence.\r
 \r
@@ -50,6 +74,8 @@ HashStart (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  CheckSupportedHashMaskMismatch ();\r
+\r
   HashCtx = AllocatePool (sizeof(*HashCtx) * mHashInterfaceCount);\r
   ASSERT (HashCtx != NULL);\r
 \r
@@ -90,6 +116,8 @@ HashUpdate (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  CheckSupportedHashMaskMismatch ();\r
+\r
   HashCtx = (HASH_HANDLE *)HashHandle;\r
 \r
   for (Index = 0; Index < mHashInterfaceCount; Index++) {\r
@@ -133,6 +161,8 @@ HashCompleteAndExtend (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  CheckSupportedHashMaskMismatch ();\r
+\r
   HashCtx = (HASH_HANDLE *)HashHandle;\r
   ZeroMem (DigestList, sizeof(*DigestList));\r
 \r
@@ -180,6 +210,8 @@ HashAndExtend (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  CheckSupportedHashMaskMismatch ();\r
+\r
   HashStart (&HashHandle);\r
   HashUpdate (HashHandle, DataToHash, DataToHashLen);\r
   Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);\r
@@ -204,7 +236,6 @@ RegisterHashInterfaceLib (
 {\r
   UINTN              Index;\r
   UINT32             HashMask;\r
-  UINT32             BiosSupportedHashMask;\r
   EFI_STATUS         Status;\r
 \r
   //\r
@@ -218,21 +249,58 @@ RegisterHashInterfaceLib (
   if (mHashInterfaceCount >= sizeof(mHashInterface)/sizeof(mHashInterface[0])) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  BiosSupportedHashMask = PcdGet32 (PcdTcg2HashAlgorithmBitmap);\r
-  Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, BiosSupportedHashMask | HashMask);\r
-  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Check duplication\r
   //\r
   for (Index = 0; Index < mHashInterfaceCount; Index++) {\r
     if (CompareGuid (&mHashInterface[Index].HashGuid, &HashInterface->HashGuid)) {\r
+      DEBUG ((DEBUG_ERROR, "Hash Interface (%g) has been registered\n", &HashInterface->HashGuid));\r
       return EFI_ALREADY_STARTED;\r
     }\r
   }\r
 \r
+  //\r
+  // Record hash algorithm bitmap of CURRENT module which consumes HashLib.\r
+  //\r
+  mSupportedHashMaskCurrent = PcdGet32 (PcdTcg2HashAlgorithmBitmap) | HashMask;\r
+  Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, mSupportedHashMaskCurrent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   CopyMem (&mHashInterface[mHashInterfaceCount], HashInterface, sizeof(*HashInterface));\r
   mHashInterfaceCount ++;\r
   \r
   return EFI_SUCCESS;\r
-}
\ No newline at end of file
+}\r
+\r
+/**\r
+  The constructor function of HashLibBaseCryptoRouterDxe.\r
+  \r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS   The constructor executed correctly.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HashLibBaseCryptoRouterDxeConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  //\r
+  // Record hash algorithm bitmap of LAST module which also consumes HashLib.\r
+  //\r
+  mSupportedHashMaskLast = PcdGet32 (PcdTcg2HashAlgorithmBitmap);\r
+\r
+  //\r
+  // Set PcdTcg2HashAlgorithmBitmap to 0 in CONSTRUCTOR for CURRENT module.\r
+  //\r
+  Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, 0);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
index c4e40d47d998f01f92dc0bacba7d36a752c7ec25..6e660d4f14f89e8b5f458257df7e28fedac66177 100644 (file)
@@ -5,7 +5,7 @@
 #  hash handler registered, such as SHA1, SHA256. Platform can use PcdTpm2HashMask to \r
 #  mask some hash engines.\r
 #\r
-# Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution. The full text of the license may be found at\r
@@ -23,6 +23,7 @@
   MODULE_TYPE                    = DXE_DRIVER\r
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = HashLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  CONSTRUCTOR                    = HashLibBaseCryptoRouterDxeConstructor\r
 \r
 #\r
 # The following information is for reference only and not required by the build tools.\r
index a4fc0c6595d8afeeb8cb60abac1141c70bd10b5a..dbee0f2531bc943906ce29cbdc7384927f2af902 100644 (file)
@@ -3,7 +3,7 @@
   hash handler registerd, such as SHA1, SHA256.\r
   Platform can use PcdTpm2HashMask to mask some hash engines.\r
 \r
-Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved. <BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -23,6 +23,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/PcdLib.h>\r
 #include <Library/HobLib.h>\r
 #include <Library/HashLib.h>\r
+#include <Guid/ZeroGuid.h>\r
 \r
 #include "HashLibBaseCryptoRouterCommon.h"\r
 \r
@@ -32,27 +33,95 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 EFI_GUID mHashLibPeiRouterGuid = HASH_LIB_PEI_ROUTER_GUID;\r
 \r
 typedef struct {\r
+  //\r
+  // If gZeroGuid, SupportedHashMask is 0 for FIRST module which consumes HashLib\r
+  //   or the hash algorithm bitmap of LAST module which consumes HashLib.\r
+  //   HashInterfaceCount and HashInterface are all 0.\r
+  // If gEfiCallerIdGuid, HashInterfaceCount, HashInterface and SupportedHashMask\r
+  //   are the hash interface information of CURRENT module which consumes HashLib.\r
+  //\r
+  EFI_GUID         Identifier;\r
   UINTN            HashInterfaceCount;\r
   HASH_INTERFACE   HashInterface[HASH_COUNT];\r
+  UINT32           SupportedHashMask;\r
 } HASH_INTERFACE_HOB;\r
 \r
 /**\r
-  This function get hash interface.\r
+  This function gets hash interface hob.\r
+\r
+  @param Identifier    Identifier to get hash interface hob.\r
+\r
+  @retval hash interface hob.\r
+**/\r
+HASH_INTERFACE_HOB *\r
+InternalGetHashInterfaceHob (\r
+  EFI_GUID      *Identifier\r
+  )\r
+{\r
+  EFI_PEI_HOB_POINTERS  Hob;\r
+  HASH_INTERFACE_HOB    *HashInterfaceHob;\r
+\r
+  Hob.Raw = GetFirstGuidHob (&mHashLibPeiRouterGuid);\r
+  while (Hob.Raw != NULL) {\r
+    HashInterfaceHob = GET_GUID_HOB_DATA (Hob);\r
+    if (CompareGuid (&HashInterfaceHob->Identifier, Identifier)) {\r
+      //\r
+      // Found the matched one.\r
+      //\r
+      return HashInterfaceHob;\r
+    }\r
+    Hob.Raw = GET_NEXT_HOB (Hob);\r
+    Hob.Raw = GetNextGuidHob (&mHashLibPeiRouterGuid, Hob.Raw);\r
+  }\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  This function creates hash interface hob.\r
 \r
-  @retval hash interface.\r
+  @param Identifier    Identifier to create hash interface hob.\r
+\r
+  @retval hash interface hob.\r
 **/\r
 HASH_INTERFACE_HOB *\r
-InternalGetHashInterface (\r
-  VOID\r
+InternalCreateHashInterfaceHob (\r
+  EFI_GUID      *Identifier\r
   )\r
 {\r
-  EFI_HOB_GUID_TYPE *Hob;\r
+  HASH_INTERFACE_HOB LocalHashInterfaceHob;\r
+\r
+  ZeroMem (&LocalHashInterfaceHob, sizeof(LocalHashInterfaceHob));\r
+  CopyGuid (&LocalHashInterfaceHob.Identifier, Identifier);\r
+  return BuildGuidDataHob (&mHashLibPeiRouterGuid, &LocalHashInterfaceHob, sizeof(LocalHashInterfaceHob));\r
+}\r
 \r
-  Hob = GetFirstGuidHob (&mHashLibPeiRouterGuid);\r
-  if (Hob == NULL) {\r
-    return NULL;\r
+/**\r
+  Check mismatch of supported HashMask between modules\r
+  that may link different HashInstanceLib instances.\r
+\r
+  @param HashInterfaceHobCurrent    Pointer to hash interface hob for CURRENT module.\r
+\r
+**/\r
+VOID\r
+CheckSupportedHashMaskMismatch (\r
+  IN HASH_INTERFACE_HOB *HashInterfaceHobCurrent\r
+  )\r
+{\r
+  HASH_INTERFACE_HOB    *HashInterfaceHobLast;\r
+\r
+  HashInterfaceHobLast = InternalGetHashInterfaceHob (&gZeroGuid);\r
+  ASSERT (HashInterfaceHobLast != NULL);\r
+\r
+  if ((HashInterfaceHobLast->SupportedHashMask != 0) &&\r
+      (HashInterfaceHobCurrent->SupportedHashMask != HashInterfaceHobLast->SupportedHashMask)) {\r
+    DEBUG ((\r
+      DEBUG_WARN,\r
+      "WARNING: There is mismatch of supported HashMask (0x%x - 0x%x) between modules\n",\r
+      HashInterfaceHobCurrent->SupportedHashMask,\r
+      HashInterfaceHobLast->SupportedHashMask\r
+      ));\r
+    DEBUG ((DEBUG_WARN, "that are linking different HashInstanceLib instances!\n"));\r
   }\r
-  return (HASH_INTERFACE_HOB *)(Hob + 1);\r
 }\r
 \r
 /**\r
@@ -74,7 +143,7 @@ HashStart (
   UINTN              Index;\r
   UINT32             HashMask;\r
 \r
-  HashInterfaceHob = InternalGetHashInterface ();\r
+  HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);\r
   if (HashInterfaceHob == NULL) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -83,6 +152,8 @@ HashStart (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  CheckSupportedHashMaskMismatch (HashInterfaceHob);\r
+\r
   HashCtx = AllocatePool (sizeof(*HashCtx) * HashInterfaceHob->HashInterfaceCount);\r
   ASSERT (HashCtx != NULL);\r
 \r
@@ -120,7 +191,7 @@ HashUpdate (
   UINTN              Index;\r
   UINT32             HashMask;\r
 \r
-  HashInterfaceHob = InternalGetHashInterface ();\r
+  HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);\r
   if (HashInterfaceHob == NULL) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -129,6 +200,8 @@ HashUpdate (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  CheckSupportedHashMaskMismatch (HashInterfaceHob);\r
+\r
   HashCtx = (HASH_HANDLE *)HashHandle;\r
 \r
   for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {\r
@@ -169,7 +242,7 @@ HashCompleteAndExtend (
   EFI_STATUS         Status;\r
   UINT32             HashMask;\r
 \r
-  HashInterfaceHob = InternalGetHashInterface ();\r
+  HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);\r
   if (HashInterfaceHob == NULL) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -178,6 +251,8 @@ HashCompleteAndExtend (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  CheckSupportedHashMaskMismatch (HashInterfaceHob);\r
+\r
   HashCtx = (HASH_HANDLE *)HashHandle;\r
   ZeroMem (DigestList, sizeof(*DigestList));\r
 \r
@@ -222,7 +297,7 @@ HashAndExtend (
   HASH_HANDLE        HashHandle;\r
   EFI_STATUS         Status;\r
 \r
-  HashInterfaceHob = InternalGetHashInterface ();\r
+  HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);\r
   if (HashInterfaceHob == NULL) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -231,6 +306,8 @@ HashAndExtend (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  CheckSupportedHashMaskMismatch (HashInterfaceHob);\r
+\r
   HashStart (&HashHandle);\r
   HashUpdate (HashHandle, DataToHash, DataToHashLen);\r
   Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);\r
@@ -255,9 +332,7 @@ RegisterHashInterfaceLib (
 {\r
   UINTN              Index;\r
   HASH_INTERFACE_HOB *HashInterfaceHob;\r
-  HASH_INTERFACE_HOB LocalHashInterfaceHob;\r
   UINT32             HashMask;\r
-  UINT32             BiosSupportedHashMask;\r
   EFI_STATUS         Status;\r
 \r
   //\r
@@ -268,10 +343,9 @@ RegisterHashInterfaceLib (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  HashInterfaceHob = InternalGetHashInterface ();\r
+  HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);\r
   if (HashInterfaceHob == NULL) {\r
-    ZeroMem (&LocalHashInterfaceHob, sizeof(LocalHashInterfaceHob));\r
-    HashInterfaceHob = BuildGuidDataHob (&mHashLibPeiRouterGuid, &LocalHashInterfaceHob, sizeof(LocalHashInterfaceHob));\r
+    HashInterfaceHob = InternalCreateHashInterfaceHob (&gEfiCallerIdGuid);\r
     if (HashInterfaceHob == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
@@ -280,26 +354,84 @@ RegisterHashInterfaceLib (
   if (HashInterfaceHob->HashInterfaceCount >= HASH_COUNT) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  BiosSupportedHashMask = PcdGet32 (PcdTcg2HashAlgorithmBitmap);\r
-  Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, BiosSupportedHashMask | HashMask);\r
-  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Check duplication\r
   //\r
   for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {\r
     if (CompareGuid (&HashInterfaceHob->HashInterface[Index].HashGuid, &HashInterface->HashGuid)) {\r
-      //\r
-      // In PEI phase, there will be shadow driver dispatched again.\r
-      //\r
-      DEBUG ((EFI_D_INFO, "RegisterHashInterfaceLib - Override\n"));\r
-      CopyMem (&HashInterfaceHob->HashInterface[Index], HashInterface, sizeof(*HashInterface));\r
-      return EFI_SUCCESS;\r
+      DEBUG ((DEBUG_ERROR, "Hash Interface (%g) has been registered\n", &HashInterface->HashGuid));\r
+      return EFI_ALREADY_STARTED;\r
     }\r
   }\r
 \r
+  //\r
+  // Record hash algorithm bitmap of CURRENT module which consumes HashLib.\r
+  //\r
+  HashInterfaceHob->SupportedHashMask = PcdGet32 (PcdTcg2HashAlgorithmBitmap) | HashMask;\r
+  Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, HashInterfaceHob->SupportedHashMask);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   CopyMem (&HashInterfaceHob->HashInterface[HashInterfaceHob->HashInterfaceCount], HashInterface, sizeof(*HashInterface));\r
   HashInterfaceHob->HashInterfaceCount ++;\r
   \r
   return EFI_SUCCESS;\r
-}
\ No newline at end of file
+}\r
+\r
+/**\r
+  The constructor function of HashLibBaseCryptoRouterPei.\r
+\r
+  @param  FileHandle   The handle of FFS header the loaded driver.\r
+  @param  PeiServices  The pointer to the PEI services.\r
+\r
+  @retval EFI_SUCCESS           The constructor executes successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource for the constructor.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HashLibBaseCryptoRouterPeiConstructor (\r
+  IN EFI_PEI_FILE_HANDLE        FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  HASH_INTERFACE_HOB    *HashInterfaceHob;\r
+\r
+  HashInterfaceHob = InternalGetHashInterfaceHob (&gZeroGuid);\r
+  if (HashInterfaceHob == NULL) {\r
+    //\r
+    // No HOB with gZeroGuid Identifier has been created,\r
+    // this is FIRST module which consumes HashLib.\r
+    // Create the HOB with gZeroGuid Identifier.\r
+    //\r
+    HashInterfaceHob = InternalCreateHashInterfaceHob (&gZeroGuid);\r
+    if (HashInterfaceHob == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  } else {\r
+    //\r
+    // Record hash algorithm bitmap of LAST module which also consumes HashLib.\r
+    //\r
+    HashInterfaceHob->SupportedHashMask = PcdGet32 (PcdTcg2HashAlgorithmBitmap);\r
+  }\r
+\r
+  HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);\r
+  if (HashInterfaceHob != NULL) {\r
+    //\r
+    // In PEI phase, some modules may call RegisterForShadow and will be\r
+    // shadowed and executed again after memory is discovered.\r
+    // This is the second execution of this module, clear the hash interface\r
+    // information registered at its first execution.\r
+    //\r
+    ZeroMem (&HashInterfaceHob->HashInterface, sizeof (*HashInterfaceHob) - sizeof (EFI_GUID));\r
+  }\r
+\r
+  //\r
+  // Set PcdTcg2HashAlgorithmBitmap to 0 in CONSTRUCTOR for CURRENT module.\r
+  //\r
+  Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, 0);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
index f5ca5d4635d8aaff8fd8fdf55c12833de0ff0bd8..eebf90e2ef40148a86f45fdd93f64788c5d3b2cd 100644 (file)
@@ -5,7 +5,7 @@
 #  hash handler registered, such as SHA1, SHA256. Platform can use PcdTpm2HashMask to \r
 #  mask some hash engines.\r
 #\r
-# Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution. The full text of the license may be found at\r
@@ -23,6 +23,7 @@
   MODULE_TYPE                    = PEIM\r
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = HashLib|PEIM\r
+  CONSTRUCTOR                    = HashLibBaseCryptoRouterPeiConstructor\r
 \r
 #\r
 # The following information is for reference only and not required by the build tools.\r
@@ -38,6 +39,7 @@
 [Packages]\r
   MdePkg/MdePkg.dec\r
   SecurityPkg/SecurityPkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
 \r
 [LibraryClasses]\r
   BaseLib\r
   PcdLib\r
   HobLib\r
 \r
+[Guids]\r
+  ## CONSUMES   ## GUID\r
+  gZeroGuid\r
+\r
 [Pcd]\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTpm2HashMask             ## CONSUMES\r
   ## SOMETIMES_CONSUMES\r
index b556fb68da1cc406772ffc3eaca2400de39ac403..07a66f5fac300f9507d401e924219c281bed1fe9 100644 (file)
   ## This PCD indicated final BIOS supported Hash mask.\r
   #    Bios may choose to register a subset of PcdTpm2HashMask.\r
   #    So this PCD is final value of how many hash algo is extended to PCR.\r
+  # If software HashLib(HashLibBaseCryptoRouter) solution is chosen, this PCD\r
+  # has no need to be configured in platform dsc and will be set to correct\r
+  # value by the HashLib instance according to the HashInstanceLib instances\r
+  # linked, and the value of this PCD should be got in module entrypoint.\r
   # @Prompt Hash Algorithm bitmap.\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTcg2HashAlgorithmBitmap|0xFFFFFFFF|UINT32|0x00010016\r
   \r
index 17d36c0d6014a44a39c9c1209ee2b6b05729efad..126351624056982ce24872677b847f6ec1e52cb3 100644 (file)
 \r
 #string STR_gEfiSecurityPkgTokenSpaceGuid_PcdTcg2HashAlgorithmBitmap_HELP  #language en-US "This PCD indicated final BIOS supported Hash mask.\n"\r
                                                                                            "Bios may choose to register a subset of PcdTpm2HashMask.\n"\r
-                                                                                           "So this PCD is final value of how many hash algo is extended to PCR."\r
+                                                                                           "So this PCD is final value of how many hash algo is extended to PCR.\n"\r
+                                                                                           "If software HashLib(HashLibBaseCryptoRouter) solution is chosen, this PCD\n"\r
+                                                                                           "has no need to be configured in platform dsc and will be set to correct\n"\r
+                                                                                           "value by the HashLib instance according to the HashInstanceLib instances\n"\r
+                                                                                           "linked, and the value of this PCD should be got in module entrypoint."\r
 \r
 #string STR_gEfiSecurityPkgTokenSpaceGuid_PcdTcgLogAreaMinLen_PROMPT  #language en-US "Minimum length(in bytes) of the system preboot TCG event log area(LAML)."\r
 \r
 #string STR_gEfiSecurityPkgTokenSpaceGuid_PcdTpm2AcpiTableRev_HELP  #language en-US "This PCD defines initial revision of TPM2 ACPI table\n"\r
                                                                                     "To support configuring from setup page, this PCD can be DynamicHii type and map to a setup option.<BR>\n"\r
                                                                                     "For example, map to TCG2_VERSION.Tpm2AcpiTableRev to be configured by Tcg2ConfigDxe driver.<BR>\n"\r
-                                                                                    "gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableRev|L\"TCG2_VERSION\"|gTcg2ConfigFormSetGuid|0x8|3|NV,BS<BR>"
\ No newline at end of file
+                                                                                    "gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableRev|L\"TCG2_VERSION\"|gTcg2ConfigFormSetGuid|0x8|3|NV,BS<BR>"\r