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
;
42 #define TPMA_CC_COMMANDINDEX_MASK 0x2000FFFF
45 This command returns various information regarding the TPM and its current state.
47 The capability parameter determines the category of data returned. The property parameter
48 selects the first value of the selected category to be returned. If there is no property
49 that corresponds to the value of property, the next higher value is returned, if it exists.
50 The moreData parameter will have a value of YES if there are more values of the requested
51 type that were not returned.
52 If no next capability exists, the TPM will return a zero-length list and moreData will have
56 To simplify this function, leave returned CapabilityData for caller to unpack since there are
57 many capability categories and only few categories will be used in firmware. It means the caller
58 need swap the byte order for the fields in CapabilityData.
60 @param[in] Capability Group selection; determines the format of the response.
61 @param[in] Property Further definition of information.
62 @param[in] PropertyCount Number of properties of the indicated type to return.
63 @param[out] MoreData Flag to indicate if there are more values of this type.
64 @param[out] CapabilityData The capability data.
66 @retval EFI_SUCCESS Operation completed successfully.
67 @retval EFI_DEVICE_ERROR The command was unsuccessful.
72 IN TPM_CAP Capability
,
74 IN UINT32 PropertyCount
,
75 OUT TPMI_YES_NO
*MoreData
,
76 OUT TPMS_CAPABILITY_DATA
*CapabilityData
80 TPM2_GET_CAPABILITY_COMMAND SendBuffer
;
81 TPM2_GET_CAPABILITY_RESPONSE RecvBuffer
;
82 UINT32 SendBufferSize
;
83 UINT32 RecvBufferSize
;
88 SendBuffer
.Header
.tag
= SwapBytes16 (TPM_ST_NO_SESSIONS
);
89 SendBuffer
.Header
.commandCode
= SwapBytes32 (TPM_CC_GetCapability
);
91 SendBuffer
.Capability
= SwapBytes32 (Capability
);
92 SendBuffer
.Property
= SwapBytes32 (Property
);
93 SendBuffer
.PropertyCount
= SwapBytes32 (PropertyCount
);
95 SendBufferSize
= (UINT32
)sizeof (SendBuffer
);
96 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
101 RecvBufferSize
= sizeof (RecvBuffer
);
102 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
103 if (EFI_ERROR (Status
)) {
107 if (RecvBufferSize
<= sizeof (TPM2_RESPONSE_HEADER
) + sizeof (UINT8
)) {
108 return EFI_DEVICE_ERROR
;
112 // Fail if command failed
114 if (SwapBytes32 (RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
115 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapability: Response Code error! 0x%08x\r\n", SwapBytes32 (RecvBuffer
.Header
.responseCode
)));
116 return EFI_DEVICE_ERROR
;
120 // Return the response
122 *MoreData
= RecvBuffer
.MoreData
;
124 // Does not unpack all possible property here, the caller should unpack it and note the byte order.
126 CopyMem (CapabilityData
, &RecvBuffer
.CapabilityData
, RecvBufferSize
- sizeof (TPM2_RESPONSE_HEADER
) - sizeof (UINT8
));
132 This command returns the information of TPM Family.
134 This function parse the value got from TPM2_GetCapability and return the Family.
136 @param[out] Family The Family of TPM. (a 4-octet character string)
138 @retval EFI_SUCCESS Operation completed successfully.
139 @retval EFI_DEVICE_ERROR The command was unsuccessful.
143 Tpm2GetCapabilityFamily (
147 TPMS_CAPABILITY_DATA TpmCap
;
148 TPMI_YES_NO MoreData
;
151 Status
= Tpm2GetCapability (
152 TPM_CAP_TPM_PROPERTIES
,
153 TPM_PT_FAMILY_INDICATOR
,
158 if (EFI_ERROR (Status
)) {
162 CopyMem (Family
, &TpmCap
.data
.tpmProperties
.tpmProperty
->value
, 4);
168 This command returns the information of TPM manufacture ID.
170 This function parse the value got from TPM2_GetCapability and return the TPM manufacture ID.
172 @param[out] ManufactureId The manufacture ID of TPM.
174 @retval EFI_SUCCESS Operation completed successfully.
175 @retval EFI_DEVICE_ERROR The command was unsuccessful.
179 Tpm2GetCapabilityManufactureID (
180 OUT UINT32
*ManufactureId
183 TPMS_CAPABILITY_DATA TpmCap
;
184 TPMI_YES_NO MoreData
;
187 Status
= Tpm2GetCapability (
188 TPM_CAP_TPM_PROPERTIES
,
194 if (EFI_ERROR (Status
)) {
198 *ManufactureId
= TpmCap
.data
.tpmProperties
.tpmProperty
->value
;
204 This command returns the information of TPM FirmwareVersion.
206 This function parse the value got from TPM2_GetCapability and return the TPM FirmwareVersion.
208 @param[out] FirmwareVersion1 The FirmwareVersion1.
209 @param[out] FirmwareVersion2 The FirmwareVersion2.
211 @retval EFI_SUCCESS Operation completed successfully.
212 @retval EFI_DEVICE_ERROR The command was unsuccessful.
216 Tpm2GetCapabilityFirmwareVersion (
217 OUT UINT32
*FirmwareVersion1
,
218 OUT UINT32
*FirmwareVersion2
221 TPMS_CAPABILITY_DATA TpmCap
;
222 TPMI_YES_NO MoreData
;
225 Status
= Tpm2GetCapability (
226 TPM_CAP_TPM_PROPERTIES
,
227 TPM_PT_FIRMWARE_VERSION_1
,
232 if (EFI_ERROR (Status
)) {
236 *FirmwareVersion1
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
238 Status
= Tpm2GetCapability (
239 TPM_CAP_TPM_PROPERTIES
,
240 TPM_PT_FIRMWARE_VERSION_2
,
245 if (EFI_ERROR (Status
)) {
249 *FirmwareVersion2
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
255 This command returns the information of the maximum value for commandSize and responseSize in a command.
257 This function parse the value got from TPM2_GetCapability and return the max command size and response size
259 @param[out] MaxCommandSize The maximum value for commandSize in a command.
260 @param[out] MaxResponseSize The maximum value for responseSize in a command.
262 @retval EFI_SUCCESS Operation completed successfully.
263 @retval EFI_DEVICE_ERROR The command was unsuccessful.
267 Tpm2GetCapabilityMaxCommandResponseSize (
268 OUT UINT32
*MaxCommandSize
,
269 OUT UINT32
*MaxResponseSize
272 TPMS_CAPABILITY_DATA TpmCap
;
273 TPMI_YES_NO MoreData
;
276 Status
= Tpm2GetCapability (
277 TPM_CAP_TPM_PROPERTIES
,
278 TPM_PT_MAX_COMMAND_SIZE
,
283 if (EFI_ERROR (Status
)) {
287 *MaxCommandSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
289 Status
= Tpm2GetCapability (
290 TPM_CAP_TPM_PROPERTIES
,
291 TPM_PT_MAX_RESPONSE_SIZE
,
296 if (EFI_ERROR (Status
)) {
300 *MaxResponseSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
305 This command returns Returns a list of TPMS_ALG_PROPERTIES. Each entry is an
306 algorithm ID and a set of properties of the algorithm.
308 This function parse the value got from TPM2_GetCapability and return the list.
310 @param[out] AlgList List of algorithm.
312 @retval EFI_SUCCESS Operation completed successfully.
313 @retval EFI_DEVICE_ERROR The command was unsuccessful.
317 Tpm2GetCapabilitySupportedAlg (
318 OUT TPML_ALG_PROPERTY
*AlgList
321 TPMS_CAPABILITY_DATA TpmCap
;
322 TPMI_YES_NO MoreData
;
326 Status
= Tpm2GetCapability (
333 if (EFI_ERROR (Status
)) {
337 CopyMem (AlgList
, &TpmCap
.data
.algorithms
, sizeof (TPML_ALG_PROPERTY
));
339 AlgList
->count
= SwapBytes32 (AlgList
->count
);
340 if (AlgList
->count
> MAX_CAP_ALGS
) {
341 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilitySupportedAlg - AlgList->count error %x\n", AlgList
->count
));
342 return EFI_DEVICE_ERROR
;
345 for (Index
= 0; Index
< AlgList
->count
; Index
++) {
346 AlgList
->algProperties
[Index
].alg
= SwapBytes16 (AlgList
->algProperties
[Index
].alg
);
347 WriteUnaligned32 ((UINT32
*)&AlgList
->algProperties
[Index
].algProperties
, SwapBytes32 (ReadUnaligned32 ((UINT32
*)&AlgList
->algProperties
[Index
].algProperties
)));
354 This command returns the information of TPM LockoutCounter.
356 This function parse the value got from TPM2_GetCapability and return the LockoutCounter.
358 @param[out] LockoutCounter The LockoutCounter of TPM.
360 @retval EFI_SUCCESS Operation completed successfully.
361 @retval EFI_DEVICE_ERROR The command was unsuccessful.
365 Tpm2GetCapabilityLockoutCounter (
366 OUT UINT32
*LockoutCounter
369 TPMS_CAPABILITY_DATA TpmCap
;
370 TPMI_YES_NO MoreData
;
373 Status
= Tpm2GetCapability (
374 TPM_CAP_TPM_PROPERTIES
,
375 TPM_PT_LOCKOUT_COUNTER
,
380 if (EFI_ERROR (Status
)) {
384 *LockoutCounter
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
390 This command returns the information of TPM LockoutInterval.
392 This function parse the value got from TPM2_GetCapability and return the LockoutInterval.
394 @param[out] LockoutInterval The LockoutInterval of TPM.
396 @retval EFI_SUCCESS Operation completed successfully.
397 @retval EFI_DEVICE_ERROR The command was unsuccessful.
401 Tpm2GetCapabilityLockoutInterval (
402 OUT UINT32
*LockoutInterval
405 TPMS_CAPABILITY_DATA TpmCap
;
406 TPMI_YES_NO MoreData
;
409 Status
= Tpm2GetCapability (
410 TPM_CAP_TPM_PROPERTIES
,
411 TPM_PT_LOCKOUT_INTERVAL
,
416 if (EFI_ERROR (Status
)) {
420 *LockoutInterval
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
426 This command returns the information of TPM InputBufferSize.
428 This function parse the value got from TPM2_GetCapability and return the InputBufferSize.
430 @param[out] InputBufferSize The InputBufferSize of TPM.
431 the maximum size of a parameter (typically, a TPM2B_MAX_BUFFER)
433 @retval EFI_SUCCESS Operation completed successfully.
434 @retval EFI_DEVICE_ERROR The command was unsuccessful.
438 Tpm2GetCapabilityInputBufferSize (
439 OUT UINT32
*InputBufferSize
442 TPMS_CAPABILITY_DATA TpmCap
;
443 TPMI_YES_NO MoreData
;
446 Status
= Tpm2GetCapability (
447 TPM_CAP_TPM_PROPERTIES
,
453 if (EFI_ERROR (Status
)) {
457 *InputBufferSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
463 This command returns the information of TPM PCRs.
465 This function parse the value got from TPM2_GetCapability and return the PcrSelection.
467 @param[out] Pcrs The Pcr Selection
469 @retval EFI_SUCCESS Operation completed successfully.
470 @retval EFI_DEVICE_ERROR The command was unsuccessful.
474 Tpm2GetCapabilityPcrs (
475 OUT TPML_PCR_SELECTION
*Pcrs
478 TPMS_CAPABILITY_DATA TpmCap
;
479 TPMI_YES_NO MoreData
;
483 Status
= Tpm2GetCapability (
490 if (EFI_ERROR (Status
)) {
494 Pcrs
->count
= SwapBytes32 (TpmCap
.data
.assignedPCR
.count
);
495 if (Pcrs
->count
> HASH_COUNT
) {
496 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilityPcrs - Pcrs->count error %x\n", Pcrs
->count
));
497 return EFI_DEVICE_ERROR
;
500 for (Index
= 0; Index
< Pcrs
->count
; Index
++) {
501 Pcrs
->pcrSelections
[Index
].hash
= SwapBytes16 (TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].hash
);
502 Pcrs
->pcrSelections
[Index
].sizeofSelect
= TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].sizeofSelect
;
503 if (Pcrs
->pcrSelections
[Index
].sizeofSelect
> PCR_SELECT_MAX
) {
504 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilityPcrs - sizeofSelect error %x\n", Pcrs
->pcrSelections
[Index
].sizeofSelect
));
505 return EFI_DEVICE_ERROR
;
508 CopyMem (Pcrs
->pcrSelections
[Index
].pcrSelect
, TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].pcrSelect
, Pcrs
->pcrSelections
[Index
].sizeofSelect
);
515 This function will query the TPM to determine which hashing algorithms
516 are supported and which PCR banks are currently active.
518 @param[out] TpmHashAlgorithmBitmap A bitmask containing the algorithms supported by the TPM.
519 @param[out] ActivePcrBanks A bitmask containing the PCRs currently allocated.
521 @retval EFI_SUCCESS TPM was successfully queried and return values can be trusted.
522 @retval Others An error occurred, likely in communication with the TPM.
527 Tpm2GetCapabilitySupportedAndActivePcrs (
528 OUT UINT32
*TpmHashAlgorithmBitmap
,
529 OUT UINT32
*ActivePcrBanks
533 TPML_PCR_SELECTION Pcrs
;
535 UINT8 ActivePcrBankCount
;
540 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
541 DEBUG ((DEBUG_INFO
, "Supported PCRs - Count = %08x\n", Pcrs
.count
));
542 ActivePcrBankCount
= 0;
544 // If error, assume that we have at least SHA-1 (and return the error.)
546 if (EFI_ERROR (Status
)) {
547 DEBUG ((DEBUG_ERROR
, "GetSupportedAndActivePcrs - Tpm2GetCapabilityPcrs fail!\n"));
548 *TpmHashAlgorithmBitmap
= HASH_ALG_SHA1
;
549 *ActivePcrBanks
= HASH_ALG_SHA1
;
550 ActivePcrBankCount
= 1;
553 // Otherwise, process the return data to determine what algorithms are supported
554 // and currently allocated.
557 *TpmHashAlgorithmBitmap
= 0;
559 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
560 switch (Pcrs
.pcrSelections
[Index
].hash
) {
562 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 present.\n"));
563 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA1
;
564 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
565 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 active.\n"));
566 *ActivePcrBanks
|= HASH_ALG_SHA1
;
567 ActivePcrBankCount
++;
572 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 present.\n"));
573 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA256
;
574 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
575 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 active.\n"));
576 *ActivePcrBanks
|= HASH_ALG_SHA256
;
577 ActivePcrBankCount
++;
582 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 present.\n"));
583 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA384
;
584 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
585 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 active.\n"));
586 *ActivePcrBanks
|= HASH_ALG_SHA384
;
587 ActivePcrBankCount
++;
592 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 present.\n"));
593 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA512
;
594 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
595 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 active.\n"));
596 *ActivePcrBanks
|= HASH_ALG_SHA512
;
597 ActivePcrBankCount
++;
601 case TPM_ALG_SM3_256
:
602 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 present.\n"));
603 *TpmHashAlgorithmBitmap
|= HASH_ALG_SM3_256
;
604 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
605 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 active.\n"));
606 *ActivePcrBanks
|= HASH_ALG_SM3_256
;
607 ActivePcrBankCount
++;
612 DEBUG ((DEBUG_VERBOSE
, "GetSupportedAndActivePcrs - Unsupported bank 0x%04x.\n", Pcrs
.pcrSelections
[Index
].hash
));
619 DEBUG ((DEBUG_INFO
, "GetSupportedAndActivePcrs - Count = %08x\n", ActivePcrBankCount
));
624 This command returns the information of TPM AlgorithmSet.
626 This function parse the value got from TPM2_GetCapability and return the AlgorithmSet.
628 @param[out] AlgorithmSet The AlgorithmSet of TPM.
630 @retval EFI_SUCCESS Operation completed successfully.
631 @retval EFI_DEVICE_ERROR The command was unsuccessful.
635 Tpm2GetCapabilityAlgorithmSet (
636 OUT UINT32
*AlgorithmSet
639 TPMS_CAPABILITY_DATA TpmCap
;
640 TPMI_YES_NO MoreData
;
643 Status
= Tpm2GetCapability (
644 TPM_CAP_TPM_PROPERTIES
,
645 TPM_PT_ALGORITHM_SET
,
650 if (EFI_ERROR (Status
)) {
654 *AlgorithmSet
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
660 This function will query if the command is supported.
662 @param[In] Command TPM_CC command starts from TPM_CC_FIRST.
663 @param[out] IsCmdImpl The command is supported or not.
665 @retval EFI_SUCCESS Operation completed successfully.
666 @retval EFI_DEVICE_ERROR The command was unsuccessful.
670 Tpm2GetCapabilityIsCommandImplemented (
672 OUT BOOLEAN
*IsCmdImpl
675 TPMS_CAPABILITY_DATA TpmCap
;
676 TPMI_YES_NO MoreData
;
680 Status
= Tpm2GetCapability (
687 if (EFI_ERROR (Status
)) {
691 CopyMem (&Attribute
, &TpmCap
.data
.command
.commandAttributes
[0], sizeof (UINT32
));
692 *IsCmdImpl
= (Command
== (SwapBytes32 (Attribute
) & TPMA_CC_COMMANDINDEX_MASK
));
698 This command is used to check to see if specific combinations of algorithm parameters are supported.
700 @param[in] Parameters Algorithm parameters to be validated
702 @retval EFI_SUCCESS Operation completed successfully.
703 @retval EFI_DEVICE_ERROR Unexpected device behavior.
708 IN TPMT_PUBLIC_PARMS
*Parameters
712 TPM2_TEST_PARMS_COMMAND SendBuffer
;
713 TPM2_TEST_PARMS_RESPONSE RecvBuffer
;
714 UINT32 SendBufferSize
;
715 UINT32 RecvBufferSize
;
721 SendBuffer
.Header
.tag
= SwapBytes16 (TPM_ST_NO_SESSIONS
);
722 SendBuffer
.Header
.commandCode
= SwapBytes32 (TPM_CC_TestParms
);
724 Buffer
= (UINT8
*)&SendBuffer
.Parameters
;
725 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->type
));
726 Buffer
+= sizeof (UINT16
);
727 switch (Parameters
->type
) {
728 case TPM_ALG_KEYEDHASH
:
729 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
));
730 Buffer
+= sizeof (UINT16
);
731 switch (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
) {
733 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.hmac
.hashAlg
));
734 Buffer
+= sizeof (UINT16
);
737 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.hashAlg
));
738 Buffer
+= sizeof (UINT16
);
739 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.kdf
));
740 Buffer
+= sizeof (UINT16
);
743 return EFI_INVALID_PARAMETER
;
746 case TPM_ALG_SYMCIPHER
:
747 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.algorithm
));
748 Buffer
+= sizeof (UINT16
);
749 switch (Parameters
->parameters
.symDetail
.algorithm
) {
751 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.aes
));
752 Buffer
+= sizeof (UINT16
);
753 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.aes
));
754 Buffer
+= sizeof (UINT16
);
757 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.SM4
));
758 Buffer
+= sizeof (UINT16
);
759 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.SM4
));
760 Buffer
+= sizeof (UINT16
);
763 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.xor));
764 Buffer
+= sizeof (UINT16
);
769 return EFI_INVALID_PARAMETER
;
774 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
));
775 Buffer
+= sizeof (UINT16
);
776 switch (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
) {
778 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.aes
));
779 Buffer
+= sizeof (UINT16
);
780 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.aes
));
781 Buffer
+= sizeof (UINT16
);
784 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.SM4
));
785 Buffer
+= sizeof (UINT16
);
786 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.SM4
));
787 Buffer
+= sizeof (UINT16
);
792 return EFI_INVALID_PARAMETER
;
795 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.scheme
));
796 Buffer
+= sizeof (UINT16
);
797 switch (Parameters
->parameters
.rsaDetail
.scheme
.scheme
) {
799 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsassa
.hashAlg
));
800 Buffer
+= sizeof (UINT16
);
803 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsapss
.hashAlg
));
804 Buffer
+= sizeof (UINT16
);
809 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.oaep
.hashAlg
));
810 Buffer
+= sizeof (UINT16
);
815 return EFI_INVALID_PARAMETER
;
818 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.keyBits
));
819 Buffer
+= sizeof (UINT16
);
820 WriteUnaligned32 ((UINT32
*)Buffer
, SwapBytes32 (Parameters
->parameters
.rsaDetail
.exponent
));
821 Buffer
+= sizeof (UINT32
);
824 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
));
825 Buffer
+= sizeof (UINT16
);
826 switch (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
) {
828 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.aes
));
829 Buffer
+= sizeof (UINT16
);
830 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.aes
));
831 Buffer
+= sizeof (UINT16
);
834 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.SM4
));
835 Buffer
+= sizeof (UINT16
);
836 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.SM4
));
837 Buffer
+= sizeof (UINT16
);
842 return EFI_INVALID_PARAMETER
;
845 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.scheme
));
846 Buffer
+= sizeof (UINT16
);
847 switch (Parameters
->parameters
.eccDetail
.scheme
.scheme
) {
849 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdsa
.hashAlg
));
850 Buffer
+= sizeof (UINT16
);
853 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdaa
.hashAlg
));
854 Buffer
+= sizeof (UINT16
);
856 case TPM_ALG_ECSCHNORR
:
857 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecSchnorr
.hashAlg
));
858 Buffer
+= sizeof (UINT16
);
865 return EFI_INVALID_PARAMETER
;
868 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.curveID
));
869 Buffer
+= sizeof (UINT16
);
870 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.scheme
));
871 Buffer
+= sizeof (UINT16
);
872 switch (Parameters
->parameters
.eccDetail
.kdf
.scheme
) {
874 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.mgf1
.hashAlg
));
875 Buffer
+= sizeof (UINT16
);
877 case TPM_ALG_KDF1_SP800_108
:
878 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_sp800_108
.hashAlg
));
879 Buffer
+= sizeof (UINT16
);
881 case TPM_ALG_KDF1_SP800_56a
:
882 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_SP800_56a
.hashAlg
));
883 Buffer
+= sizeof (UINT16
);
886 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf2
.hashAlg
));
887 Buffer
+= sizeof (UINT16
);
892 return EFI_INVALID_PARAMETER
;
897 return EFI_INVALID_PARAMETER
;
900 SendBufferSize
= (UINT32
)((UINTN
)Buffer
- (UINTN
)&SendBuffer
);
901 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
906 RecvBufferSize
= sizeof (RecvBuffer
);
907 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
908 if (EFI_ERROR (Status
)) {
912 if (RecvBufferSize
< sizeof (TPM2_RESPONSE_HEADER
)) {
913 DEBUG ((DEBUG_ERROR
, "Tpm2TestParms - RecvBufferSize Error - %x\n", RecvBufferSize
));
914 return EFI_DEVICE_ERROR
;
917 if (SwapBytes32 (RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
918 DEBUG ((DEBUG_ERROR
, "Tpm2TestParms - responseCode - %x\n", SwapBytes32 (RecvBuffer
.Header
.responseCode
)));
919 return EFI_UNSUPPORTED
;