24#define HASH_LIB_PEI_ROUTER_GUID \
25 { 0x84681c08, 0x6873, 0x46f3, { 0x8b, 0xb7, 0xab, 0x66, 0x18, 0x95, 0xa1, 0xb3 } }
27EFI_GUID mHashLibPeiRouterGuid = HASH_LIB_PEI_ROUTER_GUID;
38 UINTN HashInterfaceCount;
40 UINT32 SupportedHashMask;
59 while (Hob.Raw !=
NULL) {
60 HashInterfaceHob = GET_GUID_HOB_DATA (Hob);
61 if (
CompareGuid (&HashInterfaceHob->Identifier, Identifier)) {
65 return HashInterfaceHob;
68 Hob.Raw = GET_NEXT_HOB (Hob);
89 ZeroMem (&LocalHashInterfaceHob,
sizeof (LocalHashInterfaceHob));
90 CopyGuid (&LocalHashInterfaceHob.Identifier, Identifier);
91 return BuildGuidDataHob (&mHashLibPeiRouterGuid, &LocalHashInterfaceHob,
sizeof (LocalHashInterfaceHob));
109 ASSERT (HashInterfaceHobLast !=
NULL);
111 if ((HashInterfaceHobLast->SupportedHashMask != 0) &&
112 (HashInterfaceHobCurrent->SupportedHashMask != HashInterfaceHobLast->SupportedHashMask))
116 "WARNING: There is mismatch of supported HashMask (0x%x - 0x%x) between modules\n",
117 HashInterfaceHobCurrent->SupportedHashMask,
118 HashInterfaceHobLast->SupportedHashMask
120 DEBUG ((DEBUG_WARN,
"that are linking different HashInstanceLib instances!\n"));
135 OUT HASH_HANDLE *HashHandle
139 HASH_HANDLE *HashCtx;
144 if (HashInterfaceHob ==
NULL) {
145 return EFI_UNSUPPORTED;
148 if (HashInterfaceHob->HashInterfaceCount == 0) {
149 return EFI_UNSUPPORTED;
154 HashCtx =
AllocatePool (
sizeof (*HashCtx) * HashInterfaceHob->HashInterfaceCount);
155 ASSERT (HashCtx !=
NULL);
157 for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {
159 if ((HashMask &
PcdGet32 (PcdTpm2HashMask)) != 0) {
160 HashInterfaceHob->HashInterface[Index].HashInit (&HashCtx[Index]);
164 *HashHandle = (HASH_HANDLE)HashCtx;
181 IN HASH_HANDLE HashHandle,
187 HASH_HANDLE *HashCtx;
192 if (HashInterfaceHob ==
NULL) {
193 return EFI_UNSUPPORTED;
196 if (HashInterfaceHob->HashInterfaceCount == 0) {
197 return EFI_UNSUPPORTED;
202 HashCtx = (HASH_HANDLE *)HashHandle;
204 for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {
206 if ((HashMask &
PcdGet32 (PcdTpm2HashMask)) != 0) {
207 HashInterfaceHob->HashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen);
228 IN HASH_HANDLE HashHandle,
229 IN TPMI_DH_PCR PcrIndex,
237 HASH_HANDLE *HashCtx;
243 if (HashInterfaceHob ==
NULL) {
244 return EFI_UNSUPPORTED;
247 if (HashInterfaceHob->HashInterfaceCount == 0) {
248 return EFI_UNSUPPORTED;
253 HashCtx = (HASH_HANDLE *)HashHandle;
254 ZeroMem (DigestList,
sizeof (*DigestList));
256 for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {
258 if ((HashMask &
PcdGet32 (PcdTpm2HashMask)) != 0) {
259 HashInterfaceHob->HashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen);
260 HashInterfaceHob->HashInterface[Index].HashFinal (HashCtx[Index], &Digest);
287 IN TPMI_DH_PCR PcrIndex,
294 HASH_HANDLE HashHandle;
298 if (HashInterfaceHob ==
NULL) {
299 return EFI_UNSUPPORTED;
302 if (HashInterfaceHob->HashInterfaceCount == 0) {
303 return EFI_UNSUPPORTED;
309 HashUpdate (HashHandle, DataToHash, DataToHashLen);
340 Tpm2HashMask =
PcdGet32 (PcdTpm2HashMask);
342 if ((Tpm2HashMask != 0) &&
343 ((HashMask & Tpm2HashMask) == 0))
345 return EFI_UNSUPPORTED;
349 if (HashInterfaceHob ==
NULL) {
351 if (HashInterfaceHob ==
NULL) {
352 return EFI_OUT_OF_RESOURCES;
356 if (HashInterfaceHob->HashInterfaceCount >= HASH_COUNT) {
357 return EFI_OUT_OF_RESOURCES;
363 for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {
364 if (
CompareGuid (&HashInterfaceHob->HashInterface[Index].HashGuid, &HashInterface->HashGuid)) {
365 DEBUG ((DEBUG_ERROR,
"Hash Interface (%g) has been registered\n", &HashInterface->HashGuid));
366 return EFI_ALREADY_STARTED;
373 HashInterfaceHob->SupportedHashMask =
PcdGet32 (PcdTcg2HashAlgorithmBitmap) | HashMask;
374 Status =
PcdSet32S (PcdTcg2HashAlgorithmBitmap, HashInterfaceHob->SupportedHashMask);
377 CopyMem (&HashInterfaceHob->HashInterface[HashInterfaceHob->HashInterfaceCount], HashInterface, sizeof (*HashInterface));
378 HashInterfaceHob->HashInterfaceCount++;
404 if (HashInterfaceHob ==
NULL) {
411 if (HashInterfaceHob ==
NULL) {
412 return EFI_OUT_OF_RESOURCES;
418 HashInterfaceHob->SupportedHashMask =
PcdGet32 (PcdTcg2HashAlgorithmBitmap);
422 if (HashInterfaceHob !=
NULL) {
429 ZeroMem (&HashInterfaceHob->HashInterface, sizeof (HashInterfaceHob->HashInterface));
430 HashInterfaceHob->HashInterfaceCount = 0;
431 HashInterfaceHob->SupportedHashMask = 0;
437 Status =
PcdSet32S (PcdTcg2HashAlgorithmBitmap, 0);
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
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)
HASH_INTERFACE_HOB * InternalCreateHashInterfaceHob(EFI_GUID *Identifier)
EFI_STATUS EFIAPI HashStart(OUT HASH_HANDLE *HashHandle)
VOID CheckSupportedHashMaskMismatch(IN HASH_INTERFACE_HOB *HashInterfaceHobCurrent)
EFI_STATUS EFIAPI RegisterHashInterfaceLib(IN HASH_INTERFACE *HashInterface)
HASH_INTERFACE_HOB * InternalGetHashInterfaceHob(EFI_GUID *Identifier)
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)
EFI_STATUS EFIAPI HashLibBaseCryptoRouterPeiConstructor(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
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 * EFI_PEI_FILE_HANDLE
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI Tpm2PcrExtend(IN TPMI_DH_PCR PcrHandle, IN TPML_DIGEST_VALUES *Digests)