]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c
aec874a9e07212fb847e45e6050fed9f4c95fa0b
[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 for (Index = 0; Index < sizeof(mTpm2HashMask)/sizeof(mTpm2HashMask[0]); Index++) {
46 if (CompareGuid (HashGuid, &mTpm2HashMask[Index].Guid)) {
47 return mTpm2HashMask[Index].Mask;
48 }
49 }
50 return 0;
51 }
52
53 /**
54 The function set digest to digest list.
55
56 @param DigestList digest list
57 @param Digest digest data
58 **/
59 VOID
60 EFIAPI
61 Tpm2SetHashToDigestList (
62 IN OUT TPML_DIGEST_VALUES *DigestList,
63 IN TPML_DIGEST_VALUES *Digest
64 )
65 {
66 CopyMem (
67 &DigestList->digests[DigestList->count],
68 &Digest->digests[0],
69 sizeof(Digest->digests[0])
70 );
71 DigestList->count ++;
72 }