]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/Tcg2Dxe/MeasureBootPeCoff.c
SecurityPkg: Apply uncrustify changes
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Dxe / MeasureBootPeCoff.c
index 347c6ab702c6a01a349ce383d3c07de25474dd2e..b6c6faf2d24ba91d60d6a714bbe6068065456b72 100644 (file)
@@ -43,15 +43,15 @@ UINTN  mTcg2DxeImageSize = 0;
 EFI_STATUS\r
 EFIAPI\r
 Tcg2DxeImageRead (\r
 EFI_STATUS\r
 EFIAPI\r
 Tcg2DxeImageRead (\r
-  IN     VOID    *FileHandle,\r
-  IN     UINTN   FileOffset,\r
-  IN OUT UINTN   *ReadSize,\r
-  OUT    VOID    *Buffer\r
+  IN     VOID   *FileHandle,\r
+  IN     UINTN  FileOffset,\r
+  IN OUT UINTN  *ReadSize,\r
+  OUT    VOID   *Buffer\r
   )\r
 {\r
   )\r
 {\r
-  UINTN               EndPosition;\r
+  UINTN  EndPosition;\r
 \r
 \r
-  if (FileHandle == NULL || ReadSize == NULL || Buffer == NULL) {\r
+  if ((FileHandle == NULL) || (ReadSize == NULL) || (Buffer == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -68,7 +68,7 @@ Tcg2DxeImageRead (
     *ReadSize = 0;\r
   }\r
 \r
     *ReadSize = 0;\r
   }\r
 \r
-  CopyMem (Buffer, (UINT8 *)((UINTN) FileHandle + FileOffset), *ReadSize);\r
+  CopyMem (Buffer, (UINT8 *)((UINTN)FileHandle + FileOffset), *ReadSize);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -94,10 +94,10 @@ Tcg2DxeImageRead (
 **/\r
 EFI_STATUS\r
 MeasurePeImageAndExtend (\r
 **/\r
 EFI_STATUS\r
 MeasurePeImageAndExtend (\r
-  IN  UINT32                    PCRIndex,\r
-  IN  EFI_PHYSICAL_ADDRESS      ImageAddress,\r
-  IN  UINTN                     ImageSize,\r
-  OUT TPML_DIGEST_VALUES        *DigestList\r
+  IN  UINT32                PCRIndex,\r
+  IN  EFI_PHYSICAL_ADDRESS  ImageAddress,\r
+  IN  UINTN                 ImageSize,\r
+  OUT TPML_DIGEST_VALUES    *DigestList\r
   )\r
 {\r
   EFI_STATUS                           Status;\r
   )\r
 {\r
   EFI_STATUS                           Status;\r
@@ -125,9 +125,9 @@ MeasurePeImageAndExtend (
   // Check PE/COFF image\r
   //\r
   ZeroMem (&ImageContext, sizeof (ImageContext));\r
   // Check PE/COFF image\r
   //\r
   ZeroMem (&ImageContext, sizeof (ImageContext));\r
-  ImageContext.Handle    = (VOID *) (UINTN) ImageAddress;\r
+  ImageContext.Handle    = (VOID *)(UINTN)ImageAddress;\r
   mTcg2DxeImageSize      = ImageSize;\r
   mTcg2DxeImageSize      = ImageSize;\r
-  ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) Tcg2DxeImageRead;\r
+  ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE)Tcg2DxeImageRead;\r
 \r
   //\r
   // Get information about the image being loaded\r
 \r
   //\r
   // Get information about the image being loaded\r
@@ -141,13 +141,13 @@ MeasurePeImageAndExtend (
     goto Finish;\r
   }\r
 \r
     goto Finish;\r
   }\r
 \r
-  DosHdr = (EFI_IMAGE_DOS_HEADER *) (UINTN) ImageAddress;\r
+  DosHdr             = (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageAddress;\r
   PeCoffHeaderOffset = 0;\r
   if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
     PeCoffHeaderOffset = DosHdr->e_lfanew;\r
   }\r
 \r
   PeCoffHeaderOffset = 0;\r
   if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
     PeCoffHeaderOffset = DosHdr->e_lfanew;\r
   }\r
 \r
-  Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *) (UINTN) ImageAddress + PeCoffHeaderOffset);\r
+  Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *)(UINTN)ImageAddress + PeCoffHeaderOffset);\r
   if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
     Status = EFI_UNSUPPORTED;\r
     goto Finish;\r
   if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
     Status = EFI_UNSUPPORTED;\r
     goto Finish;\r
