]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
SecurityPkg/TPM2: Move GetDigestFromDigestList() to Tpm2CommandLib
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Help.c
index 5e24290f7c8ad9a72c5e3021a1aacb2e3e2c3d2f..b40c2ab09d30186a6cb2540d5f3c097c162b3e11 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implement TPM2 help.\r
 \r
-Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2013 - 2016, 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
@@ -164,3 +164,39 @@ CopyAuthSessionResponse (
 \r
   return (UINT32)(UINTN)(Buffer - (UINT8 *)AuthSessionIn);\r
 }\r
+\r
+/**\r
+  This function get digest from digest list.\r
+\r
+  @param HashAlg    digest algorithm\r
+  @param DigestList digest list\r
+  @param Digest     digest\r
+\r
+  @retval EFI_SUCCESS   Sha1Digest is found and returned.\r
+  @retval EFI_NOT_FOUND Sha1Digest is not found.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetDigestFromDigestList (\r
+  IN TPMI_ALG_HASH      HashAlg,\r
+  IN TPML_DIGEST_VALUES *DigestList,\r
+  IN VOID               *Digest\r
+  )\r
+{\r
+  UINTN  Index;\r
+  UINT16 DigestSize;\r
+\r
+  DigestSize = GetHashSizeFromAlgo (HashAlg);\r
+  for (Index = 0; Index < DigestList->count; Index++) {\r
+    if (DigestList->digests[Index].hashAlg == HashAlg) {\r
+      CopyMem (\r
+        Digest,\r
+        &DigestList->digests[Index].digest,\r
+        DigestSize\r
+        );\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}
\ No newline at end of file