]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c
SecurityPkg: Replace BSD License with BSD+Patent License
[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 };
29
30 /**
31 The function get hash mask info from algorithm.
32
33 @param HashGuid Hash Guid
34
35 @return HashMask
36 **/
37 UINT32
38 EFIAPI
39 Tpm2GetHashMaskFromAlgo (
40 IN EFI_GUID *HashGuid
41 )
42 {
43 UINTN Index;
44 for (Index = 0; Index < sizeof(mTpm2HashMask)/sizeof(mTpm2HashMask[0]); Index++) {
45 if (CompareGuid (HashGuid, &mTpm2HashMask[Index].Guid)) {
46 return mTpm2HashMask[Index].Mask;
47 }
48 }
49 return 0;
50 }
51
52 /**
53 The function set digest to digest list.
54
55 @param DigestList digest list
56 @param Digest digest data
57 **/
58 VOID
59 EFIAPI
60 Tpm2SetHashToDigestList (
61 IN OUT TPML_DIGEST_VALUES *DigestList,
62 IN TPML_DIGEST_VALUES *Digest
63 )
64 {
65 CopyMem (
66 &DigestList->digests[DigestList->count],
67 &Digest->digests[0],
68 sizeof(Digest->digests[0])
69 );
70 DigestList->count ++;
71 }