21 TPMI_ALG_HASH HashAlg;
26 TPMI_DH_OBJECT SequenceHandle;
31 TPMI_DH_OBJECT SequenceHandle;
32 UINT32 AuthorizationSize;
45 TPMI_DH_PCR PcrHandle;
46 TPMI_DH_OBJECT SequenceHandle;
47 UINT32 AuthorizationSize;
63 TPMI_DH_OBJECT SequenceHandle;
64 UINT32 AuthorizationSize;
67 TPMI_RH_HIERARCHY Hierarchy;
94 IN TPMI_ALG_HASH HashAlg,
95 OUT TPMI_DH_OBJECT *SequenceHandle
104 UINT32 ResultBufSize;
112 Cmd.Header.commandCode =
SwapBytes32 (TPM_CC_HashSequenceStart);
114 Buffer = (UINT8 *)&Cmd.Auth;
118 Buffer +=
sizeof (UINT16);
122 Buffer +=
sizeof (UINT16);
124 CmdSize = (UINT32)(Buffer - (UINT8 *)&Cmd);
130 ResultBufSize =
sizeof (Res);
131 Status =
Tpm2SubmitCommand (CmdSize, (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
132 if (EFI_ERROR (Status)) {
136 if (ResultBufSize >
sizeof (Res)) {
137 DEBUG ((DEBUG_ERROR,
"HashSequenceStart: Failed ExecuteCommand: Buffer Too Small\r\n"));
138 return EFI_BUFFER_TOO_SMALL;
145 if (RespSize >
sizeof (Res)) {
146 DEBUG ((DEBUG_ERROR,
"HashSequenceStart: Response size too large! %d\r\n", RespSize));
147 return EFI_BUFFER_TOO_SMALL;
153 if (
SwapBytes32 (Res.Header.responseCode) != TPM_RC_SUCCESS) {
154 DEBUG ((DEBUG_ERROR,
"HashSequenceStart: Response Code error! 0x%08x\r\n",
SwapBytes32 (Res.Header.responseCode)));
155 return EFI_DEVICE_ERROR;
163 *SequenceHandle =
SwapBytes32 (Res.SequenceHandle);
182 IN TPMI_DH_OBJECT SequenceHandle,
192 UINT32 SessionInfoSize;
193 UINT32 ResultBufSize;
201 Cmd.Header.commandCode =
SwapBytes32 (TPM_CC_SequenceUpdate);
207 BufferPtr = (UINT8 *)&Cmd.AuthSessionSeq;
211 BufferPtr += SessionInfoSize;
212 Cmd.AuthorizationSize =
SwapBytes32 (SessionInfoSize);
216 BufferPtr +=
sizeof (UINT16);
218 CopyMem (BufferPtr, &Buffer->buffer, Buffer->size);
219 BufferPtr += Buffer->size;
221 CmdSize = (UINT32)(BufferPtr - (UINT8 *)&Cmd);
227 ResultBufSize =
sizeof (Res);
228 Status =
Tpm2SubmitCommand (CmdSize, (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
229 if (EFI_ERROR (Status)) {
233 if (ResultBufSize >
sizeof (Res)) {
234 DEBUG ((DEBUG_ERROR,
"SequenceUpdate: Failed ExecuteCommand: Buffer Too Small\r\n"));
235 return EFI_BUFFER_TOO_SMALL;
242 if (RespSize >
sizeof (Res)) {
243 DEBUG ((DEBUG_ERROR,
"SequenceUpdate: Response size too large! %d\r\n", RespSize));
244 return EFI_BUFFER_TOO_SMALL;
250 if (
SwapBytes32 (Res.Header.responseCode) != TPM_RC_SUCCESS) {
251 DEBUG ((DEBUG_ERROR,
"SequenceUpdate: Response Code error! 0x%08x\r\n",
SwapBytes32 (Res.Header.responseCode)));
252 return EFI_DEVICE_ERROR;
281 IN TPMI_DH_PCR PcrHandle,
282 IN TPMI_DH_OBJECT SequenceHandle,
293 UINT32 SessionInfoSize;
294 UINT32 SessionInfoSize2;
296 UINT32 ResultBufSize;
305 Cmd.Header.commandCode =
SwapBytes32 (TPM_CC_EventSequenceComplete);
312 BufferPtr = (UINT8 *)&Cmd.AuthSessionPcr;
316 BufferPtr += SessionInfoSize;
320 BufferPtr += SessionInfoSize2;
321 Cmd.AuthorizationSize =
SwapBytes32 (SessionInfoSize + SessionInfoSize2);
325 BufferPtr +=
sizeof (UINT16);
327 CopyMem (BufferPtr, &Buffer->buffer[0], Buffer->size);
328 BufferPtr += Buffer->size;
330 CmdSize = (UINT32)(BufferPtr - (UINT8 *)&Cmd);
336 ResultBufSize =
sizeof (Res);
337 Status =
Tpm2SubmitCommand (CmdSize, (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
338 if (EFI_ERROR (Status)) {
342 if (ResultBufSize >
sizeof (Res)) {
343 DEBUG ((DEBUG_ERROR,
"EventSequenceComplete: Failed ExecuteCommand: Buffer Too Small\r\n"));
344 return EFI_BUFFER_TOO_SMALL;
351 if (RespSize >
sizeof (Res)) {
352 DEBUG ((DEBUG_ERROR,
"EventSequenceComplete: Response size too large! %d\r\n", RespSize));
353 return EFI_BUFFER_TOO_SMALL;
359 if (
SwapBytes32 (Res.Header.responseCode) != TPM_RC_SUCCESS) {
360 DEBUG ((DEBUG_ERROR,
"EventSequenceComplete: Response Code error! 0x%08x\r\n",
SwapBytes32 (Res.Header.responseCode)));
361 return EFI_DEVICE_ERROR;
368 BufferPtr = (UINT8 *)&Res.Results;
372 if (Results->count > HASH_COUNT) {
373 DEBUG ((DEBUG_ERROR,
"Tpm2EventSequenceComplete - Results->count error %x\n", Results->count));
374 return EFI_DEVICE_ERROR;
377 BufferPtr +=
sizeof (UINT32);
379 for (Index = 0; Index < Results->count; Index++) {
381 BufferPtr +=
sizeof (UINT16);
384 if (DigestSize == 0) {
385 DEBUG ((DEBUG_ERROR,
"EventSequenceComplete: Unknown hash algorithm %d\r\n", Results->digests[Index].hashAlg));
386 return EFI_DEVICE_ERROR;
390 &Results->digests[Index].digest,
394 BufferPtr += DigestSize;
413 IN TPMI_DH_OBJECT SequenceHandle,
424 UINT32 SessionInfoSize;
425 UINT32 ResultBufSize;
433 Cmd.Header.commandCode =
SwapBytes32 (TPM_CC_SequenceComplete);
439 BufferPtr = (UINT8 *)&Cmd.AuthSessionSeq;
443 BufferPtr += SessionInfoSize;
444 Cmd.AuthorizationSize =
SwapBytes32 (SessionInfoSize);
448 BufferPtr +=
sizeof (UINT16);
450 CopyMem (BufferPtr, &Buffer->buffer[0], Buffer->size);
451 BufferPtr += Buffer->size;
455 BufferPtr +=
sizeof (UINT32);
457 CmdSize = (UINT32)(BufferPtr - (UINT8 *)&Cmd);
463 ResultBufSize =
sizeof (Res);
464 Status =
Tpm2SubmitCommand (CmdSize, (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
465 if (EFI_ERROR (Status)) {
469 if (ResultBufSize >
sizeof (Res)) {
470 DEBUG ((DEBUG_ERROR,
"SequenceComplete: Failed ExecuteCommand: Buffer Too Small\r\n"));
471 return EFI_BUFFER_TOO_SMALL;
478 if (RespSize >
sizeof (Res)) {
479 DEBUG ((DEBUG_ERROR,
"SequenceComplete: Response size too large! %d\r\n", RespSize));
480 return EFI_BUFFER_TOO_SMALL;
486 if (
SwapBytes32 (Res.Header.responseCode) != TPM_RC_SUCCESS) {
487 DEBUG ((DEBUG_ERROR,
"SequenceComplete: Response Code error! 0x%08x\r\n",
SwapBytes32 (Res.Header.responseCode)));
488 return EFI_DEVICE_ERROR;
495 BufferPtr = (UINT8 *)&Res.Digest;
499 if (Result->size > sizeof (
TPMU_HA)) {
500 DEBUG ((DEBUG_ERROR,
"Tpm2SequenceComplete - Result->size error %x\n", Result->size));
501 return EFI_DEVICE_ERROR;
504 BufferPtr +=
sizeof (UINT16);
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
UINT16 EFIAPI ReadUnaligned16(IN CONST UINT16 *Buffer)
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
UINT16 EFIAPI WriteUnaligned16(OUT UINT16 *Buffer, IN UINT16 Value)
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define DEBUG(Expression)
UINT16 GetHashSizeFromAlgo(IN TPMI_ALG_HASH HashAlgo)
UINT32 EFIAPI CopyAuthSessionCommand(IN TPMS_AUTH_COMMAND *AuthSessionIn OPTIONAL, OUT UINT8 *AuthSessionOut)
EFI_STATUS EFIAPI Tpm2SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
EFI_STATUS EFIAPI Tpm2HashSequenceStart(IN TPMI_ALG_HASH HashAlg, OUT TPMI_DH_OBJECT *SequenceHandle)
EFI_STATUS EFIAPI Tpm2SequenceComplete(IN TPMI_DH_OBJECT SequenceHandle, IN TPM2B_MAX_BUFFER *Buffer, OUT TPM2B_DIGEST *Result)
EFI_STATUS EFIAPI Tpm2EventSequenceComplete(IN TPMI_DH_PCR PcrHandle, IN TPMI_DH_OBJECT SequenceHandle, IN TPM2B_MAX_BUFFER *Buffer, OUT TPML_DIGEST_VALUES *Results)
EFI_STATUS EFIAPI Tpm2SequenceUpdate(IN TPMI_DH_OBJECT SequenceHandle, IN TPM2B_MAX_BUFFER *Buffer)