]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c
OvmfPkg: Add section of memory to use for PEI on S3 resume
[mirror_edk2.git] / SecurityPkg / Library / HashLibBaseCryptoRouter / HashLibBaseCryptoRouterCommon.c
CommitLineData
c1d93242
JY
1/** @file\r
2 Ihis is BaseCrypto router support function.\r
3\r
4Copyright (c) 2013, Intel Corporation. All rights reserved. <BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiPei.h>\r
16#include <Library/BaseLib.h>\r
17#include <Library/BaseMemoryLib.h>\r
18#include <Library/Tpm2CommandLib.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/MemoryAllocationLib.h>\r
21#include <Library/HashLib.h>\r
22#include <Protocol/TrEEProtocol.h>\r
23\r
24typedef struct {\r
25 EFI_GUID Guid;\r
26 UINT32 Mask;\r
27} TPM2_HASH_MASK;\r
28\r
29TPM2_HASH_MASK mTpm2HashMask[] = {\r
30 {HASH_ALGORITHM_SHA1_GUID, TREE_BOOT_HASH_ALG_SHA1},\r
31 {HASH_ALGORITHM_SHA256_GUID, TREE_BOOT_HASH_ALG_SHA256},\r
32 {HASH_ALGORITHM_SHA384_GUID, TREE_BOOT_HASH_ALG_SHA384},\r
33 {HASH_ALGORITHM_SHA512_GUID, TREE_BOOT_HASH_ALG_SHA512},\r
34};\r
35\r
36/**\r
37 The function get hash mask info from algorithm.\r
38\r
39 @param HashGuid Hash Guid\r
40\r
41 @return HashMask\r
42**/\r
43UINT32\r
44EFIAPI\r
45Tpm2GetHashMaskFromAlgo (\r
46 IN EFI_GUID *HashGuid\r
47 )\r
48{\r
49 UINTN Index;\r
50 for (Index = 0; Index < sizeof(mTpm2HashMask)/sizeof(mTpm2HashMask[0]); Index++) {\r
51 if (CompareGuid (HashGuid, &mTpm2HashMask[Index].Guid)) {\r
52 return mTpm2HashMask[Index].Mask;\r
53 }\r
54 }\r
55 return 0;\r
56}\r
57\r
58/**\r
59 The function set digest to digest list.\r
60\r
61 @param DigestList digest list\r
62 @param Digest digest data\r
63**/\r
64VOID\r
65EFIAPI\r
66Tpm2SetHashToDigestList (\r
67 IN OUT TPML_DIGEST_VALUES *DigestList,\r
68 IN TPML_DIGEST_VALUES *Digest\r
69 )\r
70{\r
71 CopyMem (\r
72 &DigestList->digests[DigestList->count],\r
73 &Digest->digests[0],\r
74 sizeof(Digest->digests[0])\r
75 );\r
76 DigestList->count ++;\r
77}\r