@@ -179,19 +179,19 @@ MeasurePeImageAndExtend (
   // 3.  Calculate the distance from the base of the image header to the image checksum address.\r
   // 4.  Hash the image header from its base to beginning of the image checksum.\r
   //\r
   // 3.  Calculate the distance from the base of the image header to the image checksum address.\r
   // 4.  Hash the image header from its base to beginning of the image checksum.\r
   //\r
-  HashBase = (UINT8 *) (UINTN) ImageAddress;\r
+  HashBase = (UINT8 *)(UINTN)ImageAddress;\r
   if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
     //\r
     // Use PE32 offset\r
     //\r
     NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
   if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
     //\r
     // Use PE32 offset\r
     //\r
     NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
-    HashSize = (UINTN) (&Hdr.Pe32->OptionalHeader.CheckSum) - (UINTN) HashBase;\r
+    HashSize            = (UINTN)(&Hdr.Pe32->OptionalHeader.CheckSum) - (UINTN)HashBase;\r
   } else {\r
     //\r
     // Use PE32+ offset\r
     //\r
     NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
   } else {\r
     //\r
     // Use PE32+ offset\r
     //\r
     NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
-    HashSize = (UINTN) (&Hdr.Pe32Plus->OptionalHeader.CheckSum) - (UINTN) HashBase;\r
+    HashSize            = (UINTN)(&Hdr.Pe32Plus->OptionalHeader.CheckSum) - (UINTN)HashBase;\r
   }\r
 \r
   Status = HashUpdate (HashHandle, HashBase, HashSize);\r
   }\r
 \r
   Status = HashUpdate (HashHandle, HashBase, HashSize);\r
