]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c
SecurityPkg: Apply uncrustify changes
[mirror_edk2.git] / SecurityPkg / Library / HashLibBaseCryptoRouter / HashLibBaseCryptoRouterCommon.c
1 /** @file
2 This is BaseCrypto router support function.
3
4 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiPei.h>
10 #include <Library/BaseLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/Tpm2CommandLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/MemoryAllocationLib.h>
15 #include <Library/HashLib.h>
16 #include <Protocol/Tcg2Protocol.h>
17
18 typedef struct {
19 EFI_GUID Guid;
20 UINT32 Mask;
21 } TPM2_HASH_MASK;
22
23 TPM2_HASH_MASK mTpm2HashMask[] = {
24 { HASH_ALGORITHM_SHA1_GUID, HASH_ALG_SHA1 },
25 { HASH_ALGORITHM_SHA256_GUID, HASH_ALG_SHA256 },
26 { HASH_ALGORITHM_SHA384_GUID, HASH_ALG_SHA384 },
27 { HASH_ALGORITHM_SHA512_GUID, HASH_ALG_SHA512 },
28 { HASH_ALGORITHM_SM3_256_GUID, HASH_ALG_SM3_256 },
29 };
30
31 /**
32 The function get hash mask info from algorithm.
33
34 @param HashGuid Hash Guid
35
36 @return HashMask
37 **/
38 UINT32
39 EFIAPI
40 Tpm2GetHashMaskFromAlgo (
41 IN EFI_GUID *HashGuid
42 )
43 {
44 UINTN Index;
45
46 for (Index = 0; Index < sizeof (mTpm2HashMask)/sizeof (mTpm2HashMask[0]); Index++) {
47 if (CompareGuid (HashGuid, &mTpm2HashMask[Index].Guid)) {
48 return mTpm2HashMask[Index].Mask;
49 }
50 }
51
52 return 0;
53 }
54
55 /**
56 The function set digest to digest list.
57
58 @param DigestList digest list
59 @param Digest digest data
60 **/
61 VOID
62 EFIAPI
63 Tpm2SetHashToDigestList (
64 IN OUT TPML_DIGEST_VALUES *DigestList,
65 IN TPML_DIGEST_VALUES *Digest
66 )
67 {
68 CopyMem (
69 &DigestList->digests[DigestList->count],
70 &Digest->digests[0],
71 sizeof (Digest->digests[0])
72 );
73 DigestList->count++;
74 }