]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
Add TPM2 support defined in trusted computing group.
[mirror_edk2.git] / SecurityPkg / Library / HashLibBaseCryptoRouter / HashLibBaseCryptoRouterPei.c
index 5bc8d01ad56028bfcf81b40f86e5b580dfac1c59..98c07933d827d27ada6757be272f6e1c870b0059 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 - 2014, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2013 - 2015, 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
@@ -72,6 +72,7 @@ HashStart (
   HASH_INTERFACE_HOB *HashInterfaceHob;\r
   HASH_HANDLE        *HashCtx;\r
   UINTN              Index;\r
+  UINT32             HashMask;\r
 \r
   HashInterfaceHob = InternalGetHashInterface ();\r
   if (HashInterfaceHob == NULL) {\r
@@ -86,7 +87,10 @@ HashStart (
   ASSERT (HashCtx != NULL);\r
 \r
   for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {\r
-    HashInterfaceHob->HashInterface[Index].HashInit (&HashCtx[Index]);\r
+    HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid);\r
+    if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) {\r
+      HashInterfaceHob->HashInterface[Index].HashInit (&HashCtx[Index]);\r
+    }\r
   }\r
 \r
   *HashHandle = (HASH_HANDLE)HashCtx;\r
@@ -114,6 +118,7 @@ HashUpdate (
   HASH_INTERFACE_HOB *HashInterfaceHob;\r
   HASH_HANDLE        *HashCtx;\r
   UINTN              Index;\r
+  UINT32             HashMask;\r
 \r
   HashInterfaceHob = InternalGetHashInterface ();\r
   if (HashInterfaceHob == NULL) {\r
@@ -127,7 +132,10 @@ HashUpdate (
   HashCtx = (HASH_HANDLE *)HashHandle;\r
 \r
   for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {\r
-    HashInterfaceHob->HashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen);\r
+    HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid);\r
+    if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) {\r
+      HashInterfaceHob->HashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen);\r
+    }\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -159,6 +167,7 @@ HashCompleteAndExtend (
   HASH_HANDLE        *HashCtx;\r
   UINTN              Index;\r
   EFI_STATUS         Status;\r
+  UINT32             HashMask;\r
 \r
   HashInterfaceHob = InternalGetHashInterface ();\r
   if (HashInterfaceHob == NULL) {\r
@@ -173,9 +182,12 @@ HashCompleteAndExtend (
   ZeroMem (DigestList, sizeof(*DigestList));\r
 \r
   for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {\r
-    HashInterfaceHob->HashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen);\r
-    HashInterfaceHob->HashInterface[Index].HashFinal (HashCtx[Index], &Digest);\r
-    Tpm2SetHashToDigestList (DigestList, &Digest);\r
+    HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid);\r
+    if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) {\r
+      HashInterfaceHob->HashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen);\r
+      HashInterfaceHob->HashInterface[Index].HashFinal (HashCtx[Index], &Digest);\r
+      Tpm2SetHashToDigestList (DigestList, &Digest);\r
+    }\r
   }\r
 \r
   FreePool (HashCtx);\r
@@ -245,6 +257,7 @@ RegisterHashInterfaceLib (
   HASH_INTERFACE_HOB *HashInterfaceHob;\r
   HASH_INTERFACE_HOB LocalHashInterfaceHob;\r
   UINT32             HashMask;\r
+  UINT32             BiosSupportedHashMask;\r
 \r
   //\r
   // Check allow\r
@@ -266,6 +279,8 @@ RegisterHashInterfaceLib (
   if (HashInterfaceHob->HashInterfaceCount >= HASH_COUNT) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+  BiosSupportedHashMask = PcdGet32 (PcdTcg2HashAlgorithmBitmap);\r
+  PcdSet32 (PcdTcg2HashAlgorithmBitmap, BiosSupportedHashMask | HashMask);\r
 \r
   //\r
   // Check duplication\r