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 ((EFI_D_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
)) {
161 CopyMem (Family
, &TpmCap
.data
.tpmProperties
.tpmProperty
->value
, 4);
167 This command returns the information of TPM manufacture ID.
169 This function parse the value got from TPM2_GetCapability and return the TPM manufacture ID.
171 @param[out] ManufactureId The manufacture ID of TPM.
173 @retval EFI_SUCCESS Operation completed successfully.
174 @retval EFI_DEVICE_ERROR The command was unsuccessful.
178 Tpm2GetCapabilityManufactureID (
179 OUT UINT32
*ManufactureId
182 TPMS_CAPABILITY_DATA TpmCap
;
183 TPMI_YES_NO MoreData
;
186 Status
= Tpm2GetCapability (
187 TPM_CAP_TPM_PROPERTIES
,
193 if (EFI_ERROR (Status
)) {
196 *ManufactureId
= TpmCap
.data
.tpmProperties
.tpmProperty
->value
;
202 This command returns the information of TPM FirmwareVersion.
204 This function parse the value got from TPM2_GetCapability and return the TPM FirmwareVersion.
206 @param[out] FirmwareVersion1 The FirmwareVersion1.
207 @param[out] FirmwareVersion2 The FirmwareVersion2.
209 @retval EFI_SUCCESS Operation completed successfully.
210 @retval EFI_DEVICE_ERROR The command was unsuccessful.
214 Tpm2GetCapabilityFirmwareVersion (
215 OUT UINT32
*FirmwareVersion1
,
216 OUT UINT32
*FirmwareVersion2
219 TPMS_CAPABILITY_DATA TpmCap
;
220 TPMI_YES_NO MoreData
;
223 Status
= Tpm2GetCapability (
224 TPM_CAP_TPM_PROPERTIES
,
225 TPM_PT_FIRMWARE_VERSION_1
,
230 if (EFI_ERROR (Status
)) {
233 *FirmwareVersion1
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
235 Status
= Tpm2GetCapability (
236 TPM_CAP_TPM_PROPERTIES
,
237 TPM_PT_FIRMWARE_VERSION_2
,
242 if (EFI_ERROR (Status
)) {
245 *FirmwareVersion2
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
251 This command returns the information of the maximum value for commandSize and responseSize in a command.
253 This function parse the value got from TPM2_GetCapability and return the max command size and response size
255 @param[out] MaxCommandSize The maximum value for commandSize in a command.
256 @param[out] MaxResponseSize The maximum value for responseSize in a command.
258 @retval EFI_SUCCESS Operation completed successfully.
259 @retval EFI_DEVICE_ERROR The command was unsuccessful.
263 Tpm2GetCapabilityMaxCommandResponseSize (
264 OUT UINT32
*MaxCommandSize
,
265 OUT UINT32
*MaxResponseSize
268 TPMS_CAPABILITY_DATA TpmCap
;
269 TPMI_YES_NO MoreData
;
272 Status
= Tpm2GetCapability (
273 TPM_CAP_TPM_PROPERTIES
,
274 TPM_PT_MAX_COMMAND_SIZE
,
279 if (EFI_ERROR (Status
)) {
283 *MaxCommandSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
285 Status
= Tpm2GetCapability (
286 TPM_CAP_TPM_PROPERTIES
,
287 TPM_PT_MAX_RESPONSE_SIZE
,
292 if (EFI_ERROR (Status
)) {
296 *MaxResponseSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
301 This command returns Returns a list of TPMS_ALG_PROPERTIES. Each entry is an
302 algorithm ID and a set of properties of the algorithm.
304 This function parse the value got from TPM2_GetCapability and return the list.
306 @param[out] AlgList List of algorithm.
308 @retval EFI_SUCCESS Operation completed successfully.
309 @retval EFI_DEVICE_ERROR The command was unsuccessful.
313 Tpm2GetCapabilitySupportedAlg (
314 OUT TPML_ALG_PROPERTY
*AlgList
317 TPMS_CAPABILITY_DATA TpmCap
;
318 TPMI_YES_NO MoreData
;
322 Status
= Tpm2GetCapability (
329 if (EFI_ERROR (Status
)) {
333 CopyMem (AlgList
, &TpmCap
.data
.algorithms
, sizeof (TPML_ALG_PROPERTY
));
335 AlgList
->count
= SwapBytes32 (AlgList
->count
);
336 if (AlgList
->count
> MAX_CAP_ALGS
) {
337 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilitySupportedAlg - AlgList->count error %x\n", AlgList
->count
));
338 return EFI_DEVICE_ERROR
;
341 for (Index
= 0; Index
< AlgList
->count
; Index
++) {
342 AlgList
->algProperties
[Index
].alg
= SwapBytes16 (AlgList
->algProperties
[Index
].alg
);
343 WriteUnaligned32 ((UINT32
*)&AlgList
->algProperties
[Index
].algProperties
, SwapBytes32 (ReadUnaligned32 ((UINT32
*)&AlgList
->algProperties
[Index
].algProperties
)));
350 This command returns the information of TPM LockoutCounter.
352 This function parse the value got from TPM2_GetCapability and return the LockoutCounter.
354 @param[out] LockoutCounter The LockoutCounter of TPM.
356 @retval EFI_SUCCESS Operation completed successfully.
357 @retval EFI_DEVICE_ERROR The command was unsuccessful.
361 Tpm2GetCapabilityLockoutCounter (
362 OUT UINT32
*LockoutCounter
365 TPMS_CAPABILITY_DATA TpmCap
;
366 TPMI_YES_NO MoreData
;
369 Status
= Tpm2GetCapability (
370 TPM_CAP_TPM_PROPERTIES
,
371 TPM_PT_LOCKOUT_COUNTER
,
376 if (EFI_ERROR (Status
)) {
379 *LockoutCounter
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
385 This command returns the information of TPM LockoutInterval.
387 This function parse the value got from TPM2_GetCapability and return the LockoutInterval.
389 @param[out] LockoutInterval The LockoutInterval of TPM.
391 @retval EFI_SUCCESS Operation completed successfully.
392 @retval EFI_DEVICE_ERROR The command was unsuccessful.
396 Tpm2GetCapabilityLockoutInterval (
397 OUT UINT32
*LockoutInterval
400 TPMS_CAPABILITY_DATA TpmCap
;
401 TPMI_YES_NO MoreData
;
404 Status
= Tpm2GetCapability (
405 TPM_CAP_TPM_PROPERTIES
,
406 TPM_PT_LOCKOUT_INTERVAL
,
411 if (EFI_ERROR (Status
)) {
414 *LockoutInterval
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
420 This command returns the information of TPM InputBufferSize.
422 This function parse the value got from TPM2_GetCapability and return the InputBufferSize.
424 @param[out] InputBufferSize The InputBufferSize of TPM.
425 the maximum size of a parameter (typically, a TPM2B_MAX_BUFFER)
427 @retval EFI_SUCCESS Operation completed successfully.
428 @retval EFI_DEVICE_ERROR The command was unsuccessful.
432 Tpm2GetCapabilityInputBufferSize (
433 OUT UINT32
*InputBufferSize
436 TPMS_CAPABILITY_DATA TpmCap
;
437 TPMI_YES_NO MoreData
;
440 Status
= Tpm2GetCapability (
441 TPM_CAP_TPM_PROPERTIES
,
447 if (EFI_ERROR (Status
)) {
450 *InputBufferSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
456 This command returns the information of TPM PCRs.
458 This function parse the value got from TPM2_GetCapability and return the PcrSelection.
460 @param[out] Pcrs The Pcr Selection
462 @retval EFI_SUCCESS Operation completed successfully.
463 @retval EFI_DEVICE_ERROR The command was unsuccessful.
467 Tpm2GetCapabilityPcrs (
468 OUT TPML_PCR_SELECTION
*Pcrs
471 TPMS_CAPABILITY_DATA TpmCap
;
472 TPMI_YES_NO MoreData
;
476 Status
= Tpm2GetCapability (
483 if (EFI_ERROR (Status
)) {
487 Pcrs
->count
= SwapBytes32 (TpmCap
.data
.assignedPCR
.count
);
488 if (Pcrs
->count
> HASH_COUNT
) {
489 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilityPcrs - Pcrs->count error %x\n", Pcrs
->count
));
490 return EFI_DEVICE_ERROR
;
493 for (Index
= 0; Index
< Pcrs
->count
; Index
++) {
494 Pcrs
->pcrSelections
[Index
].hash
= SwapBytes16 (TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].hash
);
495 Pcrs
->pcrSelections
[Index
].sizeofSelect
= TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].sizeofSelect
;
496 if (Pcrs
->pcrSelections
[Index
].sizeofSelect
> PCR_SELECT_MAX
) {
497 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilityPcrs - sizeofSelect error %x\n", Pcrs
->pcrSelections
[Index
].sizeofSelect
));
498 return EFI_DEVICE_ERROR
;
500 CopyMem (Pcrs
->pcrSelections
[Index
].pcrSelect
, TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].pcrSelect
, Pcrs
->pcrSelections
[Index
].sizeofSelect
);
507 This function will query the TPM to determine which hashing algorithms
508 are supported and which PCR banks are currently active.
510 @param[out] TpmHashAlgorithmBitmap A bitmask containing the algorithms supported by the TPM.
511 @param[out] ActivePcrBanks A bitmask containing the PCRs currently allocated.
513 @retval EFI_SUCCESS TPM was successfully queried and return values can be trusted.
514 @retval Others An error occurred, likely in communication with the TPM.
519 Tpm2GetCapabilitySupportedAndActivePcrs (
520 OUT UINT32
*TpmHashAlgorithmBitmap
,
521 OUT UINT32
*ActivePcrBanks
525 TPML_PCR_SELECTION Pcrs
;
529 // Get supported PCR and current Active PCRs.
531 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
534 // If error, assume that we have at least SHA-1 (and return the error.)
536 if (EFI_ERROR (Status
)) {
537 DEBUG ((EFI_D_ERROR
, "GetSupportedAndActivePcrs - Tpm2GetCapabilityPcrs fail!\n"));
538 *TpmHashAlgorithmBitmap
= HASH_ALG_SHA1
;
539 *ActivePcrBanks
= HASH_ALG_SHA1
;
542 // Otherwise, process the return data to determine what algorithms are supported
543 // and currently allocated.
546 DEBUG ((EFI_D_INFO
, "GetSupportedAndActivePcrs - Count = %08x\n", Pcrs
.count
));
547 *TpmHashAlgorithmBitmap
= 0;
549 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
550 switch (Pcrs
.pcrSelections
[Index
].hash
) {
552 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 present.\n"));
553 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA1
;
554 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
555 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 active.\n"));
556 *ActivePcrBanks
|= HASH_ALG_SHA1
;
560 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 present.\n"));
561 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA256
;
562 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
563 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 active.\n"));
564 *ActivePcrBanks
|= HASH_ALG_SHA256
;
568 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 present.\n"));
569 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA384
;
570 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
571 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 active.\n"));
572 *ActivePcrBanks
|= HASH_ALG_SHA384
;
576 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 present.\n"));
577 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA512
;
578 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
579 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 active.\n"));
580 *ActivePcrBanks
|= HASH_ALG_SHA512
;
583 case TPM_ALG_SM3_256
:
584 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 present.\n"));
585 *TpmHashAlgorithmBitmap
|= HASH_ALG_SM3_256
;
586 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
587 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 active.\n"));
588 *ActivePcrBanks
|= HASH_ALG_SM3_256
;
599 This command returns the information of TPM AlgorithmSet.
601 This function parse the value got from TPM2_GetCapability and return the AlgorithmSet.
603 @param[out] AlgorithmSet The AlgorithmSet of TPM.
605 @retval EFI_SUCCESS Operation completed successfully.
606 @retval EFI_DEVICE_ERROR The command was unsuccessful.
610 Tpm2GetCapabilityAlgorithmSet (
611 OUT UINT32
*AlgorithmSet
614 TPMS_CAPABILITY_DATA TpmCap
;
615 TPMI_YES_NO MoreData
;
618 Status
= Tpm2GetCapability (
619 TPM_CAP_TPM_PROPERTIES
,
620 TPM_PT_ALGORITHM_SET
,
625 if (EFI_ERROR (Status
)) {
628 *AlgorithmSet
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
634 This function will query if the command is supported.
636 @param[In] Command TPM_CC command starts from TPM_CC_FIRST.
637 @param[out] IsCmdImpl The command is supported or not.
639 @retval EFI_SUCCESS Operation completed successfully.
640 @retval EFI_DEVICE_ERROR The command was unsuccessful.
644 Tpm2GetCapabilityIsCommandImplemented (
646 OUT BOOLEAN
*IsCmdImpl
649 TPMS_CAPABILITY_DATA TpmCap
;
650 TPMI_YES_NO MoreData
;
654 Status
= Tpm2GetCapability (
661 if (EFI_ERROR (Status
)) {
665 CopyMem (&Attribute
, &TpmCap
.data
.command
.commandAttributes
[0], sizeof (UINT32
));
666 *IsCmdImpl
= (Command
== (SwapBytes32(Attribute
) & TPMA_CC_COMMANDINDEX_MASK
));
672 This command is used to check to see if specific combinations of algorithm parameters are supported.
674 @param[in] Parameters Algorithm parameters to be validated
676 @retval EFI_SUCCESS Operation completed successfully.
677 @retval EFI_DEVICE_ERROR Unexpected device behavior.
682 IN TPMT_PUBLIC_PARMS
*Parameters
686 TPM2_TEST_PARMS_COMMAND SendBuffer
;
687 TPM2_TEST_PARMS_RESPONSE RecvBuffer
;
688 UINT32 SendBufferSize
;
689 UINT32 RecvBufferSize
;
695 SendBuffer
.Header
.tag
= SwapBytes16(TPM_ST_NO_SESSIONS
);
696 SendBuffer
.Header
.commandCode
= SwapBytes32(TPM_CC_TestParms
);
698 Buffer
= (UINT8
*)&SendBuffer
.Parameters
;
699 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->type
));
700 Buffer
+= sizeof(UINT16
);
701 switch (Parameters
->type
) {
702 case TPM_ALG_KEYEDHASH
:
703 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
));
704 Buffer
+= sizeof(UINT16
);
705 switch (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
) {
707 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.hmac
.hashAlg
));
708 Buffer
+= sizeof(UINT16
);
711 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.hashAlg
));
712 Buffer
+= sizeof(UINT16
);
713 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.kdf
));
714 Buffer
+= sizeof(UINT16
);
717 return EFI_INVALID_PARAMETER
;
719 case TPM_ALG_SYMCIPHER
:
720 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.algorithm
));
721 Buffer
+= sizeof(UINT16
);
722 switch (Parameters
->parameters
.symDetail
.algorithm
) {
724 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.aes
));
725 Buffer
+= sizeof(UINT16
);
726 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.aes
));
727 Buffer
+= sizeof(UINT16
);
730 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.SM4
));
731 Buffer
+= sizeof(UINT16
);
732 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.SM4
));
733 Buffer
+= sizeof(UINT16
);
736 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.xor));
737 Buffer
+= sizeof(UINT16
);
742 return EFI_INVALID_PARAMETER
;
746 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
));
747 Buffer
+= sizeof(UINT16
);
748 switch (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
) {
750 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.aes
));
751 Buffer
+= sizeof(UINT16
);
752 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.aes
));
753 Buffer
+= sizeof(UINT16
);
756 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.SM4
));
757 Buffer
+= sizeof(UINT16
);
758 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.SM4
));
759 Buffer
+= sizeof(UINT16
);
764 return EFI_INVALID_PARAMETER
;
766 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.scheme
));
767 Buffer
+= sizeof(UINT16
);
768 switch (Parameters
->parameters
.rsaDetail
.scheme
.scheme
) {
770 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsassa
.hashAlg
));
771 Buffer
+= sizeof(UINT16
);
774 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsapss
.hashAlg
));
775 Buffer
+= sizeof(UINT16
);
780 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.oaep
.hashAlg
));
781 Buffer
+= sizeof(UINT16
);
786 return EFI_INVALID_PARAMETER
;
788 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.keyBits
));
789 Buffer
+= sizeof(UINT16
);
790 WriteUnaligned32 ((UINT32
*)Buffer
, SwapBytes32 (Parameters
->parameters
.rsaDetail
.exponent
));
791 Buffer
+= sizeof(UINT32
);
794 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
));
795 Buffer
+= sizeof(UINT16
);
796 switch (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
) {
798 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.aes
));
799 Buffer
+= sizeof(UINT16
);
800 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.aes
));
801 Buffer
+= sizeof(UINT16
);
804 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.SM4
));
805 Buffer
+= sizeof(UINT16
);
806 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.SM4
));
807 Buffer
+= sizeof(UINT16
);
812 return EFI_INVALID_PARAMETER
;
814 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.scheme
));
815 Buffer
+= sizeof(UINT16
);
816 switch (Parameters
->parameters
.eccDetail
.scheme
.scheme
) {
818 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdsa
.hashAlg
));
819 Buffer
+= sizeof(UINT16
);
822 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdaa
.hashAlg
));
823 Buffer
+= sizeof(UINT16
);
825 case TPM_ALG_ECSCHNORR
:
826 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecSchnorr
.hashAlg
));
827 Buffer
+= sizeof(UINT16
);
834 return EFI_INVALID_PARAMETER
;
836 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.curveID
));
837 Buffer
+= sizeof(UINT16
);
838 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.scheme
));
839 Buffer
+= sizeof(UINT16
);
840 switch (Parameters
->parameters
.eccDetail
.kdf
.scheme
) {
842 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.mgf1
.hashAlg
));
843 Buffer
+= sizeof(UINT16
);
845 case TPM_ALG_KDF1_SP800_108
:
846 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_sp800_108
.hashAlg
));
847 Buffer
+= sizeof(UINT16
);
849 case TPM_ALG_KDF1_SP800_56a
:
850 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_SP800_56a
.hashAlg
));
851 Buffer
+= sizeof(UINT16
);
854 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf2
.hashAlg
));
855 Buffer
+= sizeof(UINT16
);
860 return EFI_INVALID_PARAMETER
;
864 return EFI_INVALID_PARAMETER
;
867 SendBufferSize
= (UINT32
)((UINTN
)Buffer
- (UINTN
)&SendBuffer
);
868 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
873 RecvBufferSize
= sizeof (RecvBuffer
);
874 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
875 if (EFI_ERROR (Status
)) {
879 if (RecvBufferSize
< sizeof (TPM2_RESPONSE_HEADER
)) {
880 DEBUG ((EFI_D_ERROR
, "Tpm2TestParms - RecvBufferSize Error - %x\n", RecvBufferSize
));
881 return EFI_DEVICE_ERROR
;
883 if (SwapBytes32(RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
884 DEBUG ((EFI_D_ERROR
, "Tpm2TestParms - responseCode - %x\n", SwapBytes32(RecvBuffer
.Header
.responseCode
)));
885 return EFI_UNSUPPORTED
;