20 TPMI_DH_ENTITY AuthHandle;
21 TPMI_SH_POLICY PolicySession;
22 UINT32 AuthSessionSize;
32 UINT32 AuthSessionSize;
40 TPMI_SH_POLICY PolicySession;
50 TPMI_SH_POLICY PolicySession;
60 TPMI_SH_POLICY PolicySession;
91 IN TPMI_DH_ENTITY AuthHandle,
92 IN TPMI_SH_POLICY PolicySession,
105 UINT32 SendBufferSize;
106 UINT32 RecvBufferSize;
108 UINT32 SessionInfoSize;
113 SendBuffer.Header.tag =
SwapBytes16 (TPM_ST_SESSIONS);
114 SendBuffer.Header.commandCode =
SwapBytes32 (TPM_CC_PolicySecret);
116 SendBuffer.PolicySession =
SwapBytes32 (PolicySession);
121 Buffer = (UINT8 *)&SendBuffer.AuthSession;
125 Buffer += SessionInfoSize;
126 SendBuffer.AuthSessionSize =
SwapBytes32 (SessionInfoSize);
132 Buffer +=
sizeof (UINT16);
133 CopyMem (Buffer, NonceTPM->buffer, NonceTPM->size);
134 Buffer += NonceTPM->size;
137 Buffer +=
sizeof (UINT16);
138 CopyMem (Buffer, CpHashA->buffer, CpHashA->size);
139 Buffer += CpHashA->size;
142 Buffer +=
sizeof (UINT16);
143 CopyMem (Buffer, PolicyRef->buffer, PolicyRef->size);
144 Buffer += PolicyRef->size;
147 Buffer +=
sizeof (UINT32);
149 SendBufferSize = (UINT32)((
UINTN)Buffer - (
UINTN)&SendBuffer);
150 SendBuffer.Header.paramSize =
SwapBytes32 (SendBufferSize);
155 RecvBufferSize =
sizeof (RecvBuffer);
156 Status =
Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
157 if (EFI_ERROR (Status)) {
162 DEBUG ((DEBUG_ERROR,
"Tpm2PolicySecret - RecvBufferSize Error - %x\n", RecvBufferSize));
163 Status = EFI_DEVICE_ERROR;
167 if (
SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
168 DEBUG ((DEBUG_ERROR,
"Tpm2PolicySecret - responseCode - %x\n",
SwapBytes32 (RecvBuffer.Header.responseCode)));
169 Status = EFI_DEVICE_ERROR;
176 Buffer = (UINT8 *)&RecvBuffer.Timeout;
178 if (Timeout->size > sizeof (UINT64)) {
179 DEBUG ((DEBUG_ERROR,
"Tpm2PolicySecret - Timeout->size error %x\n", Timeout->size));
180 Status = EFI_DEVICE_ERROR;
184 Buffer +=
sizeof (UINT16);
185 CopyMem (Timeout->buffer, Buffer, Timeout->size);
188 Buffer +=
sizeof (UINT16);
190 Buffer +=
sizeof (UINT32);
192 Buffer +=
sizeof (UINT16);
193 if (PolicyTicket->digest.size > sizeof (
TPMU_HA)) {
194 DEBUG ((DEBUG_ERROR,
"Tpm2PolicySecret - digest.size error %x\n", PolicyTicket->digest.size));
195 Status = EFI_DEVICE_ERROR;
199 CopyMem (PolicyTicket->digest.buffer, Buffer, PolicyTicket->digest.size);
205 ZeroMem (&SendBuffer,
sizeof (SendBuffer));
206 ZeroMem (&RecvBuffer,
sizeof (RecvBuffer));
225 IN TPMI_SH_POLICY PolicySession,
232 UINT32 SendBufferSize;
233 UINT32 RecvBufferSize;
240 SendBuffer.Header.tag =
SwapBytes16 (TPM_ST_NO_SESSIONS);
241 SendBuffer.Header.commandCode =
SwapBytes32 (TPM_CC_PolicyOR);
243 SendBuffer.PolicySession =
SwapBytes32 (PolicySession);
244 Buffer = (UINT8 *)&SendBuffer.HashList;
246 Buffer +=
sizeof (UINT32);
247 for (Index = 0; Index < HashList->count; Index++) {
249 Buffer +=
sizeof (UINT16);
250 CopyMem (Buffer, HashList->digests[Index].buffer, HashList->digests[Index].size);
251 Buffer += HashList->digests[Index].size;
254 SendBufferSize = (UINT32)((
UINTN)Buffer - (
UINTN)&SendBuffer);
255 SendBuffer.Header.paramSize =
SwapBytes32 (SendBufferSize);
260 RecvBufferSize =
sizeof (RecvBuffer);
261 Status =
Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
262 if (EFI_ERROR (Status)) {
267 DEBUG ((DEBUG_ERROR,
"Tpm2PolicyOR - RecvBufferSize Error - %x\n", RecvBufferSize));
268 return EFI_DEVICE_ERROR;
271 if (
SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
272 DEBUG ((DEBUG_ERROR,
"Tpm2PolicyOR - responseCode - %x\n",
SwapBytes32 (RecvBuffer.Header.responseCode)));
273 return EFI_DEVICE_ERROR;
291 IN TPMI_SH_POLICY PolicySession,
298 UINT32 SendBufferSize;
299 UINT32 RecvBufferSize;
304 SendBuffer.Header.tag =
SwapBytes16 (TPM_ST_NO_SESSIONS);
305 SendBuffer.Header.commandCode =
SwapBytes32 (TPM_CC_PolicyCommandCode);
307 SendBuffer.PolicySession =
SwapBytes32 (PolicySession);
310 SendBufferSize = (UINT32)
sizeof (SendBuffer);
311 SendBuffer.Header.paramSize =
SwapBytes32 (SendBufferSize);
316 RecvBufferSize =
sizeof (RecvBuffer);
317 Status =
Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
318 if (EFI_ERROR (Status)) {
323 DEBUG ((DEBUG_ERROR,
"Tpm2PolicyCommandCode - RecvBufferSize Error - %x\n", RecvBufferSize));
324 return EFI_DEVICE_ERROR;
327 if (
SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
328 DEBUG ((DEBUG_ERROR,
"Tpm2PolicyCommandCode - responseCode - %x\n",
SwapBytes32 (RecvBuffer.Header.responseCode)));
329 return EFI_DEVICE_ERROR;
348 IN TPMI_SH_POLICY PolicySession,
355 UINT32 SendBufferSize;
356 UINT32 RecvBufferSize;
361 SendBuffer.Header.tag =
SwapBytes16 (TPM_ST_NO_SESSIONS);
362 SendBuffer.Header.commandCode =
SwapBytes32 (TPM_CC_PolicyGetDigest);
364 SendBuffer.PolicySession =
SwapBytes32 (PolicySession);
366 SendBufferSize = (UINT32)
sizeof (SendBuffer);
367 SendBuffer.Header.paramSize =
SwapBytes32 (SendBufferSize);
372 RecvBufferSize =
sizeof (RecvBuffer);
373 Status =
Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
374 if (EFI_ERROR (Status)) {
379 DEBUG ((DEBUG_ERROR,
"Tpm2PolicyGetDigest - RecvBufferSize Error - %x\n", RecvBufferSize));
380 return EFI_DEVICE_ERROR;
383 if (
SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
384 DEBUG ((DEBUG_ERROR,
"Tpm2PolicyGetDigest - responseCode - %x\n",
SwapBytes32 (RecvBuffer.Header.responseCode)));
385 return EFI_DEVICE_ERROR;
391 PolicyHash->size =
SwapBytes16 (RecvBuffer.PolicyHash.size);
392 if (PolicyHash->size > sizeof (
TPMU_HA)) {
393 DEBUG ((DEBUG_ERROR,
"Tpm2PolicyGetDigest - PolicyHash->size error %x\n", PolicyHash->size));
394 return EFI_DEVICE_ERROR;
397 CopyMem (PolicyHash->buffer, &RecvBuffer.PolicyHash.buffer, PolicyHash->size);
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)
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 Tpm2PolicyOR(IN TPMI_SH_POLICY PolicySession, IN TPML_DIGEST *HashList)
EFI_STATUS EFIAPI Tpm2PolicyCommandCode(IN TPMI_SH_POLICY PolicySession, IN TPM_CC Code)
EFI_STATUS EFIAPI Tpm2PolicySecret(IN TPMI_DH_ENTITY AuthHandle, IN TPMI_SH_POLICY PolicySession, IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL, IN TPM2B_NONCE *NonceTPM, IN TPM2B_DIGEST *CpHashA, IN TPM2B_NONCE *PolicyRef, IN INT32 Expiration, OUT TPM2B_TIMEOUT *Timeout, OUT TPMT_TK_AUTH *PolicyTicket)
EFI_STATUS EFIAPI Tpm2PolicyGetDigest(IN TPMI_SH_POLICY PolicySession, OUT TPM2B_DIGEST *PolicyHash)