2 Implement TPM2 Capability related command.
4 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <IndustryStandard/UefiTcgPlatform.h>
16 #include <Library/Tpm2CommandLib.h>
17 #include <Library/Tpm2DeviceLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
25 TPM2_COMMAND_HEADER Header
;
29 } TPM2_GET_CAPABILITY_COMMAND
;
32 TPM2_RESPONSE_HEADER Header
;
34 TPMS_CAPABILITY_DATA CapabilityData
;
35 } TPM2_GET_CAPABILITY_RESPONSE
;
38 TPM2_COMMAND_HEADER Header
;
39 TPMT_PUBLIC_PARMS Parameters
;
40 } TPM2_TEST_PARMS_COMMAND
;
43 TPM2_RESPONSE_HEADER Header
;
44 } TPM2_TEST_PARMS_RESPONSE
;
49 This command returns various information regarding the TPM and its current state.
51 The capability parameter determines the category of data returned. The property parameter
52 selects the first value of the selected category to be returned. If there is no property
53 that corresponds to the value of property, the next higher value is returned, if it exists.
54 The moreData parameter will have a value of YES if there are more values of the requested
55 type that were not returned.
56 If no next capability exists, the TPM will return a zero-length list and moreData will have
60 To simplify this function, leave returned CapabilityData for caller to unpack since there are
61 many capability categories and only few categories will be used in firmware. It means the caller
62 need swap the byte order for the feilds in CapabilityData.
64 @param[in] Capability Group selection; determines the format of the response.
65 @param[in] Property Further definition of information.
66 @param[in] PropertyCount Number of properties of the indicated type to return.
67 @param[out] MoreData Flag to indicate if there are more values of this type.
68 @param[out] CapabilityData The capability data.
70 @retval EFI_SUCCESS Operation completed successfully.
71 @retval EFI_DEVICE_ERROR The command was unsuccessful.
76 IN TPM_CAP Capability
,
78 IN UINT32 PropertyCount
,
79 OUT TPMI_YES_NO
*MoreData
,
80 OUT TPMS_CAPABILITY_DATA
*CapabilityData
84 TPM2_GET_CAPABILITY_COMMAND SendBuffer
;
85 TPM2_GET_CAPABILITY_RESPONSE RecvBuffer
;
86 UINT32 SendBufferSize
;
87 UINT32 RecvBufferSize
;
92 SendBuffer
.Header
.tag
= SwapBytes16(TPM_ST_NO_SESSIONS
);
93 SendBuffer
.Header
.commandCode
= SwapBytes32(TPM_CC_GetCapability
);
95 SendBuffer
.Capability
= SwapBytes32 (Capability
);
96 SendBuffer
.Property
= SwapBytes32 (Property
);
97 SendBuffer
.PropertyCount
= SwapBytes32 (PropertyCount
);
99 SendBufferSize
= (UINT32
) sizeof (SendBuffer
);
100 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
105 RecvBufferSize
= sizeof (RecvBuffer
);
106 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
107 if (EFI_ERROR (Status
)) {
111 if (RecvBufferSize
<= sizeof (TPM2_RESPONSE_HEADER
) + sizeof (UINT8
)) {
112 return EFI_DEVICE_ERROR
;
116 // Fail if command failed
118 if (SwapBytes32(RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
119 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapability: Response Code error! 0x%08x\r\n", SwapBytes32(RecvBuffer
.Header
.responseCode
)));
120 return EFI_DEVICE_ERROR
;
124 // Return the response
126 *MoreData
= RecvBuffer
.MoreData
;
128 // Does not unpack all possiable property here, the caller should unpack it and note the byte order.
130 CopyMem (CapabilityData
, &RecvBuffer
.CapabilityData
, RecvBufferSize
- sizeof (TPM2_RESPONSE_HEADER
) - sizeof (UINT8
));
136 This command returns the information of TPM Family.
138 This function parse the value got from TPM2_GetCapability and return the Family.
140 @param[out] Family The Family of TPM. (a 4-octet character string)
142 @retval EFI_SUCCESS Operation completed successfully.
143 @retval EFI_DEVICE_ERROR The command was unsuccessful.
147 Tpm2GetCapabilityFamily (
151 TPMS_CAPABILITY_DATA TpmCap
;
152 TPMI_YES_NO MoreData
;
155 Status
= Tpm2GetCapability (
156 TPM_CAP_TPM_PROPERTIES
,
157 TPM_PT_FAMILY_INDICATOR
,
162 if (EFI_ERROR (Status
)) {
165 CopyMem (Family
, &TpmCap
.data
.tpmProperties
.tpmProperty
->value
, 4);
171 This command returns the information of TPM manufacture ID.
173 This function parse the value got from TPM2_GetCapability and return the TPM manufacture ID.
175 @param[out] ManufactureId The manufacture ID of TPM.
177 @retval EFI_SUCCESS Operation completed successfully.
178 @retval EFI_DEVICE_ERROR The command was unsuccessful.
182 Tpm2GetCapabilityManufactureID (
183 OUT UINT32
*ManufactureId
186 TPMS_CAPABILITY_DATA TpmCap
;
187 TPMI_YES_NO MoreData
;
190 Status
= Tpm2GetCapability (
191 TPM_CAP_TPM_PROPERTIES
,
197 if (EFI_ERROR (Status
)) {
200 *ManufactureId
= TpmCap
.data
.tpmProperties
.tpmProperty
->value
;
206 This command returns the information of TPM FirmwareVersion.
208 This function parse the value got from TPM2_GetCapability and return the TPM FirmwareVersion.
210 @param[out] FirmwareVersion1 The FirmwareVersion1.
211 @param[out] FirmwareVersion2 The FirmwareVersion2.
213 @retval EFI_SUCCESS Operation completed successfully.
214 @retval EFI_DEVICE_ERROR The command was unsuccessful.
218 Tpm2GetCapabilityFirmwareVersion (
219 OUT UINT32
*FirmwareVersion1
,
220 OUT UINT32
*FirmwareVersion2
223 TPMS_CAPABILITY_DATA TpmCap
;
224 TPMI_YES_NO MoreData
;
227 Status
= Tpm2GetCapability (
228 TPM_CAP_TPM_PROPERTIES
,
229 TPM_PT_FIRMWARE_VERSION_1
,
234 if (EFI_ERROR (Status
)) {
237 *FirmwareVersion1
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
239 Status
= Tpm2GetCapability (
240 TPM_CAP_TPM_PROPERTIES
,
241 TPM_PT_FIRMWARE_VERSION_2
,
246 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
)) {
383 *LockoutCounter
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
389 This command returns the information of TPM LockoutInterval.
391 This function parse the value got from TPM2_GetCapability and return the LockoutInterval.
393 @param[out] LockoutInterval The LockoutInterval of TPM.
395 @retval EFI_SUCCESS Operation completed successfully.
396 @retval EFI_DEVICE_ERROR The command was unsuccessful.
400 Tpm2GetCapabilityLockoutInterval (
401 OUT UINT32
*LockoutInterval
404 TPMS_CAPABILITY_DATA TpmCap
;
405 TPMI_YES_NO MoreData
;
408 Status
= Tpm2GetCapability (
409 TPM_CAP_TPM_PROPERTIES
,
410 TPM_PT_LOCKOUT_INTERVAL
,
415 if (EFI_ERROR (Status
)) {
418 *LockoutInterval
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
424 This command returns the information of TPM InputBufferSize.
426 This function parse the value got from TPM2_GetCapability and return the InputBufferSize.
428 @param[out] InputBufferSize The InputBufferSize of TPM.
429 the maximum size of a parameter (typically, a TPM2B_MAX_BUFFER)
431 @retval EFI_SUCCESS Operation completed successfully.
432 @retval EFI_DEVICE_ERROR The command was unsuccessful.
436 Tpm2GetCapabilityInputBufferSize (
437 OUT UINT32
*InputBufferSize
440 TPMS_CAPABILITY_DATA TpmCap
;
441 TPMI_YES_NO MoreData
;
444 Status
= Tpm2GetCapability (
445 TPM_CAP_TPM_PROPERTIES
,
451 if (EFI_ERROR (Status
)) {
454 *InputBufferSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
460 This command returns the information of TPM PCRs.
462 This function parse the value got from TPM2_GetCapability and return the PcrSelection.
464 @param[out] Pcrs The Pcr Selection
466 @retval EFI_SUCCESS Operation completed successfully.
467 @retval EFI_DEVICE_ERROR The command was unsuccessful.
471 Tpm2GetCapabilityPcrs (
472 OUT TPML_PCR_SELECTION
*Pcrs
475 TPMS_CAPABILITY_DATA TpmCap
;
476 TPMI_YES_NO MoreData
;
480 Status
= Tpm2GetCapability (
487 if (EFI_ERROR (Status
)) {
491 Pcrs
->count
= SwapBytes32 (TpmCap
.data
.assignedPCR
.count
);
492 if (Pcrs
->count
> HASH_COUNT
) {
493 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilityPcrs - Pcrs->count error %x\n", Pcrs
->count
));
494 return EFI_DEVICE_ERROR
;
497 for (Index
= 0; Index
< Pcrs
->count
; Index
++) {
498 Pcrs
->pcrSelections
[Index
].hash
= SwapBytes16 (TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].hash
);
499 Pcrs
->pcrSelections
[Index
].sizeofSelect
= TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].sizeofSelect
;
500 if (Pcrs
->pcrSelections
[Index
].sizeofSelect
> PCR_SELECT_MAX
) {
501 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilityPcrs - sizeofSelect error %x\n", Pcrs
->pcrSelections
[Index
].sizeofSelect
));
502 return EFI_DEVICE_ERROR
;
504 CopyMem (Pcrs
->pcrSelections
[Index
].pcrSelect
, TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].pcrSelect
, Pcrs
->pcrSelections
[Index
].sizeofSelect
);
511 This function will query the TPM to determine which hashing algorithms
512 are supported and which PCR banks are currently active.
514 @param[out] TpmHashAlgorithmBitmap A bitmask containing the algorithms supported by the TPM.
515 @param[out] ActivePcrBanks A bitmask containing the PCRs currently allocated.
517 @retval EFI_SUCCESS TPM was successfully queried and return values can be trusted.
518 @retval Others An error occurred, likely in communication with the TPM.
523 Tpm2GetCapabilitySupportedAndActivePcrs (
524 OUT UINT32
*TpmHashAlgorithmBitmap
,
525 OUT UINT32
*ActivePcrBanks
529 TPML_PCR_SELECTION Pcrs
;
533 // Get supported PCR and current Active PCRs.
535 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
538 // If error, assume that we have at least SHA-1 (and return the error.)
540 if (EFI_ERROR (Status
)) {
541 DEBUG ((EFI_D_ERROR
, "GetSupportedAndActivePcrs - Tpm2GetCapabilityPcrs fail!\n"));
542 *TpmHashAlgorithmBitmap
= HASH_ALG_SHA1
;
543 *ActivePcrBanks
= HASH_ALG_SHA1
;
546 // Otherwise, process the return data to determine what algorithms are supported
547 // and currently allocated.
550 DEBUG ((EFI_D_INFO
, "GetSupportedAndActivePcrs - Count = %08x\n", Pcrs
.count
));
551 *TpmHashAlgorithmBitmap
= 0;
553 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
554 switch (Pcrs
.pcrSelections
[Index
].hash
) {
556 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 present.\n"));
557 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA1
;
558 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
559 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 active.\n"));
560 *ActivePcrBanks
|= HASH_ALG_SHA1
;
564 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 present.\n"));
565 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA256
;
566 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
567 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 active.\n"));
568 *ActivePcrBanks
|= HASH_ALG_SHA256
;
572 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 present.\n"));
573 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA384
;
574 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
575 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 active.\n"));
576 *ActivePcrBanks
|= HASH_ALG_SHA384
;
580 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 present.\n"));
581 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA512
;
582 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
583 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 active.\n"));
584 *ActivePcrBanks
|= HASH_ALG_SHA512
;
587 case TPM_ALG_SM3_256
:
588 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 present.\n"));
589 *TpmHashAlgorithmBitmap
|= HASH_ALG_SM3_256
;
590 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
591 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 active.\n"));
592 *ActivePcrBanks
|= HASH_ALG_SM3_256
;
603 This command returns the information of TPM AlgorithmSet.
605 This function parse the value got from TPM2_GetCapability and return the AlgorithmSet.
607 @param[out] AlgorithmSet The AlgorithmSet of TPM.
609 @retval EFI_SUCCESS Operation completed successfully.
610 @retval EFI_DEVICE_ERROR The command was unsuccessful.
614 Tpm2GetCapabilityAlgorithmSet (
615 OUT UINT32
*AlgorithmSet
618 TPMS_CAPABILITY_DATA TpmCap
;
619 TPMI_YES_NO MoreData
;
622 Status
= Tpm2GetCapability (
623 TPM_CAP_TPM_PROPERTIES
,
624 TPM_PT_ALGORITHM_SET
,
629 if (EFI_ERROR (Status
)) {
632 *AlgorithmSet
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
638 This command is used to check to see if specific combinations of algorithm parameters are supported.
640 @param[in] Parameters Algorithm parameters to be validated
642 @retval EFI_SUCCESS Operation completed successfully.
643 @retval EFI_DEVICE_ERROR Unexpected device behavior.
648 IN TPMT_PUBLIC_PARMS
*Parameters
652 TPM2_TEST_PARMS_COMMAND SendBuffer
;
653 TPM2_TEST_PARMS_RESPONSE RecvBuffer
;
654 UINT32 SendBufferSize
;
655 UINT32 RecvBufferSize
;
661 SendBuffer
.Header
.tag
= SwapBytes16(TPM_ST_NO_SESSIONS
);
662 SendBuffer
.Header
.commandCode
= SwapBytes32(TPM_CC_TestParms
);
664 Buffer
= (UINT8
*)&SendBuffer
.Parameters
;
665 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->type
));
666 Buffer
+= sizeof(UINT16
);
667 switch (Parameters
->type
) {
668 case TPM_ALG_KEYEDHASH
:
669 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
));
670 Buffer
+= sizeof(UINT16
);
671 switch (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
) {
673 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.hmac
.hashAlg
));
674 Buffer
+= sizeof(UINT16
);
677 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.hashAlg
));
678 Buffer
+= sizeof(UINT16
);
679 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.kdf
));
680 Buffer
+= sizeof(UINT16
);
683 return EFI_INVALID_PARAMETER
;
685 case TPM_ALG_SYMCIPHER
:
686 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.algorithm
));
687 Buffer
+= sizeof(UINT16
);
688 switch (Parameters
->parameters
.symDetail
.algorithm
) {
690 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.aes
));
691 Buffer
+= sizeof(UINT16
);
692 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.aes
));
693 Buffer
+= sizeof(UINT16
);
696 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.SM4
));
697 Buffer
+= sizeof(UINT16
);
698 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.SM4
));
699 Buffer
+= sizeof(UINT16
);
702 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.xor));
703 Buffer
+= sizeof(UINT16
);
708 return EFI_INVALID_PARAMETER
;
712 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
));
713 Buffer
+= sizeof(UINT16
);
714 switch (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
) {
716 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.aes
));
717 Buffer
+= sizeof(UINT16
);
718 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.aes
));
719 Buffer
+= sizeof(UINT16
);
722 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.SM4
));
723 Buffer
+= sizeof(UINT16
);
724 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.SM4
));
725 Buffer
+= sizeof(UINT16
);
730 return EFI_INVALID_PARAMETER
;
732 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.scheme
));
733 Buffer
+= sizeof(UINT16
);
734 switch (Parameters
->parameters
.rsaDetail
.scheme
.scheme
) {
736 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsassa
.hashAlg
));
737 Buffer
+= sizeof(UINT16
);
740 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsapss
.hashAlg
));
741 Buffer
+= sizeof(UINT16
);
746 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.oaep
.hashAlg
));
747 Buffer
+= sizeof(UINT16
);
752 return EFI_INVALID_PARAMETER
;
754 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.keyBits
));
755 Buffer
+= sizeof(UINT16
);
756 WriteUnaligned32 ((UINT32
*)Buffer
, SwapBytes32 (Parameters
->parameters
.rsaDetail
.exponent
));
757 Buffer
+= sizeof(UINT32
);
760 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
));
761 Buffer
+= sizeof(UINT16
);
762 switch (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
) {
764 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.aes
));
765 Buffer
+= sizeof(UINT16
);
766 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.aes
));
767 Buffer
+= sizeof(UINT16
);
770 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.SM4
));
771 Buffer
+= sizeof(UINT16
);
772 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.SM4
));
773 Buffer
+= sizeof(UINT16
);
778 return EFI_INVALID_PARAMETER
;
780 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.scheme
));
781 Buffer
+= sizeof(UINT16
);
782 switch (Parameters
->parameters
.eccDetail
.scheme
.scheme
) {
784 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdsa
.hashAlg
));
785 Buffer
+= sizeof(UINT16
);
788 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdaa
.hashAlg
));
789 Buffer
+= sizeof(UINT16
);
791 case TPM_ALG_ECSCHNORR
:
792 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecSchnorr
.hashAlg
));
793 Buffer
+= sizeof(UINT16
);
800 return EFI_INVALID_PARAMETER
;
802 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.curveID
));
803 Buffer
+= sizeof(UINT16
);
804 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.scheme
));
805 Buffer
+= sizeof(UINT16
);
806 switch (Parameters
->parameters
.eccDetail
.kdf
.scheme
) {
808 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.mgf1
.hashAlg
));
809 Buffer
+= sizeof(UINT16
);
811 case TPM_ALG_KDF1_SP800_108
:
812 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_sp800_108
.hashAlg
));
813 Buffer
+= sizeof(UINT16
);
815 case TPM_ALG_KDF1_SP800_56a
:
816 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_SP800_56a
.hashAlg
));
817 Buffer
+= sizeof(UINT16
);
820 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf2
.hashAlg
));
821 Buffer
+= sizeof(UINT16
);
826 return EFI_INVALID_PARAMETER
;
830 return EFI_INVALID_PARAMETER
;
833 SendBufferSize
= (UINT32
)((UINTN
)Buffer
- (UINTN
)&SendBuffer
);
834 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
839 RecvBufferSize
= sizeof (RecvBuffer
);
840 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
841 if (EFI_ERROR (Status
)) {
845 if (RecvBufferSize
< sizeof (TPM2_RESPONSE_HEADER
)) {
846 DEBUG ((EFI_D_ERROR
, "Tpm2TestParms - RecvBufferSize Error - %x\n", RecvBufferSize
));
847 return EFI_DEVICE_ERROR
;
849 if (SwapBytes32(RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
850 DEBUG ((EFI_D_ERROR
, "Tpm2TestParms - responseCode - %x\n", SwapBytes32(RecvBuffer
.Header
.responseCode
)));
851 return EFI_UNSUPPORTED
;