]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2CommandLib/Tpm2Integrity.c
SecurityPkg: Apply uncrustify changes
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Integrity.c
index d232fe725daac4cc849486da145d78d8e7516a7f..8dde5f34a27338fa6245f09d4f7799a237c5f4a3 100644 (file)
@@ -16,62 +16,62 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #pragma pack(1)\r
 \r
 typedef struct {\r
-  TPM2_COMMAND_HEADER       Header;\r
-  TPMI_DH_PCR               PcrHandle;\r
-  UINT32                    AuthorizationSize;\r
-  TPMS_AUTH_COMMAND         AuthSessionPcr;\r
-  TPML_DIGEST_VALUES        DigestValues;\r
+  TPM2_COMMAND_HEADER    Header;\r
+  TPMI_DH_PCR            PcrHandle;\r
+  UINT32                 AuthorizationSize;\r
+  TPMS_AUTH_COMMAND      AuthSessionPcr;\r
+  TPML_DIGEST_VALUES     DigestValues;\r
 } TPM2_PCR_EXTEND_COMMAND;\r
 \r
 typedef struct {\r
-  TPM2_RESPONSE_HEADER       Header;\r
-  UINT32                     ParameterSize;\r
-  TPMS_AUTH_RESPONSE         AuthSessionPcr;\r
+  TPM2_RESPONSE_HEADER    Header;\r
+  UINT32                  ParameterSize;\r
+  TPMS_AUTH_RESPONSE      AuthSessionPcr;\r
 } TPM2_PCR_EXTEND_RESPONSE;\r
 \r
 typedef struct {\r
-  TPM2_COMMAND_HEADER       Header;\r
-  TPMI_DH_PCR               PcrHandle;\r
-  UINT32                    AuthorizationSize;\r
-  TPMS_AUTH_COMMAND         AuthSessionPcr;\r
-  TPM2B_EVENT               EventData;\r
+  TPM2_COMMAND_HEADER    Header;\r
+  TPMI_DH_PCR            PcrHandle;\r
+  UINT32                 AuthorizationSize;\r
+  TPMS_AUTH_COMMAND      AuthSessionPcr;\r
+  TPM2B_EVENT            EventData;\r
 } TPM2_PCR_EVENT_COMMAND;\r
 \r
 typedef struct {\r
-  TPM2_RESPONSE_HEADER       Header;\r
-  UINT32                     ParameterSize;\r
-  TPML_DIGEST_VALUES         Digests;\r
-  TPMS_AUTH_RESPONSE         AuthSessionPcr;\r
+  TPM2_RESPONSE_HEADER    Header;\r
+  UINT32                  ParameterSize;\r
+  TPML_DIGEST_VALUES      Digests;\r
+  TPMS_AUTH_RESPONSE      AuthSessionPcr;\r
 } TPM2_PCR_EVENT_RESPONSE;\r
 \r
 typedef struct {\r
-  TPM2_COMMAND_HEADER       Header;\r
-  TPML_PCR_SELECTION        PcrSelectionIn;\r
+  TPM2_COMMAND_HEADER    Header;\r
+  TPML_PCR_SELECTION     PcrSelectionIn;\r
 } TPM2_PCR_READ_COMMAND;\r
 \r
 typedef struct {\r
-  TPM2_RESPONSE_HEADER      Header;\r
-  UINT32                    PcrUpdateCounter;\r
-  TPML_PCR_SELECTION        PcrSelectionOut;\r
-  TPML_DIGEST               PcrValues;\r
+  TPM2_RESPONSE_HEADER    Header;\r
+  UINT32                  PcrUpdateCounter;\r
+  TPML_PCR_SELECTION      PcrSelectionOut;\r
+  TPML_DIGEST             PcrValues;\r
 } TPM2_PCR_READ_RESPONSE;\r
 \r
 typedef struct {\r
-  TPM2_COMMAND_HEADER       Header;\r
-  TPMI_RH_PLATFORM          AuthHandle;\r
-  UINT32                    AuthSessionSize;\r
-  TPMS_AUTH_COMMAND         AuthSession;\r
-  TPML_PCR_SELECTION        PcrAllocation;\r
+  TPM2_COMMAND_HEADER    Header;\r
+  TPMI_RH_PLATFORM       AuthHandle;\r
+  UINT32                 AuthSessionSize;\r
+  TPMS_AUTH_COMMAND      AuthSession;\r
+  TPML_PCR_SELECTION     PcrAllocation;\r
 } TPM2_PCR_ALLOCATE_COMMAND;\r
 \r
 typedef struct {\r
-  TPM2_RESPONSE_HEADER       Header;\r
-  UINT32                     AuthSessionSize;\r
-  TPMI_YES_NO                AllocationSuccess;\r
-  UINT32                     MaxPCR;\r
-  UINT32                     SizeNeeded;\r
-  UINT32                     SizeAvailable;\r
-  TPMS_AUTH_RESPONSE         AuthSession;\r
+  TPM2_RESPONSE_HEADER    Header;\r
+  UINT32                  AuthSessionSize;\r
+  TPMI_YES_NO             AllocationSuccess;\r
+  UINT32                  MaxPCR;\r
+  UINT32                  SizeNeeded;\r
+  UINT32                  SizeAvailable;\r
+  TPMS_AUTH_RESPONSE      AuthSession;\r
 } TPM2_PCR_ALLOCATE_RESPONSE;\r
 \r
 #pragma pack()\r
