2 Implement TPM2 Capability related command.
4 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <IndustryStandard/UefiTcgPlatform.h>
10 #include <Library/Tpm2CommandLib.h>
11 #include <Library/Tpm2DeviceLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/BaseLib.h>
14 #include <Library/DebugLib.h>
19 TPM2_COMMAND_HEADER Header
;
23 } TPM2_GET_CAPABILITY_COMMAND
;
26 TPM2_RESPONSE_HEADER Header
;
28 TPMS_CAPABILITY_DATA CapabilityData
;
29 } TPM2_GET_CAPABILITY_RESPONSE
;
32 TPM2_COMMAND_HEADER Header
;
33 TPMT_PUBLIC_PARMS Parameters
;
34 } TPM2_TEST_PARMS_COMMAND
;
37 TPM2_RESPONSE_HEADER Header
;
38 } TPM2_TEST_PARMS_RESPONSE
;
43 This command returns various information regarding the TPM and its current state.
45 The capability parameter determines the category of data returned. The property parameter
46 selects the first value of the selected category to be returned. If there is no property
47 that corresponds to the value of property, the next higher value is returned, if it exists.
48 The moreData parameter will have a value of YES if there are more values of the requested
49 type that were not returned.
50 If no next capability exists, the TPM will return a zero-length list and moreData will have
54 To simplify this function, leave returned CapabilityData for caller to unpack since there are
55 many capability categories and only few categories will be used in firmware. It means the caller
56 need swap the byte order for the feilds in CapabilityData.
58 @param[in] Capability Group selection; determines the format of the response.
59 @param[in] Property Further definition of information.
60 @param[in] PropertyCount Number of properties of the indicated type to return.
61 @param[out] MoreData Flag to indicate if there are more values of this type.
62 @param[out] CapabilityData The capability data.
64 @retval EFI_SUCCESS Operation completed successfully.
65 @retval EFI_DEVICE_ERROR The command was unsuccessful.
70 IN TPM_CAP Capability
,
72 IN UINT32 PropertyCount
,
73 OUT TPMI_YES_NO
*MoreData
,
74 OUT TPMS_CAPABILITY_DATA
*CapabilityData
78 TPM2_GET_CAPABILITY_COMMAND SendBuffer
;
79 TPM2_GET_CAPABILITY_RESPONSE RecvBuffer
;
80 UINT32 SendBufferSize
;
81 UINT32 RecvBufferSize
;
86 SendBuffer
.Header
.tag
= SwapBytes16(TPM_ST_NO_SESSIONS
);
87 SendBuffer
.Header
.commandCode
= SwapBytes32(TPM_CC_GetCapability
);
89 SendBuffer
.Capability
= SwapBytes32 (Capability
);
90 SendBuffer
.Property
= SwapBytes32 (Property
);
91 SendBuffer
.PropertyCount
= SwapBytes32 (PropertyCount
);
93 SendBufferSize
= (UINT32
) sizeof (SendBuffer
);
94 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
99 RecvBufferSize
= sizeof (RecvBuffer
);
100 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
101 if (EFI_ERROR (Status
)) {
105 if (RecvBufferSize
<= sizeof (TPM2_RESPONSE_HEADER
) + sizeof (UINT8
)) {
106 return EFI_DEVICE_ERROR
;
110 // Fail if command failed
112 if (SwapBytes32(RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
113 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapability: Response Code error! 0x%08x\r\n", SwapBytes32(RecvBuffer
.Header
.responseCode
)));
114 return EFI_DEVICE_ERROR
;
118 // Return the response
120 *MoreData
= RecvBuffer
.MoreData
;
122 // Does not unpack all possiable property here, the caller should unpack it and note the byte order.
124 CopyMem (CapabilityData
, &RecvBuffer
.CapabilityData
, RecvBufferSize
- sizeof (TPM2_RESPONSE_HEADER
) - sizeof (UINT8
));
130 This command returns the information of TPM Family.
132 This function parse the value got from TPM2_GetCapability and return the Family.
134 @param[out] Family The Family of TPM. (a 4-octet character string)
136 @retval EFI_SUCCESS Operation completed successfully.
137 @retval EFI_DEVICE_ERROR The command was unsuccessful.
141 Tpm2GetCapabilityFamily (
145 TPMS_CAPABILITY_DATA TpmCap
;
146 TPMI_YES_NO MoreData
;
149 Status
= Tpm2GetCapability (
150 TPM_CAP_TPM_PROPERTIES
,
151 TPM_PT_FAMILY_INDICATOR
,
156 if (EFI_ERROR (Status
)) {
159 CopyMem (Family
, &TpmCap
.data
.tpmProperties
.tpmProperty
->value
, 4);
165 This command returns the information of TPM manufacture ID.
167 This function parse the value got from TPM2_GetCapability and return the TPM manufacture ID.
169 @param[out] ManufactureId The manufacture ID of TPM.
171 @retval EFI_SUCCESS Operation completed successfully.
172 @retval EFI_DEVICE_ERROR The command was unsuccessful.
176 Tpm2GetCapabilityManufactureID (
177 OUT UINT32
*ManufactureId
180 TPMS_CAPABILITY_DATA TpmCap
;
181 TPMI_YES_NO MoreData
;
184 Status
= Tpm2GetCapability (
185 TPM_CAP_TPM_PROPERTIES
,
191 if (EFI_ERROR (Status
)) {
194 *ManufactureId
= TpmCap
.data
.tpmProperties
.tpmProperty
->value
;
200 This command returns the information of TPM FirmwareVersion.
202 This function parse the value got from TPM2_GetCapability and return the TPM FirmwareVersion.
204 @param[out] FirmwareVersion1 The FirmwareVersion1.
205 @param[out] FirmwareVersion2 The FirmwareVersion2.
207 @retval EFI_SUCCESS Operation completed successfully.
208 @retval EFI_DEVICE_ERROR The command was unsuccessful.
212 Tpm2GetCapabilityFirmwareVersion (
213 OUT UINT32
*FirmwareVersion1
,
214 OUT UINT32
*FirmwareVersion2
217 TPMS_CAPABILITY_DATA TpmCap
;
218 TPMI_YES_NO MoreData
;
221 Status
= Tpm2GetCapability (
222 TPM_CAP_TPM_PROPERTIES
,
223 TPM_PT_FIRMWARE_VERSION_1
,
228 if (EFI_ERROR (Status
)) {
231 *FirmwareVersion1
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
233 Status
= Tpm2GetCapability (
234 TPM_CAP_TPM_PROPERTIES
,
235 TPM_PT_FIRMWARE_VERSION_2
,
240 if (EFI_ERROR (Status
)) {
243 *FirmwareVersion2
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
249 This command returns the information of the maximum value for commandSize and responseSize in a command.
251 This function parse the value got from TPM2_GetCapability and return the max command size and response size
253 @param[out] MaxCommandSize The maximum value for commandSize in a command.
254 @param[out] MaxResponseSize The maximum value for responseSize in a command.
256 @retval EFI_SUCCESS Operation completed successfully.
257 @retval EFI_DEVICE_ERROR The command was unsuccessful.
261 Tpm2GetCapabilityMaxCommandResponseSize (
262 OUT UINT32
*MaxCommandSize
,
263 OUT UINT32
*MaxResponseSize
266 TPMS_CAPABILITY_DATA TpmCap
;
267 TPMI_YES_NO MoreData
;
270 Status
= Tpm2GetCapability (
271 TPM_CAP_TPM_PROPERTIES
,
272 TPM_PT_MAX_COMMAND_SIZE
,
277 if (EFI_ERROR (Status
)) {
281 *MaxCommandSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
283 Status
= Tpm2GetCapability (
284 TPM_CAP_TPM_PROPERTIES
,
285 TPM_PT_MAX_RESPONSE_SIZE
,
290 if (EFI_ERROR (Status
)) {
294 *MaxResponseSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
299 This command returns Returns a list of TPMS_ALG_PROPERTIES. Each entry is an
300 algorithm ID and a set of properties of the algorithm.
302 This function parse the value got from TPM2_GetCapability and return the list.
304 @param[out] AlgList List of algorithm.
306 @retval EFI_SUCCESS Operation completed successfully.
307 @retval EFI_DEVICE_ERROR The command was unsuccessful.
311 Tpm2GetCapabilitySupportedAlg (
312 OUT TPML_ALG_PROPERTY
*AlgList
315 TPMS_CAPABILITY_DATA TpmCap
;
316 TPMI_YES_NO MoreData
;
320 Status
= Tpm2GetCapability (
327 if (EFI_ERROR (Status
)) {
331 CopyMem (AlgList
, &TpmCap
.data
.algorithms
, sizeof (TPML_ALG_PROPERTY
));
333 AlgList
->count
= SwapBytes32 (AlgList
->count
);
334 if (AlgList
->count
> MAX_CAP_ALGS
) {
335 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilitySupportedAlg - AlgList->count error %x\n", AlgList
->count
));
336 return EFI_DEVICE_ERROR
;
339 for (Index
= 0; Index
< AlgList
->count
; Index
++) {
340 AlgList
->algProperties
[Index
].alg
= SwapBytes16 (AlgList
->algProperties
[Index
].alg
);
341 WriteUnaligned32 ((UINT32
*)&AlgList
->algProperties
[Index
].algProperties
, SwapBytes32 (ReadUnaligned32 ((UINT32
*)&AlgList
->algProperties
[Index
].algProperties
)));
348 This command returns the information of TPM LockoutCounter.
350 This function parse the value got from TPM2_GetCapability and return the LockoutCounter.
352 @param[out] LockoutCounter The LockoutCounter of TPM.
354 @retval EFI_SUCCESS Operation completed successfully.
355 @retval EFI_DEVICE_ERROR The command was unsuccessful.
359 Tpm2GetCapabilityLockoutCounter (
360 OUT UINT32
*LockoutCounter
363 TPMS_CAPABILITY_DATA TpmCap
;
364 TPMI_YES_NO MoreData
;
367 Status
= Tpm2GetCapability (
368 TPM_CAP_TPM_PROPERTIES
,
369 TPM_PT_LOCKOUT_COUNTER
,
374 if (EFI_ERROR (Status
)) {
377 *LockoutCounter
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
383 This command returns the information of TPM LockoutInterval.
385 This function parse the value got from TPM2_GetCapability and return the LockoutInterval.
387 @param[out] LockoutInterval The LockoutInterval of TPM.
389 @retval EFI_SUCCESS Operation completed successfully.
390 @retval EFI_DEVICE_ERROR The command was unsuccessful.
394 Tpm2GetCapabilityLockoutInterval (
395 OUT UINT32
*LockoutInterval
398 TPMS_CAPABILITY_DATA TpmCap
;
399 TPMI_YES_NO MoreData
;
402 Status
= Tpm2GetCapability (
403 TPM_CAP_TPM_PROPERTIES
,
404 TPM_PT_LOCKOUT_INTERVAL
,
409 if (EFI_ERROR (Status
)) {
412 *LockoutInterval
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
418 This command returns the information of TPM InputBufferSize.
420 This function parse the value got from TPM2_GetCapability and return the InputBufferSize.
422 @param[out] InputBufferSize The InputBufferSize of TPM.
423 the maximum size of a parameter (typically, a TPM2B_MAX_BUFFER)
425 @retval EFI_SUCCESS Operation completed successfully.
426 @retval EFI_DEVICE_ERROR The command was unsuccessful.
430 Tpm2GetCapabilityInputBufferSize (
431 OUT UINT32
*InputBufferSize
434 TPMS_CAPABILITY_DATA TpmCap
;
435 TPMI_YES_NO MoreData
;
438 Status
= Tpm2GetCapability (
439 TPM_CAP_TPM_PROPERTIES
,
445 if (EFI_ERROR (Status
)) {
448 *InputBufferSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
454 This command returns the information of TPM PCRs.
456 This function parse the value got from TPM2_GetCapability and return the PcrSelection.
458 @param[out] Pcrs The Pcr Selection
460 @retval EFI_SUCCESS Operation completed successfully.
461 @retval EFI_DEVICE_ERROR The command was unsuccessful.
465 Tpm2GetCapabilityPcrs (
466 OUT TPML_PCR_SELECTION
*Pcrs
469 TPMS_CAPABILITY_DATA TpmCap
;
470 TPMI_YES_NO MoreData
;
474 Status
= Tpm2GetCapability (
481 if (EFI_ERROR (Status
)) {
485 Pcrs
->count
= SwapBytes32 (TpmCap
.data
.assignedPCR
.count
);
486 if (Pcrs
->count
> HASH_COUNT
) {
487 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilityPcrs - Pcrs->count error %x\n", Pcrs
->count
));
488 return EFI_DEVICE_ERROR
;
491 for (Index
= 0; Index
< Pcrs
->count
; Index
++) {
492 Pcrs
->pcrSelections
[Index
].hash
= SwapBytes16 (TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].hash
);
493 Pcrs
->pcrSelections
[Index
].sizeofSelect
= TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].sizeofSelect
;
494 if (Pcrs
->pcrSelections
[Index
].sizeofSelect
> PCR_SELECT_MAX
) {
495 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilityPcrs - sizeofSelect error %x\n", Pcrs
->pcrSelections
[Index
].sizeofSelect
));
496 return EFI_DEVICE_ERROR
;
498 CopyMem (Pcrs
->pcrSelections
[Index
].pcrSelect
, TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].pcrSelect
, Pcrs
->pcrSelections
[Index
].sizeofSelect
);
505 This function will query the TPM to determine which hashing algorithms
506 are supported and which PCR banks are currently active.
508 @param[out] TpmHashAlgorithmBitmap A bitmask containing the algorithms supported by the TPM.
509 @param[out] ActivePcrBanks A bitmask containing the PCRs currently allocated.
511 @retval EFI_SUCCESS TPM was successfully queried and return values can be trusted.
512 @retval Others An error occurred, likely in communication with the TPM.
517 Tpm2GetCapabilitySupportedAndActivePcrs (
518 OUT UINT32
*TpmHashAlgorithmBitmap
,
519 OUT UINT32
*ActivePcrBanks
523 TPML_PCR_SELECTION Pcrs
;
527 // Get supported PCR and current Active PCRs.
529 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
532 // If error, assume that we have at least SHA-1 (and return the error.)
534 if (EFI_ERROR (Status
)) {
535 DEBUG ((EFI_D_ERROR
, "GetSupportedAndActivePcrs - Tpm2GetCapabilityPcrs fail!\n"));
536 *TpmHashAlgorithmBitmap
= HASH_ALG_SHA1
;
537 *ActivePcrBanks
= HASH_ALG_SHA1
;
540 // Otherwise, process the return data to determine what algorithms are supported
541 // and currently allocated.
544 DEBUG ((EFI_D_INFO
, "GetSupportedAndActivePcrs - Count = %08x\n", Pcrs
.count
));
545 *TpmHashAlgorithmBitmap
= 0;
547 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
548 switch (Pcrs
.pcrSelections
[Index
].hash
) {
550 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 present.\n"));
551 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA1
;
552 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
553 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 active.\n"));
554 *ActivePcrBanks
|= HASH_ALG_SHA1
;
558 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 present.\n"));
559 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA256
;
560 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
561 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 active.\n"));
562 *ActivePcrBanks
|= HASH_ALG_SHA256
;
566 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 present.\n"));
567 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA384
;
568 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
569 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 active.\n"));
570 *ActivePcrBanks
|= HASH_ALG_SHA384
;
574 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 present.\n"));
575 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA512
;
576 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
577 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 active.\n"));
578 *ActivePcrBanks
|= HASH_ALG_SHA512
;
581 case TPM_ALG_SM3_256
:
582 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 present.\n"));
583 *TpmHashAlgorithmBitmap
|= HASH_ALG_SM3_256
;
584 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
585 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 active.\n"));
586 *ActivePcrBanks
|= HASH_ALG_SM3_256
;
597 This command returns the information of TPM AlgorithmSet.
599 This function parse the value got from TPM2_GetCapability and return the AlgorithmSet.
601 @param[out] AlgorithmSet The AlgorithmSet of TPM.
603 @retval EFI_SUCCESS Operation completed successfully.
604 @retval EFI_DEVICE_ERROR The command was unsuccessful.
608 Tpm2GetCapabilityAlgorithmSet (
609 OUT UINT32
*AlgorithmSet
612 TPMS_CAPABILITY_DATA TpmCap
;
613 TPMI_YES_NO MoreData
;
616 Status
= Tpm2GetCapability (
617 TPM_CAP_TPM_PROPERTIES
,
618 TPM_PT_ALGORITHM_SET
,
623 if (EFI_ERROR (Status
)) {
626 *AlgorithmSet
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
632 This command is used to check to see if specific combinations of algorithm parameters are supported.
634 @param[in] Parameters Algorithm parameters to be validated
636 @retval EFI_SUCCESS Operation completed successfully.
637 @retval EFI_DEVICE_ERROR Unexpected device behavior.
642 IN TPMT_PUBLIC_PARMS
*Parameters
646 TPM2_TEST_PARMS_COMMAND SendBuffer
;
647 TPM2_TEST_PARMS_RESPONSE RecvBuffer
;
648 UINT32 SendBufferSize
;
649 UINT32 RecvBufferSize
;
655 SendBuffer
.Header
.tag
= SwapBytes16(TPM_ST_NO_SESSIONS
);
656 SendBuffer
.Header
.commandCode
= SwapBytes32(TPM_CC_TestParms
);
658 Buffer
= (UINT8
*)&SendBuffer
.Parameters
;
659 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->type
));
660 Buffer
+= sizeof(UINT16
);
661 switch (Parameters
->type
) {
662 case TPM_ALG_KEYEDHASH
:
663 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
));
664 Buffer
+= sizeof(UINT16
);
665 switch (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
) {
667 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.hmac
.hashAlg
));
668 Buffer
+= sizeof(UINT16
);
671 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.hashAlg
));
672 Buffer
+= sizeof(UINT16
);
673 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.kdf
));
674 Buffer
+= sizeof(UINT16
);
677 return EFI_INVALID_PARAMETER
;
679 case TPM_ALG_SYMCIPHER
:
680 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.algorithm
));
681 Buffer
+= sizeof(UINT16
);
682 switch (Parameters
->parameters
.symDetail
.algorithm
) {
684 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.aes
));
685 Buffer
+= sizeof(UINT16
);
686 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.aes
));
687 Buffer
+= sizeof(UINT16
);
690 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.SM4
));
691 Buffer
+= sizeof(UINT16
);
692 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.SM4
));
693 Buffer
+= sizeof(UINT16
);
696 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.xor));
697 Buffer
+= sizeof(UINT16
);
702 return EFI_INVALID_PARAMETER
;
706 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
));
707 Buffer
+= sizeof(UINT16
);
708 switch (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
) {
710 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.aes
));
711 Buffer
+= sizeof(UINT16
);
712 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.aes
));
713 Buffer
+= sizeof(UINT16
);
716 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.SM4
));
717 Buffer
+= sizeof(UINT16
);
718 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.SM4
));
719 Buffer
+= sizeof(UINT16
);
724 return EFI_INVALID_PARAMETER
;
726 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.scheme
));
727 Buffer
+= sizeof(UINT16
);
728 switch (Parameters
->parameters
.rsaDetail
.scheme
.scheme
) {
730 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsassa
.hashAlg
));
731 Buffer
+= sizeof(UINT16
);
734 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsapss
.hashAlg
));
735 Buffer
+= sizeof(UINT16
);
740 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.oaep
.hashAlg
));
741 Buffer
+= sizeof(UINT16
);
746 return EFI_INVALID_PARAMETER
;
748 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.keyBits
));
749 Buffer
+= sizeof(UINT16
);
750 WriteUnaligned32 ((UINT32
*)Buffer
, SwapBytes32 (Parameters
->parameters
.rsaDetail
.exponent
));
751 Buffer
+= sizeof(UINT32
);
754 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
));
755 Buffer
+= sizeof(UINT16
);
756 switch (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
) {
758 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.aes
));
759 Buffer
+= sizeof(UINT16
);
760 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.aes
));
761 Buffer
+= sizeof(UINT16
);
764 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.SM4
));
765 Buffer
+= sizeof(UINT16
);
766 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.SM4
));
767 Buffer
+= sizeof(UINT16
);
772 return EFI_INVALID_PARAMETER
;
774 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.scheme
));
775 Buffer
+= sizeof(UINT16
);
776 switch (Parameters
->parameters
.eccDetail
.scheme
.scheme
) {
778 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdsa
.hashAlg
));
779 Buffer
+= sizeof(UINT16
);
782 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdaa
.hashAlg
));
783 Buffer
+= sizeof(UINT16
);
785 case TPM_ALG_ECSCHNORR
:
786 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecSchnorr
.hashAlg
));
787 Buffer
+= sizeof(UINT16
);
794 return EFI_INVALID_PARAMETER
;
796 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.curveID
));
797 Buffer
+= sizeof(UINT16
);
798 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.scheme
));
799 Buffer
+= sizeof(UINT16
);
800 switch (Parameters
->parameters
.eccDetail
.kdf
.scheme
) {
802 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.mgf1
.hashAlg
));
803 Buffer
+= sizeof(UINT16
);
805 case TPM_ALG_KDF1_SP800_108
:
806 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_sp800_108
.hashAlg
));
807 Buffer
+= sizeof(UINT16
);
809 case TPM_ALG_KDF1_SP800_56a
:
810 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_SP800_56a
.hashAlg
));
811 Buffer
+= sizeof(UINT16
);
814 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf2
.hashAlg
));
815 Buffer
+= sizeof(UINT16
);
820 return EFI_INVALID_PARAMETER
;
824 return EFI_INVALID_PARAMETER
;
827 SendBufferSize
= (UINT32
)((UINTN
)Buffer
- (UINTN
)&SendBuffer
);
828 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
833 RecvBufferSize
= sizeof (RecvBuffer
);
834 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
835 if (EFI_ERROR (Status
)) {
839 if (RecvBufferSize
< sizeof (TPM2_RESPONSE_HEADER
)) {
840 DEBUG ((EFI_D_ERROR
, "Tpm2TestParms - RecvBufferSize Error - %x\n", RecvBufferSize
));
841 return EFI_DEVICE_ERROR
;
843 if (SwapBytes32(RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
844 DEBUG ((EFI_D_ERROR
, "Tpm2TestParms - responseCode - %x\n", SwapBytes32(RecvBuffer
.Header
.responseCode
)));
845 return EFI_UNSUPPORTED
;