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