@@ -90,25 +90,24 @@ typedef struct {
 EFI_STATUS\r
 EFIAPI\r
 Tpm2PcrExtend (\r
-  IN      TPMI_DH_PCR               PcrHandle,\r
-  IN      TPML_DIGEST_VALUES        *Digests\r
+  IN      TPMI_DH_PCR         PcrHandle,\r
+  IN      TPML_DIGEST_VALUES  *Digests\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
-  TPM2_PCR_EXTEND_COMMAND           Cmd;\r
-  TPM2_PCR_EXTEND_RESPONSE          Res;\r
-  UINT32                            CmdSize;\r
-  UINT32                            RespSize;\r
-  UINT32                            ResultBufSize;\r
-  UINT8                             *Buffer;\r
-  UINTN                             Index;\r
-  UINT32                            SessionInfoSize;\r
-  UINT16                            DigestSize;\r
-\r
-  Cmd.Header.tag         = SwapBytes16(TPM_ST_SESSIONS);\r
-  Cmd.Header.commandCode = SwapBytes32(TPM_CC_PCR_Extend);\r
-  Cmd.PcrHandle          = SwapBytes32(PcrHandle);\r
+  EFI_STATUS                Status;\r
+  TPM2_PCR_EXTEND_COMMAND   Cmd;\r
+  TPM2_PCR_EXTEND_RESPONSE  Res;\r
+  UINT32                    CmdSize;\r
+  UINT32                    RespSize;\r
+  UINT32                    ResultBufSize;\r
+  UINT8                     *Buffer;\r
+  UINTN                     Index;\r
+  UINT32                    SessionInfoSize;\r
+  UINT16                    DigestSize;\r
 \r
+  Cmd.Header.tag         = SwapBytes16 (TPM_ST_SESSIONS);\r
+  Cmd.Header.commandCode = SwapBytes32 (TPM_CC_PCR_Extend);\r
+  Cmd.PcrHandle          = SwapBytes32 (PcrHandle);\r
 \r
   //\r
   // Add in Auth session\r
@@ -116,24 +115,25 @@ Tpm2PcrExtend (
   Buffer = (UINT8 *)&Cmd.AuthSessionPcr;\r
 \r
   // sessionInfoSize\r
-  SessionInfoSize = CopyAuthSessionCommand (NULL, Buffer);\r
-  Buffer += SessionInfoSize;\r
-  Cmd.AuthorizationSize = SwapBytes32(SessionInfoSize);\r
+  SessionInfoSize       = CopyAuthSessionCommand (NULL, Buffer);\r
+  Buffer               += SessionInfoSize;\r
+  Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize);\r
 \r
-  //Digest Count\r
-  WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32(Digests->count));\r
-  Buffer += sizeof(UINT32);\r
+  // Digest Count\r
+  WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (Digests->count));\r
+  Buffer += sizeof (UINT32);\r
 \r
-  //Digest\r
+  // Digest\r
   for (Index = 0; Index < Digests->count; Index++) {\r
-    WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16(Digests->digests[Index].hashAlg));\r
-    Buffer += sizeof(UINT16);\r
+    WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Digests->digests[Index].hashAlg));\r
+    Buffer    += sizeof (UINT16);\r
     DigestSize = GetHashSizeFromAlgo (Digests->digests[Index].hashAlg);\r
     if (DigestSize == 0) {\r
       DEBUG ((DEBUG_ERROR, "Unknown hash algorithm %d\r\n", Digests->digests[Index].hashAlg));\r
       return EFI_DEVICE_ERROR;\r
     }\r
