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