28UINTN mHashInterfaceCount = 0;
30UINT32 mSupportedHashMaskLast = 0;
31UINT32 mSupportedHashMaskCurrent = 0;
43 if (mSupportedHashMaskCurrent != mSupportedHashMaskLast) {
46 "WARNING: There is mismatch of supported HashMask (0x%x - 0x%x) between modules\n",
47 mSupportedHashMaskCurrent,
48 mSupportedHashMaskLast
50 DEBUG ((DEBUG_WARN,
"that are linking different HashInstanceLib instances!\n"));
65 OUT HASH_HANDLE *HashHandle
72 if (mHashInterfaceCount == 0) {
73 return EFI_UNSUPPORTED;
78 HashCtx =
AllocatePool (
sizeof (*HashCtx) * mHashInterfaceCount);
79 ASSERT (HashCtx !=
NULL);
81 for (Index = 0; Index < mHashInterfaceCount; Index++) {
83 if ((HashMask &
PcdGet32 (PcdTpm2HashMask)) != 0) {
84 mHashInterface[Index].HashInit (&HashCtx[Index]);
88 *HashHandle = (HASH_HANDLE)HashCtx;
105 IN HASH_HANDLE HashHandle,
110 HASH_HANDLE *HashCtx;
114 if (mHashInterfaceCount == 0) {
115 return EFI_UNSUPPORTED;
120 HashCtx = (HASH_HANDLE *)HashHandle;
122 for (Index = 0; Index < mHashInterfaceCount; Index++) {
124 if ((HashMask &
PcdGet32 (PcdTpm2HashMask)) != 0) {
125 mHashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen);
146 TPMI_RH_NV_INDEX NvIndex,
152 TPMI_RH_NV_AUTH AuthHandle;
155 AuthHandle = TPM_RH_PLATFORM;
156 ZeroMem (&NvExtendData,
sizeof (NvExtendData));
157 CopyMem (NvExtendData.buffer, Data, DataSize);
158 NvExtendData.size = DataSize;
165 if (EFI_ERROR (Status)) {
167 (DEBUG_ERROR,
"Extend TPM NV index failed, Index: 0x%x Status: %d\n",
189 IN HASH_HANDLE HashHandle,
190 IN TPMI_DH_PCR PcrIndex,
197 HASH_HANDLE *HashCtx;
202 EFI_TCG2_EVENT_ALGORITHM_BITMAP TpmHashAlgorithmBitmap;
203 UINT32 ActivePcrBanks;
205 UINT32 DigestListBinSize;
207 if (mHashInterfaceCount == 0) {
208 return EFI_UNSUPPORTED;
213 HashCtx = (HASH_HANDLE *)HashHandle;
214 ZeroMem (DigestList,
sizeof (*DigestList));
216 for (Index = 0; Index < mHashInterfaceCount; Index++) {
218 if ((HashMask &
PcdGet32 (PcdTpm2HashMask)) != 0) {
219 mHashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen);
220 mHashInterface[Index].HashFinal (HashCtx[Index], &Digest);
227 if (PcrIndex <= MAX_PCR_INDEX) {
235 ActivePcrBanks = ActivePcrBanks & mSupportedHashMaskCurrent;
236 ZeroMem (&TcgPcrEvent2Digest,
sizeof (TcgPcrEvent2Digest));
238 DigestListBinSize = (UINT32)((UINT8 *)BufferPtr - (UINT8 *)&TcgPcrEvent2Digest);
245 (UINT16)DigestListBinSize,
246 (BYTE *)&TcgPcrEvent2Digest
266 IN TPMI_DH_PCR PcrIndex,
272 HASH_HANDLE HashHandle;
275 if (mHashInterfaceCount == 0) {
276 return EFI_UNSUPPORTED;
282 HashUpdate (HashHandle, DataToHash, DataToHashLen);
312 Tpm2HashMask =
PcdGet32 (PcdTpm2HashMask);
314 if ((Tpm2HashMask != 0) &&
315 ((HashMask & Tpm2HashMask) == 0))
317 return EFI_UNSUPPORTED;
320 if (mHashInterfaceCount >=
sizeof (mHashInterface)/
sizeof (mHashInterface[0])) {
321 return EFI_OUT_OF_RESOURCES;
327 for (Index = 0; Index < mHashInterfaceCount; Index++) {
328 if (
CompareGuid (&mHashInterface[Index].HashGuid, &HashInterface->HashGuid)) {
329 DEBUG ((DEBUG_ERROR,
"Hash Interface (%g) has been registered\n", &HashInterface->HashGuid));
330 return EFI_ALREADY_STARTED;
337 mSupportedHashMaskCurrent =
PcdGet32 (PcdTcg2HashAlgorithmBitmap) | HashMask;
338 Status =
PcdSet32S (PcdTcg2HashAlgorithmBitmap, mSupportedHashMaskCurrent);
341 CopyMem (&mHashInterface[mHashInterfaceCount], HashInterface,
sizeof (*HashInterface));
342 mHashInterfaceCount++;
368 mSupportedHashMaskLast =
PcdGet32 (PcdTcg2HashAlgorithmBitmap);
373 Status =
PcdSet32S (PcdTcg2HashAlgorithmBitmap, 0);
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINT32 EFIAPI Tpm2GetHashMaskFromAlgo(IN EFI_GUID *HashGuid)
VOID EFIAPI Tpm2SetHashToDigestList(IN OUT TPML_DIGEST_VALUES *DigestList, IN TPML_DIGEST_VALUES *Digest)
EFI_STATUS EFIAPI HashLibBaseCryptoRouterDxeConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI HashStart(OUT HASH_HANDLE *HashHandle)
EFI_STATUS EFIAPI RegisterHashInterfaceLib(IN HASH_INTERFACE *HashInterface)
EFI_STATUS EFIAPI HashUpdate(IN HASH_HANDLE HashHandle, IN VOID *DataToHash, IN UINTN DataToHashLen)
EFI_STATUS EFIAPI HashAndExtend(IN TPMI_DH_PCR PcrIndex, IN VOID *DataToHash, IN UINTN DataToHashLen, OUT TPML_DIGEST_VALUES *DigestList)
VOID CheckSupportedHashMaskMismatch(VOID)
EFI_STATUS EFIAPI Tpm2ExtendNvIndex(TPMI_RH_NV_INDEX NvIndex, UINT16 DataSize, BYTE *Data)
EFI_STATUS EFIAPI HashCompleteAndExtend(IN HASH_HANDLE HashHandle, IN TPMI_DH_PCR PcrIndex, IN VOID *DataToHash, IN UINTN DataToHashLen, OUT TPML_DIGEST_VALUES *DigestList)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet32(TokenName)
#define PcdSet32S(TokenName, Value)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID * CopyDigestListToBuffer(IN OUT VOID *Buffer, IN TPML_DIGEST_VALUES *DigestList, IN UINT32 HashAlgorithmMask)
EFI_STATUS EFIAPI Tpm2GetCapabilitySupportedAndActivePcrs(OUT UINT32 *TpmHashAlgorithmBitmap, OUT UINT32 *ActivePcrBanks)
EFI_STATUS EFIAPI Tpm2NvExtend(IN TPMI_RH_NV_AUTH AuthHandle, IN TPMI_RH_NV_INDEX NvIndex, IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL, IN TPM2B_MAX_BUFFER *InData)
EFI_STATUS EFIAPI Tpm2PcrExtend(IN TPMI_DH_PCR PcrHandle, IN TPML_DIGEST_VALUES *Digests)