-    CopyMem(\r
+\r
+    CopyMem (\r
       Buffer,\r
       &Digests->digests[Index].digest,\r
       DigestSize\r
@@ -142,15 +142,15 @@ Tpm2PcrExtend (
   }\r
 \r
   CmdSize              = (UINT32)((UINTN)Buffer - (UINTN)&Cmd);\r
-  Cmd.Header.paramSize = SwapBytes32(CmdSize);\r
+  Cmd.Header.paramSize = SwapBytes32 (CmdSize);\r
 \r
-  ResultBufSize = sizeof(Res);\r
-  Status = Tpm2SubmitCommand (CmdSize, (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
-  if (EFI_ERROR(Status)) {\r
+  ResultBufSize = sizeof (Res);\r
+  Status        = Tpm2SubmitCommand (CmdSize, (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
+  if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  if (ResultBufSize > sizeof(Res)) {\r
+  if (ResultBufSize > sizeof (Res)) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrExtend: Failed ExecuteCommand: Buffer Too Small\r\n"));\r
     return EFI_BUFFER_TOO_SMALL;\r
   }\r
@@ -158,8 +158,8 @@ Tpm2PcrExtend (
   //\r
   // Validate response headers\r
   //\r
-  RespSize = SwapBytes32(Res.Header.paramSize);\r
-  if (RespSize > sizeof(Res)) {\r
+  RespSize = SwapBytes32 (Res.Header.paramSize);\r
+  if (RespSize > sizeof (Res)) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrExtend: Response size too large! %d\r\n", RespSize));\r
     return EFI_BUFFER_TOO_SMALL;\r
   }\r
@@ -167,8 +167,8 @@ Tpm2PcrExtend (
   //\r
   // Fail if command failed\r
   //\r
-  if (SwapBytes32(Res.Header.responseCode) != TPM_RC_SUCCESS) {\r
-    DEBUG ((DEBUG_ERROR, "Tpm2PcrExtend: Response Code error! 0x%08x\r\n", SwapBytes32(Res.Header.responseCode)));\r
+  if (SwapBytes32 (Res.Header.responseCode) != TPM_RC_SUCCESS) {\r
+    DEBUG ((DEBUG_ERROR, "Tpm2PcrExtend: Response Code error! 0x%08x\r\n", SwapBytes32 (Res.Header.responseCode)));\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
@@ -199,25 +199,25 @@ Tpm2PcrExtend (
 EFI_STATUS\r
 EFIAPI\r
 Tpm2PcrEvent (\r
-  IN      TPMI_DH_PCR               PcrHandle,\r
-  IN      TPM2B_EVENT               *EventData,\r
-     OUT  TPML_DIGEST_VALUES        *Digests\r
+  IN      TPMI_DH_PCR      PcrHandle,\r
+  IN      TPM2B_EVENT      *EventData,\r
+  OUT  TPML_DIGEST_VALUES  *Digests\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
-  TPM2_PCR_EVENT_COMMAND            Cmd;\r
-  TPM2_PCR_EVENT_RESPONSE           Res;\r
-  UINT32                            CmdSize;\r
-  UINT32                            RespSize;\r
-  UINT32                            ResultBufSize;\r
-  UINT8                             *Buffer;\r
-  UINTN                             Index;\r
-  UINT32                            SessionInfoSize;\r
-  UINT16                            DigestSize;\r
-\r
-  Cmd.Header.tag         = SwapBytes16(TPM_ST_SESSIONS);\r
-  Cmd.Header.commandCode = SwapBytes32(TPM_CC_PCR_Event);\r
-  Cmd.PcrHandle          = SwapBytes32(PcrHandle);\r
+  EFI_STATUS               Status;\r
+  TPM2_PCR_EVENT_COMMAND   Cmd;\r
+  TPM2_PCR_EVENT_RESPONSE  Res;\r
+  UINT32                   CmdSize;\r
+  UINT32                   RespSize;\r
+  UINT32                   ResultBufSize;\r
+  UINT8                    *Buffer;\r
+  UINTN                    Index;\r
+  UINT32                   SessionInfoSize;\r
+  UINT16                   DigestSize;\r
+\r
+  Cmd.Header.tag         = SwapBytes16 (TPM_ST_SESSIONS);\r
+  Cmd.Header.commandCode = SwapBytes32 (TPM_CC_PCR_Event);\r
+  Cmd.PcrHandle          = SwapBytes32 (PcrHandle);\r
 \r
   //\r
   // Add in Auth session\r
@@ -225,27 +225,27 @@ Tpm2PcrEvent (
   Buffer = (UINT8 *)&Cmd.AuthSessionPcr;\r
 \r
   // sessionInfoSize\r
-  SessionInfoSize = CopyAuthSessionCommand (NULL, Buffer);\r
-  Buffer += SessionInfoSize;\r
-  Cmd.AuthorizationSize = SwapBytes32(SessionInfoSize);\r
+  SessionInfoSize       = CopyAuthSessionCommand (NULL, Buffer);\r
+  Buffer               += SessionInfoSize;\r
+  Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize);\r
 \r
   // Event\r
-  WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16(EventData->size));\r
-  Buffer += sizeof(UINT16);\r
+  WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (EventData->size));\r
+  Buffer += sizeof (UINT16);\r
 \r
   CopyMem (Buffer, EventData->buffer, EventData->size);\r
   Buffer += EventData->size;\r
 \r
   CmdSize              = (UINT32)((UINTN)Buffer - (UINTN)&Cmd);\r
-  Cmd.Header.paramSize = SwapBytes32(CmdSize);\r
+  Cmd.Header.paramSize = SwapBytes32 (CmdSize);\r
 \r
-  ResultBufSize = sizeof(Res);\r
-  Status = Tpm2SubmitCommand (CmdSize, (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
-  if (EFI_ERROR(Status)) {\r
+  ResultBufSize = sizeof (Res);\r
+  Status        = Tpm2SubmitCommand (CmdSize, (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
+  if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  if (ResultBufSize > sizeof(Res)) {\r
+  if (ResultBufSize > sizeof (Res)) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrEvent: Failed ExecuteCommand: Buffer Too Small\r\n"));\r
     return EFI_BUFFER_TOO_SMALL;\r
   }\r
@@ -253,8 +253,8 @@ Tpm2PcrEvent (
   //\r
   // Validate response headers\r
   //\r
-  RespSize = SwapBytes32(Res.Header.paramSize);\r
-  if (RespSize > sizeof(Res)) {\r
+  RespSize = SwapBytes32 (Res.Header.paramSize);\r
+  if (RespSize > sizeof (Res)) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrEvent: Response size too large! %d\r\n", RespSize));\r
     return EFI_BUFFER_TOO_SMALL;\r
   }\r
@@ -262,8 +262,8 @@ Tpm2PcrEvent (
   //\r
   // Fail if command failed\r
   //\r
-  if (SwapBytes32(Res.Header.responseCode) != TPM_RC_SUCCESS) {\r
-    DEBUG ((DEBUG_ERROR, "Tpm2PcrEvent: Response Code error! 0x%08x\r\n", SwapBytes32(Res.Header.responseCode)));\r
+  if (SwapBytes32 (Res.Header.responseCode) != TPM_RC_SUCCESS) {\r
+    DEBUG ((DEBUG_ERROR, "Tpm2PcrEvent: Response Code error! 0x%08x\r\n", SwapBytes32 (Res.Header.responseCode)));\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
@@ -278,16 +278,17 @@ Tpm2PcrEvent (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  Buffer += sizeof(UINT32);\r
+  Buffer += sizeof (UINT32);\r
   for (Index = 0; Index < Digests->count; Index++) {\r
     Digests->digests[Index].hashAlg = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
-    Buffer += sizeof(UINT16);\r
-    DigestSize = GetHashSizeFromAlgo (Digests->digests[Index].hashAlg);\r
+    Buffer                         += sizeof (UINT16);\r
+    DigestSize                      = GetHashSizeFromAlgo (Digests->digests[Index].hashAlg);\r
     if (DigestSize == 0) {\r
       DEBUG ((DEBUG_ERROR, "Unknown hash algorithm %d\r\n", Digests->digests[Index].hashAlg));\r
       return EFI_DEVICE_ERROR;\r
     }\r
-    CopyMem(\r
+\r
+    CopyMem (\r
       &Digests->digests[Index].digest,\r
       Buffer,\r
       DigestSize\r
@@ -312,42 +313,42 @@ Tpm2PcrEvent (
 EFI_STATUS\r
 EFIAPI\r
 Tpm2PcrRead (\r
-  IN      TPML_PCR_SELECTION        *PcrSelectionIn,\r
-     OUT  UINT32                    *PcrUpdateCounter,\r
-     OUT  TPML_PCR_SELECTION        *PcrSelectionOut,\r
-     OUT  TPML_DIGEST               *PcrValues\r
+  IN      TPML_PCR_SELECTION  *PcrSelectionIn,\r
+  OUT  UINT32                 *PcrUpdateCounter,\r
+  OUT  TPML_PCR_SELECTION     *PcrSelectionOut,\r
+  OUT  TPML_DIGEST            *PcrValues\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
-  TPM2_PCR_READ_COMMAND             SendBuffer;\r
-  TPM2_PCR_READ_RESPONSE            RecvBuffer;\r
-  UINT32                            SendBufferSize;\r
-  UINT32                            RecvBufferSize;\r
-  UINTN                             Index;\r
-  TPML_DIGEST                       *PcrValuesOut;\r
-  TPM2B_DIGEST                      *Digests;\r
+  EFI_STATUS              Status;\r
+  TPM2_PCR_READ_COMMAND   SendBuffer;\r
+  TPM2_PCR_READ_RESPONSE  RecvBuffer;\r
+  UINT32                  SendBufferSize;\r
+  UINT32                  RecvBufferSize;\r
+  UINTN                   Index;\r
+  TPML_DIGEST             *PcrValuesOut;\r
+  TPM2B_DIGEST            *Digests;\r
 \r
   //\r
   // Construct command\r
   //\r
-  SendBuffer.Header.tag = SwapBytes16(TPM_ST_NO_SESSIONS);\r
-  SendBuffer.Header.commandCode = SwapBytes32(TPM_CC_PCR_Read);\r
+  SendBuffer.Header.tag         = SwapBytes16 (TPM_ST_NO_SESSIONS);\r
+  SendBuffer.Header.commandCode = SwapBytes32 (TPM_CC_PCR_Read);\r
 \r
-  SendBuffer.PcrSelectionIn.count = SwapBytes32(PcrSelectionIn->count);\r
+  SendBuffer.PcrSelectionIn.count = SwapBytes32 (PcrSelectionIn->count);\r
   for (Index = 0; Index < PcrSelectionIn->count; Index++) {\r
-    SendBuffer.PcrSelectionIn.pcrSelections[Index].hash = SwapBytes16(PcrSelectionIn->pcrSelections[Index].hash);\r
+    SendBuffer.PcrSelectionIn.pcrSelections[Index].hash         = SwapBytes16 (PcrSelectionIn->pcrSelections[Index].hash);\r
     SendBuffer.PcrSelectionIn.pcrSelections[Index].sizeofSelect = PcrSelectionIn->pcrSelections[Index].sizeofSelect;\r
     CopyMem (&SendBuffer.PcrSelectionIn.pcrSelections[Index].pcrSelect, &PcrSelectionIn->pcrSelections[Index].pcrSelect, SendBuffer.PcrSelectionIn.pcrSelections[Index].sizeofSelect);\r
   }\r
 \r
-  SendBufferSize = sizeof(SendBuffer.Header) + sizeof(SendBuffer.PcrSelectionIn.count) + sizeof(SendBuffer.PcrSelectionIn.pcrSelections[0]) * PcrSelectionIn->count;\r
+  SendBufferSize              = sizeof (SendBuffer.Header) + sizeof (SendBuffer.PcrSelectionIn.count) + sizeof (SendBuffer.PcrSelectionIn.pcrSelections[0]) * PcrSelectionIn->count;\r
   SendBuffer.Header.paramSize = SwapBytes32 (SendBufferSize);\r
 \r
   //\r
   // send Tpm command\r
   //\r
   RecvBufferSize = sizeof (RecvBuffer);\r
-  Status = Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);\r
+  Status         = Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -356,8 +357,9 @@ Tpm2PcrRead (
     DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - RecvBufferSize Error - %x\n", RecvBufferSize));\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  if (SwapBytes32(RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {\r
-    DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - responseCode - %x\n", SwapBytes32(RecvBuffer.Header.responseCode)));\r
+\r
+  if (SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {\r
+    DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - responseCode - %x\n", SwapBytes32 (RecvBuffer.Header.responseCode)));\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -368,43 +370,47 @@ Tpm2PcrRead (
   //\r
   // PcrUpdateCounter\r
   //\r
-  if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER) + sizeof(RecvBuffer.PcrUpdateCounter)) {\r
+  if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER) + sizeof (RecvBuffer.PcrUpdateCounter)) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - RecvBufferSize Error - %x\n", RecvBufferSize));\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  *PcrUpdateCounter = SwapBytes32(RecvBuffer.PcrUpdateCounter);\r
+\r
+  *PcrUpdateCounter = SwapBytes32 (RecvBuffer.PcrUpdateCounter);\r
 \r
   //\r
   // PcrSelectionOut\r
   //\r
-  if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER) + sizeof(RecvBuffer.PcrUpdateCounter) + sizeof(RecvBuffer.PcrSelectionOut.count)) {\r
+  if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER) + sizeof (RecvBuffer.PcrUpdateCounter) + sizeof (RecvBuffer.PcrSelectionOut.count)) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - RecvBufferSize Error - %x\n", RecvBufferSize));\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  PcrSelectionOut->count = SwapBytes32(RecvBuffer.PcrSelectionOut.count);\r
+\r
+  PcrSelectionOut->count = SwapBytes32 (RecvBuffer.PcrSelectionOut.count);\r
   if (PcrSelectionOut->count > HASH_COUNT) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - PcrSelectionOut->count error %x\n", PcrSelectionOut->count));\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER) + sizeof(RecvBuffer.PcrUpdateCounter) + sizeof(RecvBuffer.PcrSelectionOut.count) + sizeof(RecvBuffer.PcrSelectionOut.pcrSelections[0]) * PcrSelectionOut->count) {\r
+  if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER) + sizeof (RecvBuffer.PcrUpdateCounter) + sizeof (RecvBuffer.PcrSelectionOut.count) + sizeof (RecvBuffer.PcrSelectionOut.pcrSelections[0]) * PcrSelectionOut->count) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - RecvBufferSize Error - %x\n", RecvBufferSize));\r
     return EFI_DEVICE_ERROR;\r
   }\r
+\r
   for (Index = 0; Index < PcrSelectionOut->count; Index++) {\r
-    PcrSelectionOut->pcrSelections[Index].hash = SwapBytes16(RecvBuffer.PcrSelectionOut.pcrSelections[Index].hash);\r
+    PcrSelectionOut->pcrSelections[Index].hash         = SwapBytes16 (RecvBuffer.PcrSelectionOut.pcrSelections[Index].hash);\r
     PcrSelectionOut->pcrSelections[Index].sizeofSelect = RecvBuffer.PcrSelectionOut.pcrSelections[Index].sizeofSelect;\r
     if (PcrSelectionOut->pcrSelections[Index].sizeofSelect > PCR_SELECT_MAX) {\r
       return EFI_DEVICE_ERROR;\r
     }\r
+\r
     CopyMem (&PcrSelectionOut->pcrSelections[Index].pcrSelect, &RecvBuffer.PcrSelectionOut.pcrSelections[Index].pcrSelect, PcrSelectionOut->pcrSelections[Index].sizeofSelect);\r
   }\r
 \r
   //\r
   // PcrValues\r
   //\r
-  PcrValuesOut = (TPML_DIGEST *)((UINT8 *)&RecvBuffer + sizeof (TPM2_RESPONSE_HEADER) + sizeof(RecvBuffer.PcrUpdateCounter) + sizeof(RecvBuffer.PcrSelectionOut.count) + sizeof(RecvBuffer.PcrSelectionOut.pcrSelections[0]) * PcrSelectionOut->count);\r
-  PcrValues->count = SwapBytes32(PcrValuesOut->count);\r
+  PcrValuesOut     = (TPML_DIGEST *)((UINT8 *)&RecvBuffer + sizeof (TPM2_RESPONSE_HEADER) + sizeof (RecvBuffer.PcrUpdateCounter) + sizeof (RecvBuffer.PcrSelectionOut.count) + sizeof (RecvBuffer.PcrSelectionOut.pcrSelections[0]) * PcrSelectionOut->count);\r
+  PcrValues->count = SwapBytes32 (PcrValuesOut->count);\r
   //\r
   // The number of digests in list is not greater than 8 per TPML_DIGEST definition\r
   //\r
@@ -412,15 +418,17 @@ Tpm2PcrRead (
     DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - PcrValues->count error %x\n", PcrValues->count));\r
     return EFI_DEVICE_ERROR;\r
   }\r
+\r
   Digests = PcrValuesOut->digests;\r
   for (Index = 0; Index < PcrValues->count; Index++) {\r
-    PcrValues->digests[Index].size = SwapBytes16(Digests->size);\r
-    if (PcrValues->digests[Index].size > sizeof(TPMU_HA)) {\r
+    PcrValues->digests[Index].size = SwapBytes16 (Digests->size);\r
+    if (PcrValues->digests[Index].size > sizeof (TPMU_HA)) {\r
       DEBUG ((DEBUG_ERROR, "Tpm2PcrRead - Digest.size error %x\n", PcrValues->digests[Index].size));\r
       return EFI_DEVICE_ERROR;\r
     }\r
+\r
     CopyMem (&PcrValues->digests[Index].buffer, &Digests->buffer, PcrValues->digests[Index].size);\r
-    Digests = (TPM2B_DIGEST *)((UINT8 *)Digests + sizeof(Digests->size) + PcrValues->digests[Index].size);\r
+    Digests = (TPM2B_DIGEST *)((UINT8 *)Digests + sizeof (Digests->size) + PcrValues->digests[Index].size);\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -443,13 +451,13 @@ Tpm2PcrRead (
 EFI_STATUS\r
 EFIAPI\r
 Tpm2PcrAllocate (\r
-  IN  TPMI_RH_PLATFORM          AuthHandle,\r
-  IN  TPMS_AUTH_COMMAND         *AuthSession,\r
-  IN  TPML_PCR_SELECTION        *PcrAllocation,\r
-  OUT TPMI_YES_NO               *AllocationSuccess,\r
-  OUT UINT32                    *MaxPCR,\r
-  OUT UINT32                    *SizeNeeded,\r
-  OUT UINT32                    *SizeAvailable\r
+  IN  TPMI_RH_PLATFORM    AuthHandle,\r
+  IN  TPMS_AUTH_COMMAND   *AuthSession,\r
+  IN  TPML_PCR_SELECTION  *PcrAllocation,\r
+  OUT TPMI_YES_NO         *AllocationSuccess,\r
+  OUT UINT32              *MaxPCR,\r
+  OUT UINT32              *SizeNeeded,\r
+  OUT UINT32              *SizeAvailable\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -466,10 +474,10 @@ Tpm2PcrAllocate (
   //\r
   // Construct command\r
   //\r
-  Cmd.Header.tag          = SwapBytes16(TPM_ST_SESSIONS);\r
-  Cmd.Header.paramSize    = SwapBytes32(sizeof(Cmd));\r
-  Cmd.Header.commandCode  = SwapBytes32(TPM_CC_PCR_Allocate);\r
-  Cmd.AuthHandle          = SwapBytes32(AuthHandle);\r
+  Cmd.Header.tag         = SwapBytes16 (TPM_ST_SESSIONS);\r
+  Cmd.Header.paramSize   = SwapBytes32 (sizeof (Cmd));\r
+  Cmd.Header.commandCode = SwapBytes32 (TPM_CC_PCR_Allocate);\r
+  Cmd.AuthHandle         = SwapBytes32 (AuthHandle);\r
 \r
   //\r
   // Add in Auth session\r
@@ -477,27 +485,27 @@ Tpm2PcrAllocate (
   Buffer = (UINT8 *)&Cmd.AuthSession;\r
 \r
   // sessionInfoSize\r
-  SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer);\r
-  Buffer += SessionInfoSize;\r
-  Cmd.AuthSessionSize = SwapBytes32(SessionInfoSize);\r
+  SessionInfoSize     = CopyAuthSessionCommand (AuthSession, Buffer);\r
+  Buffer             += SessionInfoSize;\r
+  Cmd.AuthSessionSize = SwapBytes32 (SessionInfoSize);\r
 \r
   // Count\r
-  WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32(PcrAllocation->count));\r
-  Buffer += sizeof(UINT32);\r
+  WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (PcrAllocation->count));\r
+  Buffer += sizeof (UINT32);\r
   for (Index = 0; Index < PcrAllocation->count; Index++) {\r
-    WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16(PcrAllocation->pcrSelections[Index].hash));\r
-    Buffer += sizeof(UINT16);\r
+    WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (PcrAllocation->pcrSelections[Index].hash));\r
+    Buffer          += sizeof (UINT16);\r
     *(UINT8 *)Buffer = PcrAllocation->pcrSelections[Index].sizeofSelect;\r
     Buffer++;\r
     CopyMem (Buffer, PcrAllocation->pcrSelections[Index].pcrSelect, PcrAllocation->pcrSelections[Index].sizeofSelect);\r
     Buffer += PcrAllocation->pcrSelections[Index].sizeofSelect;\r
   }\r
 \r
-  CmdSize = (UINT32)(Buffer - (UINT8 *)&Cmd);\r
-  Cmd.Header.paramSize = SwapBytes32(CmdSize);\r
+  CmdSize              = (UINT32)(Buffer - (UINT8 *)&Cmd);\r
+  Cmd.Header.paramSize = SwapBytes32 (CmdSize);\r
 \r
-  ResultBuf     = (UINT8 *) &Res;\r
-  ResultBufSize = sizeof(Res);\r
+  ResultBuf     = (UINT8 *)&Res;\r
+  ResultBufSize = sizeof (Res);\r
 \r
   //\r
   // Call the TPM\r
@@ -508,11 +516,11 @@ Tpm2PcrAllocate (
              &ResultBufSize,\r
              ResultBuf\r
              );\r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
 \r
-  if (ResultBufSize > sizeof(Res)) {\r
+  if (ResultBufSize > sizeof (Res)) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrAllocate: Failed ExecuteCommand: Buffer Too Small\r\n"));\r
     Status = EFI_BUFFER_TOO_SMALL;\r
     goto Done;\r
@@ -521,8 +529,8 @@ Tpm2PcrAllocate (
   //\r
   // Validate response headers\r
   //\r
-  RespSize = SwapBytes32(Res.Header.paramSize);\r
-  if (RespSize > sizeof(Res)) {\r
+  RespSize = SwapBytes32 (Res.Header.paramSize);\r
+  if (RespSize > sizeof (Res)) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2PcrAllocate: Response size too large! %d\r\n", RespSize));\r
     Status = EFI_BUFFER_TOO_SMALL;\r
     goto Done;\r
@@ -531,8 +539,8 @@ Tpm2PcrAllocate (
   //\r
   // Fail if command failed\r
   //\r
-  if (SwapBytes32(Res.Header.responseCode) != TPM_RC_SUCCESS) {\r
-    DEBUG((DEBUG_ERROR,"Tpm2PcrAllocate: Response Code error! 0x%08x\r\n", SwapBytes32(Res.Header.responseCode)));\r
+  if (SwapBytes32 (Res.Header.responseCode) != TPM_RC_SUCCESS) {\r
+    DEBUG ((DEBUG_ERROR, "Tpm2PcrAllocate: Response Code error! 0x%08x\r\n", SwapBytes32 (Res.Header.responseCode)));\r
     Status = EFI_DEVICE_ERROR;\r
     goto Done;\r
   }\r
@@ -541,16 +549,16 @@ Tpm2PcrAllocate (
   // Return the response\r
   //\r
   *AllocationSuccess = Res.AllocationSuccess;\r
-  *MaxPCR = SwapBytes32(Res.MaxPCR);\r
-  *SizeNeeded = SwapBytes32(Res.SizeNeeded);\r
-  *SizeAvailable = SwapBytes32(Res.SizeAvailable);\r
+  *MaxPCR            = SwapBytes32 (Res.MaxPCR);\r
+  *SizeNeeded        = SwapBytes32 (Res.SizeNeeded);\r
+  *SizeAvailable     = SwapBytes32 (Res.SizeAvailable);\r
 \r
 Done:\r
   //\r
   // Clear AuthSession Content\r
   //\r
-  ZeroMem (&Cmd, sizeof(Cmd));\r
-  ZeroMem (&Res, sizeof(Res));\r
+  ZeroMem (&Cmd, sizeof (Cmd));\r
+  ZeroMem (&Res, sizeof (Res));\r
   return Status;\r
 }\r
 \r
@@ -566,36 +574,36 @@ Done:
 EFI_STATUS\r
 EFIAPI\r
 Tpm2PcrAllocateBanks (\r
-  IN TPM2B_AUTH                *PlatformAuth   OPTIONAL,\r
-  IN UINT32                    SupportedPCRBanks,\r
-  IN UINT32                    PCRBanks\r
+  IN TPM2B_AUTH  *PlatformAuth   OPTIONAL,\r
+  IN UINT32      SupportedPCRBanks,\r
+  IN UINT32      PCRBanks\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  TPMS_AUTH_COMMAND         *AuthSession;\r
-  TPMS_AUTH_COMMAND         LocalAuthSession;\r
-  TPML_PCR_SELECTION        PcrAllocation;\r
-  TPMI_YES_NO               AllocationSuccess;\r
-  UINT32                    MaxPCR;\r
-  UINT32                    SizeNeeded;\r
-  UINT32                    SizeAvailable;\r
+  EFI_STATUS          Status;\r
+  TPMS_AUTH_COMMAND   *AuthSession;\r
+  TPMS_AUTH_COMMAND   LocalAuthSession;\r
+  TPML_PCR_SELECTION  PcrAllocation;\r
+  TPMI_YES_NO         AllocationSuccess;\r
+  UINT32              MaxPCR;\r
+  UINT32              SizeNeeded;\r
+  UINT32              SizeAvailable;\r
 \r
   if (PlatformAuth == NULL) {\r
     AuthSession = NULL;\r
   } else {\r
     AuthSession = &LocalAuthSession;\r
-    ZeroMem (&LocalAuthSession, sizeof(LocalAuthSession));\r
+    ZeroMem (&LocalAuthSession, sizeof (LocalAuthSession));\r
     LocalAuthSession.sessionHandle = TPM_RS_PW;\r
-    LocalAuthSession.hmac.size = PlatformAuth->size;\r
+    LocalAuthSession.hmac.size     = PlatformAuth->size;\r
     CopyMem (LocalAuthSession.hmac.buffer, PlatformAuth->buffer, PlatformAuth->size);\r
   }\r
 \r
   //\r
   // Fill input\r
   //\r
-  ZeroMem (&PcrAllocation, sizeof(PcrAllocation));\r
+  ZeroMem (&PcrAllocation, sizeof (PcrAllocation));\r
   if ((HASH_ALG_SHA1 & SupportedPCRBanks) != 0) {\r
-    PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SHA1;\r
+    PcrAllocation.pcrSelections[PcrAllocation.count].hash         = TPM_ALG_SHA1;\r
     PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
     if ((HASH_ALG_SHA1 & PCRBanks) != 0) {\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
@@ -606,10 +614,12 @@ Tpm2PcrAllocateBanks (
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
     }\r
+\r
     PcrAllocation.count++;\r
   }\r
+\r
   if ((HASH_ALG_SHA256 & SupportedPCRBanks) != 0) {\r
-    PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SHA256;\r
+    PcrAllocation.pcrSelections[PcrAllocation.count].hash         = TPM_ALG_SHA256;\r
     PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
     if ((HASH_ALG_SHA256 & PCRBanks) != 0) {\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
@@ -620,10 +630,12 @@ Tpm2PcrAllocateBanks (
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
     }\r
+\r
     PcrAllocation.count++;\r
   }\r
+\r
   if ((HASH_ALG_SHA384 & SupportedPCRBanks) != 0) {\r
-    PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SHA384;\r
+    PcrAllocation.pcrSelections[PcrAllocation.count].hash         = TPM_ALG_SHA384;\r
     PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
     if ((HASH_ALG_SHA384 & PCRBanks) != 0) {\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
@@ -634,10 +646,12 @@ Tpm2PcrAllocateBanks (
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
     }\r
+\r
     PcrAllocation.count++;\r
   }\r
+\r
   if ((HASH_ALG_SHA512 & SupportedPCRBanks) != 0) {\r
-    PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SHA512;\r
+    PcrAllocation.pcrSelections[PcrAllocation.count].hash         = TPM_ALG_SHA512;\r
     PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
     if ((HASH_ALG_SHA512 & PCRBanks) != 0) {\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
@@ -648,10 +662,12 @@ Tpm2PcrAllocateBanks (
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
     }\r
+\r
     PcrAllocation.count++;\r
   }\r
+\r
   if ((HASH_ALG_SM3_256 & SupportedPCRBanks) != 0) {\r
-    PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SM3_256;\r
+    PcrAllocation.pcrSelections[PcrAllocation.count].hash         = TPM_ALG_SM3_256;\r
     PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
     if ((HASH_ALG_SM3_256 & PCRBanks) != 0) {\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
@@ -662,8 +678,10 @@ Tpm2PcrAllocateBanks (
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
       PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
     }\r
+\r
     PcrAllocation.count++;\r
   }\r
+\r
   Status = Tpm2PcrAllocate (\r
              TPM_RH_PLATFORM,\r
              AuthSession,\r
@@ -684,6 +702,6 @@ Tpm2PcrAllocateBanks (
   DEBUG ((DEBUG_INFO, "SizeAvailable     - %08x\n", SizeAvailable));\r
 \r
 Done:\r
-  ZeroMem(&LocalAuthSession.hmac, sizeof(LocalAuthSession.hmac));\r
+  ZeroMem (&LocalAuthSession.hmac, sizeof (LocalAuthSession.hmac));\r
   return Status;\r
 }\r