34 for (Index = 0; Index <
ARRAY_SIZE (mHashAlgInfo); ++Index) {
35 if (mHashAlgInfo[Index].HashAlgId == HashAlgId) {
36 return &mHashAlgInfo[Index];
74 ASSERT (PreHashedFvPpi !=
NULL);
76 PreHashedFvPpi->FvBase = (UINT32)(
UINTN)FvBuffer;
77 PreHashedFvPpi->FvLength = (UINT32)FvLength;
78 PreHashedFvPpi->Count = 1;
80 HashInfo = HASH_INFO_PTR (PreHashedFvPpi);
81 HashInfo->HashAlgoId = HashAlgoId;
82 HashInfo->HashSize = HashSize;
83 CopyMem (HASH_VALUE_PTR (HashInfo), HashValue, HashSize);
86 ASSERT (FvInfoPpiDescriptor !=
NULL);
88 FvInfoPpiDescriptor->
Guid = &gEdkiiPeiFirmwareVolumeInfoPrehashedFvPpiGuid;
89 FvInfoPpiDescriptor->
Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
90 FvInfoPpiDescriptor->
Ppi = (VOID *)PreHashedFvPpi;
125 if ((HashInfo ==
NULL) ||
126 (HashInfo->HashSize == 0) ||
127 (HashInfo->HashAlgoId == TPM_ALG_NULL))
129 DEBUG ((DEBUG_INFO,
"Bypass FV hash verification\r\n"));
134 if ((AlgInfo ==
NULL) || (AlgInfo->HashSize != HashInfo->HashSize)) {
137 "Unsupported or wrong hash algorithm: %04X (size=%d)\r\n",
138 HashInfo->HashAlgoId,
141 return EFI_UNSUPPORTED;
144 ASSERT (FvInfo !=
NULL);
145 ASSERT (FvNumber > 0);
151 ASSERT (HashValue !=
NULL);
154 &gEdkiiPeiFirmwareVolumeShadowPpiGuid,
157 (VOID **)&FvShadowPpi
159 if (EFI_ERROR (Status)) {
166 FvHashValue = HashValue;
167 for (FvIndex = 0; FvIndex < FvNumber; ++FvIndex) {
171 if (((FvInfo[FvIndex].Flag & HASHED_FV_FLAG_VERIFIED_BOOT) == 0) &&
172 ((FvInfo[FvIndex].Flag & HASHED_FV_FLAG_MEASURED_BOOT) == 0))
180 if ((FvInfo[FvIndex].Flag & HASHED_FV_FLAG_SKIP_BOOT_MODE (BootMode)) != 0) {
183 "Skip FV[%016lX] for boot mode[%d]\r\n",
184 FvInfo[FvIndex].Base,
192 "Pre-hashed[alg=%04X,size=%d,flag=%016lX] FV: 0x%016lX (%08lX) (Flag=%016lX)\r\n",
193 HashInfo->HashAlgoId,
196 FvInfo[FvIndex].Base,
197 FvInfo[FvIndex].Length,
206 ASSERT (FvBuffer !=
NULL);
208 if (FvShadowPpi !=
NULL) {
209 Status = FvShadowPpi->FirmwareVolumeShadow (
212 (
UINTN)FvInfo[FvIndex].Length
216 if ((FvShadowPpi ==
NULL) || (EFI_ERROR (Status))) {
220 (
UINTN)FvInfo[FvIndex].Length
224 if (!AlgInfo->HashAll (FvBuffer, (
UINTN)FvInfo[FvIndex].Length, FvHashValue)) {
225 Status = EFI_ABORTED;
232 if ((FvInfo[FvIndex].Flag & HASHED_FV_FLAG_MEASURED_BOOT) != 0) {
235 (
UINTN)FvInfo[FvIndex].Length,
236 HashInfo->HashAlgoId,
245 if ((FvInfo[FvIndex].Flag & HASHED_FV_FLAG_VERIFIED_BOOT) != 0) {
246 FvHashValue += AlgInfo->HashSize;
252 FvInfo[FvIndex].Base = (UINT64)(
UINTN)FvBuffer;
258 if ((FvHashValue == HashValue) ||
259 (AlgInfo->HashAll (HashValue, FvHashValue - HashValue, FvHashValue) &&
260 (
CompareMem (HashInfo->Hash, FvHashValue, AlgInfo->HashSize) == 0)))
264 Status = EFI_VOLUME_CORRUPTED;
286 if ((FvInfo->Flag & HASHED_FV_FLAG_REPORT_FV_HOB) != 0) {
294 DEBUG ((DEBUG_INFO,
"Reported FV HOB: %016lX (%08lX)\r\n", FvInfo->Base, FvInfo->Length));
297 if ((FvInfo->Flag & HASHED_FV_FLAG_REPORT_FV_INFO_PPI) != 0) {
304 (VOID *)(
UINTN)FvInfo->Base,
305 (UINT32)FvInfo->Length,
309 DEBUG ((DEBUG_INFO,
"Reported FV PPI: %016lX (%08lX)\r\n", FvInfo->Base, FvInfo->Length));
336 if ((StoredHashFvPpi->HashInfo.HashFlag & FV_HASH_FLAG_BOOT_MODE (BootMode)) != 0) {
337 HashInfo = &StoredHashFvPpi->HashInfo;
373 StoredHashFvPpi =
NULL;
375 &gEdkiiPeiFirmwareVolumeInfoStoredHashFvPpiGuid,
378 (VOID **)&StoredHashFvPpi
380 if (!EFI_ERROR (Status) && (StoredHashFvPpi !=
NULL) && (StoredHashFvPpi->FvNumber > 0)) {
381 HashInfo =
GetHashInfo (StoredHashFvPpi, BootMode);
384 StoredHashFvPpi->FvInfo,
385 StoredHashFvPpi->FvNumber,
388 if (!EFI_ERROR (Status)) {
389 DEBUG ((DEBUG_INFO,
"OBB verification passed (%r)\r\n", Status));
394 for (FvIndex = 0; FvIndex < StoredHashFvPpi->FvNumber; ++FvIndex) {
395 if ((StoredHashFvPpi->FvInfo[FvIndex].Flag
396 & HASHED_FV_FLAG_SKIP_BOOT_MODE (BootMode)) == 0)
404 PcdGet32 (PcdStatusCodeFvVerificationPass)
407 DEBUG ((DEBUG_ERROR,
"ERROR: Failed to verify OBB FVs (%r)\r\n", Status));
411 PcdGet32 (PcdStatusCodeFvVerificationFail),
414 &gEdkiiPeiFirmwareVolumeInfoStoredHashFvPpiGuid,
416 sizeof (*StoredHashFvPpi)
422 DEBUG ((DEBUG_ERROR,
"ERROR: No/invalid StoredHashFvPpi located\r\n"));
425 ASSERT (StoredHashFvPpi !=
NULL && StoredHashFvPpi->FvNumber > 0);
427 Status = EFI_NOT_FOUND;
456 if (EFI_ERROR (Status)) {
VOID EFIAPI BuildFvHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
BOOLEAN EFIAPI Sha512HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Sha512Final(IN OUT VOID *Sha512Context, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Sha512Init(OUT VOID *Sha512Context)
#define SHA512_DIGEST_SIZE
BOOLEAN EFIAPI Sha256Init(OUT VOID *Sha256Context)
BOOLEAN EFIAPI Sha384HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Sha256Final(IN OUT VOID *Sha256Context, OUT UINT8 *HashValue)
#define SHA256_DIGEST_SIZE
BOOLEAN EFIAPI Sha384Update(IN OUT VOID *Sha384Context, IN CONST VOID *Data, IN UINTN DataSize)
BOOLEAN EFIAPI Sha256HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Sha256Update(IN OUT VOID *Sha256Context, IN CONST VOID *Data, IN UINTN DataSize)
BOOLEAN EFIAPI Sha384Final(IN OUT VOID *Sha384Context, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Sha384Init(OUT VOID *Sha384Context)
BOOLEAN EFIAPI Sha512Update(IN OUT VOID *Sha512Context, IN CONST VOID *Data, IN UINTN DataSize)
#define SHA384_DIGEST_SIZE
VOID EFIAPI CpuDeadLoop(VOID)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI PeiServicesGetBootMode(OUT EFI_BOOT_MODE *BootMode)
VOID EFIAPI PeiServicesInstallFvInfoPpi(IN CONST EFI_GUID *FvFormat OPTIONAL, IN CONST VOID *FvInfo, IN UINT32 FvInfoSize, IN CONST EFI_GUID *ParentFvName OPTIONAL, IN CONST EFI_GUID *ParentFileName OPTIONAL)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
STATIC EFI_STATUS CheckStoredHashFv(IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_BOOT_MODE BootMode)
EFI_STATUS EFIAPI FvReportEntryPoint(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
STATIC VOID ReportHashedFv(IN HASHED_FV_INFO *FvInfo)
STATIC EFI_STATUS VerifyHashedFv(IN FV_HASH_INFO *HashInfo, IN HASHED_FV_INFO *FvInfo, IN UINTN FvNumber, IN EFI_BOOT_MODE BootMode)
STATIC CONST HASH_ALG_INFO * FindHashAlgInfo(IN UINT16 HashAlgId)
STATIC FV_HASH_INFO * GetHashInfo(IN EDKII_PEI_FIRMWARE_VOLUME_INFO_STORED_HASH_FV_PPI *StoredHashFvPpi, IN EFI_BOOT_MODE BootMode)
STATIC VOID InstallPreHashFvPpi(IN VOID *FvBuffer, IN UINTN FvLength, IN UINT16 HashAlgoId, IN UINT16 HashSize, IN UINT8 *HashValue)
#define ARRAY_SIZE(Array)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define REPORT_STATUS_CODE_EX(Type, Value, Instance, CallerId, ExtendedDataGuid, ExtendedData, ExtendedDataSize)
#define REPORT_STATUS_CODE(Type, Value)
#define PcdGet32(TokenName)
VOID * EFI_PEI_FILE_HANDLE
#define EFI_PROGRESS_CODE
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_SIZE_TO_PAGES(Size)