@@ -211,18 +211,18 @@ MeasurePeImageAndExtend (
       //\r
       // Use PE32 offset.\r
       //\r
       //\r
       // Use PE32 offset.\r
       //\r
-      HashBase = (UINT8 *) &Hdr.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);\r
-      HashSize = Hdr.Pe32->OptionalHeader.SizeOfHeaders - (UINTN) (HashBase - ImageAddress);\r
+      HashBase = (UINT8 *)&Hdr.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);\r
+      HashSize = Hdr.Pe32->OptionalHeader.SizeOfHeaders - (UINTN)(HashBase - ImageAddress);\r
     } else {\r
       //\r
       // Use PE32+ offset.\r
       //\r
     } else {\r
       //\r
       // Use PE32+ offset.\r
       //\r
-      HashBase = (UINT8 *) &Hdr.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);\r
-      HashSize = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - (UINTN) (HashBase - ImageAddress);\r
+      HashBase = (UINT8 *)&Hdr.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);\r
+      HashSize = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - (UINTN)(HashBase - ImageAddress);\r
     }\r
 \r
     if (HashSize != 0) {\r
     }\r
 \r
     if (HashSize != 0) {\r
-      Status  = HashUpdate (HashHandle, HashBase, HashSize);\r
+      Status = HashUpdate (HashHandle, HashBase, HashSize);\r
       if (EFI_ERROR (Status)) {\r
         goto Finish;\r
       }\r
       if (EFI_ERROR (Status)) {\r
         goto Finish;\r
       }\r
@@ -235,18 +235,18 @@ MeasurePeImageAndExtend (
       //\r
       // Use PE32 offset\r
       //\r
       //\r
       // Use PE32 offset\r
       //\r
-      HashBase = (UINT8 *) &Hdr.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);\r
-      HashSize = (UINTN) (&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (UINTN) HashBase;\r
+      HashBase = (UINT8 *)&Hdr.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);\r
+      HashSize = (UINTN)(&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (UINTN)HashBase;\r
     } else {\r
       //\r
       // Use PE32+ offset\r
       //\r
     } else {\r
       //\r
       // Use PE32+ offset\r
       //\r
-      HashBase = (UINT8 *) &Hdr.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);\r
-      HashSize = (UINTN) (&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (UINTN) HashBase;\r
+      HashBase = (UINT8 *)&Hdr.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);\r
+      HashSize = (UINTN)(&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (UINTN)HashBase;\r
     }\r
 \r
     if (HashSize != 0) {\r
     }\r
 \r
     if (HashSize != 0) {\r
-      Status  = HashUpdate (HashHandle, HashBase, HashSize);\r
+      Status = HashUpdate (HashHandle, HashBase, HashSize);\r
       if (EFI_ERROR (Status)) {\r
         goto Finish;\r
       }\r
       if (EFI_ERROR (Status)) {\r
         goto Finish;\r
       }\r
@@ -260,18 +260,18 @@ MeasurePeImageAndExtend (
       //\r
       // Use PE32 offset\r
       //\r
       //\r
       // Use PE32 offset\r
       //\r
-      HashBase = (UINT8 *) &Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];\r
-      HashSize = Hdr.Pe32->OptionalHeader.SizeOfHeaders - (UINTN) (HashBase - ImageAddress);\r
+      HashBase = (UINT8 *)&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];\r
+      HashSize = Hdr.Pe32->OptionalHeader.SizeOfHeaders - (UINTN)(HashBase - ImageAddress);\r
     } else {\r
       //\r
       // Use PE32+ offset\r
       //\r
     } else {\r
       //\r
       // Use PE32+ offset\r
       //\r
-      HashBase = (UINT8 *) &Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];\r
-      HashSize = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - (UINTN) (HashBase - ImageAddress);\r
+      HashBase = (UINT8 *)&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];\r
+      HashSize = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - (UINTN)(HashBase - ImageAddress);\r
     }\r
 \r
     if (HashSize != 0) {\r
     }\r
 \r
     if (HashSize != 0) {\r
-      Status  = HashUpdate (HashHandle, HashBase, HashSize);\r
+      Status = HashUpdate (HashHandle, HashBase, HashSize);\r
       if (EFI_ERROR (Status)) {\r
         goto Finish;\r
       }\r
       if (EFI_ERROR (Status)) {\r
         goto Finish;\r
       }\r
@@ -299,7 +299,7 @@ MeasurePeImageAndExtend (
   //     header indicates how big the table should be. Do not include any\r
   //     IMAGE_SECTION_HEADERs in the table whose 'SizeOfRawData' field is zero.\r
   //\r
   //     header indicates how big the table should be. Do not include any\r
   //     IMAGE_SECTION_HEADERs in the table whose 'SizeOfRawData' field is zero.\r
   //\r
-  SectionHeader = (EFI_IMAGE_SECTION_HEADER *) AllocateZeroPool (sizeof (EFI_IMAGE_SECTION_HEADER) * Hdr.Pe32->FileHeader.NumberOfSections);\r
+  SectionHeader = (EFI_IMAGE_SECTION_HEADER *)AllocateZeroPool (sizeof (EFI_IMAGE_SECTION_HEADER) * Hdr.Pe32->FileHeader.NumberOfSections);\r
   if (SectionHeader == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Finish;\r
   if (SectionHeader == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Finish;\r
@@ -311,20 +311,21 @@ MeasurePeImageAndExtend (
   //      words, sort the section headers according to the disk-file offset of\r
   //      the section.\r
   //\r
   //      words, sort the section headers according to the disk-file offset of\r
   //      the section.\r
   //\r
-  Section = (EFI_IMAGE_SECTION_HEADER *) (\r
-               (UINT8 *) (UINTN) ImageAddress +\r
-               PeCoffHeaderOffset +\r
-               sizeof(UINT32) +\r
-               sizeof(EFI_IMAGE_FILE_HEADER) +\r
-               Hdr.Pe32->FileHeader.SizeOfOptionalHeader\r
-               );\r
+  Section = (EFI_IMAGE_SECTION_HEADER *)(\r
+                                         (UINT8 *)(UINTN)ImageAddress +\r
+                                         PeCoffHeaderOffset +\r
+                                         sizeof (UINT32) +\r
+                                         sizeof (EFI_IMAGE_FILE_HEADER) +\r
+                                         Hdr.Pe32->FileHeader.SizeOfOptionalHeader\r
+                                         );\r
   for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {\r
     Pos = Index;\r
     while ((Pos > 0) && (Section->PointerToRawData < SectionHeader[Pos - 1].PointerToRawData)) {\r
   for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {\r
     Pos = Index;\r
     while ((Pos > 0) && (Section->PointerToRawData < SectionHeader[Pos - 1].PointerToRawData)) {\r
-      CopyMem (&SectionHeader[Pos], &SectionHeader[Pos - 1], sizeof(EFI_IMAGE_SECTION_HEADER));\r
+      CopyMem (&SectionHeader[Pos], &SectionHeader[Pos - 1], sizeof (EFI_IMAGE_SECTION_HEADER));\r
       Pos--;\r
     }\r
       Pos--;\r
     }\r
-    CopyMem (&SectionHeader[Pos], Section, sizeof(EFI_IMAGE_SECTION_HEADER));\r
+\r
+    CopyMem (&SectionHeader[Pos], Section, sizeof (EFI_IMAGE_SECTION_HEADER));\r
     Section += 1;\r
   }\r
 \r
     Section += 1;\r
   }\r
 \r
@@ -336,12 +337,13 @@ MeasurePeImageAndExtend (
   // 15.  Repeat steps 13 and 14 for all the sections in the sorted table.\r
   //\r
   for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {\r
   // 15.  Repeat steps 13 and 14 for all the sections in the sorted table.\r
   //\r
   for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {\r
-    Section  = (EFI_IMAGE_SECTION_HEADER *) &SectionHeader[Index];\r
+    Section = (EFI_IMAGE_SECTION_HEADER *)&SectionHeader[Index];\r
     if (Section->SizeOfRawData == 0) {\r
       continue;\r
     }\r
     if (Section->SizeOfRawData == 0) {\r
       continue;\r
     }\r
-    HashBase = (UINT8 *) (UINTN) ImageAddress + Section->PointerToRawData;\r
-    HashSize = (UINTN) Section->SizeOfRawData;\r
+\r
+    HashBase = (UINT8 *)(UINTN)ImageAddress + Section->PointerToRawData;\r
+    HashSize = (UINTN)Section->SizeOfRawData;\r
 \r
     Status = HashUpdate (HashHandle, HashBase, HashSize);\r
     if (EFI_ERROR (Status)) {\r
 \r
     Status = HashUpdate (HashHandle, HashBase, HashSize);\r
     if (EFI_ERROR (Status)) {\r
@@ -358,7 +360,7 @@ MeasurePeImageAndExtend (
   //             FileSize  -  (CertDirectory->Size)\r
   //\r
   if (ImageSize > SumOfBytesHashed) {\r
   //             FileSize  -  (CertDirectory->Size)\r
   //\r
   if (ImageSize > SumOfBytesHashed) {\r
-    HashBase = (UINT8 *) (UINTN) ImageAddress + SumOfBytesHashed;\r
+    HashBase = (UINT8 *)(UINTN)ImageAddress + SumOfBytesHashed;\r
 \r
     if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) {\r
       CertSize = 0;\r
 \r
     if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) {\r
       CertSize = 0;\r
@@ -377,7 +379,7 @@ MeasurePeImageAndExtend (
     }\r
 \r
     if (ImageSize > CertSize + SumOfBytesHashed) {\r
     }\r
 \r
     if (ImageSize > CertSize + SumOfBytesHashed) {\r
-      HashSize = (UINTN) (ImageSize - CertSize - SumOfBytesHashed);\r
+      HashSize = (UINTN)(ImageSize - CertSize - SumOfBytesHashed);\r
 \r
       Status = HashUpdate (HashHandle, HashBase, HashSize);\r
       if (EFI_ERROR (Status)) {\r
 \r
       Status = HashUpdate (HashHandle, HashBase, HashSize);\r
       if (EFI_ERROR (Status)) {\r