2 Implement TPM2 Capability related command.
4 Copyright (c) 2013, 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 // Return the response
118 *MoreData
= RecvBuffer
.MoreData
;
120 // Does not unpack all possiable property here, the caller should unpack it and note the byte order.
122 CopyMem (CapabilityData
, &RecvBuffer
.CapabilityData
, RecvBufferSize
- sizeof (TPM2_RESPONSE_HEADER
) - sizeof (UINT8
));
128 This command returns the information of TPM Family.
130 This function parse the value got from TPM2_GetCapability and return the Family.
132 @param[out] Family The Family of TPM. (a 4-octet character string)
134 @retval EFI_SUCCESS Operation completed successfully.
135 @retval EFI_DEVICE_ERROR The command was unsuccessful.
139 Tpm2GetCapabilityFamily (
143 TPMS_CAPABILITY_DATA TpmCap
;
144 TPMI_YES_NO MoreData
;
147 Status
= Tpm2GetCapability (
148 TPM_CAP_TPM_PROPERTIES
,
149 TPM_PT_FAMILY_INDICATOR
,
154 if (EFI_ERROR (Status
)) {
157 CopyMem (Family
, &TpmCap
.data
.tpmProperties
.tpmProperty
->value
, 4);
163 This command returns the information of TPM manufacture ID.
165 This function parse the value got from TPM2_GetCapability and return the TPM manufacture ID.
167 @param[out] ManufactureId The manufacture ID of TPM.
169 @retval EFI_SUCCESS Operation completed successfully.
170 @retval EFI_DEVICE_ERROR The command was unsuccessful.
174 Tpm2GetCapabilityManufactureID (
175 OUT UINT32
*ManufactureId
178 TPMS_CAPABILITY_DATA TpmCap
;
179 TPMI_YES_NO MoreData
;
182 Status
= Tpm2GetCapability (
183 TPM_CAP_TPM_PROPERTIES
,
189 if (EFI_ERROR (Status
)) {
192 *ManufactureId
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
198 This command returns the information of TPM FirmwareVersion.
200 This function parse the value got from TPM2_GetCapability and return the TPM FirmwareVersion.
202 @param[out] FirmwareVersion1 The FirmwareVersion1.
203 @param[out] FirmwareVersion2 The FirmwareVersion2.
205 @retval EFI_SUCCESS Operation completed successfully.
206 @retval EFI_DEVICE_ERROR The command was unsuccessful.
210 Tpm2GetCapabilityFirmwareVersion (
211 OUT UINT32
*FirmwareVersion1
,
212 OUT UINT32
*FirmwareVersion2
215 TPMS_CAPABILITY_DATA TpmCap
;
216 TPMI_YES_NO MoreData
;
219 Status
= Tpm2GetCapability (
220 TPM_CAP_TPM_PROPERTIES
,
221 TPM_PT_FIRMWARE_VERSION_1
,
226 if (EFI_ERROR (Status
)) {
229 *FirmwareVersion1
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
231 Status
= Tpm2GetCapability (
232 TPM_CAP_TPM_PROPERTIES
,
233 TPM_PT_FIRMWARE_VERSION_2
,
238 if (EFI_ERROR (Status
)) {
241 *FirmwareVersion2
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
247 This command returns the information of the maximum value for commandSize and responseSize in a command.
249 This function parse the value got from TPM2_GetCapability and return the max command size and response size
251 @param[out] MaxCommandSize The maximum value for commandSize in a command.
252 @param[out] MaxResponseSize The maximum value for responseSize in a command.
254 @retval EFI_SUCCESS Operation completed successfully.
255 @retval EFI_DEVICE_ERROR The command was unsuccessful.
259 Tpm2GetCapabilityMaxCommandResponseSize (
260 OUT UINT32
*MaxCommandSize
,
261 OUT UINT32
*MaxResponseSize
264 TPMS_CAPABILITY_DATA TpmCap
;
265 TPMI_YES_NO MoreData
;
268 Status
= Tpm2GetCapability (
269 TPM_CAP_TPM_PROPERTIES
,
270 TPM_PT_MAX_COMMAND_SIZE
,
275 if (EFI_ERROR (Status
)) {
279 *MaxCommandSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
281 Status
= Tpm2GetCapability (
282 TPM_CAP_TPM_PROPERTIES
,
283 TPM_PT_MAX_RESPONSE_SIZE
,
288 if (EFI_ERROR (Status
)) {
292 *MaxResponseSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
297 This command returns Returns a list of TPMS_ALG_PROPERTIES. Each entry is an
298 algorithm ID and a set of properties of the algorithm.
300 This function parse the value got from TPM2_GetCapability and return the list.
302 @param[out] AlgList List of algorithm.
304 @retval EFI_SUCCESS Operation completed successfully.
305 @retval EFI_DEVICE_ERROR The command was unsuccessful.
309 Tpm2GetCapabilitySupportedAlg (
310 OUT TPML_ALG_PROPERTY
*AlgList
313 TPMS_CAPABILITY_DATA TpmCap
;
314 TPMI_YES_NO MoreData
;
318 Status
= Tpm2GetCapability (
325 if (EFI_ERROR (Status
)) {
329 CopyMem (AlgList
, &TpmCap
.data
.algorithms
, sizeof (TPML_ALG_PROPERTY
));
331 AlgList
->count
= SwapBytes32 (AlgList
->count
);
332 for (Index
= 0; Index
< AlgList
->count
; Index
++) {
333 AlgList
->algProperties
[Index
].alg
= SwapBytes16 (AlgList
->algProperties
[Index
].alg
);
334 WriteUnaligned32 ((UINT32
*)&AlgList
->algProperties
[Index
].algProperties
, SwapBytes32 (ReadUnaligned32 ((UINT32
*)&AlgList
->algProperties
[Index
].algProperties
)));
341 This command returns the information of TPM LockoutCounter.
343 This function parse the value got from TPM2_GetCapability and return the LockoutCounter.
345 @param[out] LockoutCounter The LockoutCounter of TPM.
347 @retval EFI_SUCCESS Operation completed successfully.
348 @retval EFI_DEVICE_ERROR The command was unsuccessful.
352 Tpm2GetCapabilityLockoutCounter (
353 OUT UINT32
*LockoutCounter
356 TPMS_CAPABILITY_DATA TpmCap
;
357 TPMI_YES_NO MoreData
;
360 Status
= Tpm2GetCapability (
361 TPM_CAP_TPM_PROPERTIES
,
362 TPM_PT_LOCKOUT_COUNTER
,
367 if (EFI_ERROR (Status
)) {
370 *LockoutCounter
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
376 This command returns the information of TPM LockoutInterval.
378 This function parse the value got from TPM2_GetCapability and return the LockoutInterval.
380 @param[out] LockoutInterval The LockoutInterval of TPM.
382 @retval EFI_SUCCESS Operation completed successfully.
383 @retval EFI_DEVICE_ERROR The command was unsuccessful.
387 Tpm2GetCapabilityLockoutInterval (
388 OUT UINT32
*LockoutInterval
391 TPMS_CAPABILITY_DATA TpmCap
;
392 TPMI_YES_NO MoreData
;
395 Status
= Tpm2GetCapability (
396 TPM_CAP_TPM_PROPERTIES
,
397 TPM_PT_LOCKOUT_INTERVAL
,
402 if (EFI_ERROR (Status
)) {
405 *LockoutInterval
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
411 This command returns the information of TPM InputBufferSize.
413 This function parse the value got from TPM2_GetCapability and return the InputBufferSize.
415 @param[out] InputBufferSize The InputBufferSize of TPM.
416 the maximum size of a parameter (typically, a TPM2B_MAX_BUFFER)
418 @retval EFI_SUCCESS Operation completed successfully.
419 @retval EFI_DEVICE_ERROR The command was unsuccessful.
423 Tpm2GetCapabilityInputBufferSize (
424 OUT UINT32
*InputBufferSize
427 TPMS_CAPABILITY_DATA TpmCap
;
428 TPMI_YES_NO MoreData
;
431 Status
= Tpm2GetCapability (
432 TPM_CAP_TPM_PROPERTIES
,
438 if (EFI_ERROR (Status
)) {
441 *InputBufferSize
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
447 This command returns the information of TPM PCRs.
449 This function parse the value got from TPM2_GetCapability and return the PcrSelection.
451 @param[out] Pcrs The Pcr Selection
453 @retval EFI_SUCCESS Operation completed successfully.
454 @retval EFI_DEVICE_ERROR The command was unsuccessful.
458 Tpm2GetCapabilityPcrs (
459 OUT TPML_PCR_SELECTION
*Pcrs
462 TPMS_CAPABILITY_DATA TpmCap
;
463 TPMI_YES_NO MoreData
;
467 Status
= Tpm2GetCapability (
474 if (EFI_ERROR (Status
)) {
478 Pcrs
->count
= SwapBytes32 (TpmCap
.data
.assignedPCR
.count
);
479 for (Index
= 0; Index
< Pcrs
->count
; Index
++) {
480 Pcrs
->pcrSelections
[Index
].hash
= SwapBytes16 (TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].hash
);
481 Pcrs
->pcrSelections
[Index
].sizeofSelect
= TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].sizeofSelect
;
482 CopyMem (Pcrs
->pcrSelections
[Index
].pcrSelect
, TpmCap
.data
.assignedPCR
.pcrSelections
[Index
].pcrSelect
, Pcrs
->pcrSelections
[Index
].sizeofSelect
);
489 This function will query the TPM to determine which hashing algorithms
490 are supported and which PCR banks are currently active.
492 @param[out] TpmHashAlgorithmBitmap A bitmask containing the algorithms supported by the TPM.
493 @param[out] ActivePcrBanks A bitmask containing the PCRs currently allocated.
495 @retval EFI_SUCCESS TPM was successfully queried and return values can be trusted.
496 @retval Others An error occurred, likely in communication with the TPM.
501 Tpm2GetCapabilitySupportedAndActivePcrs (
502 OUT UINT32
*TpmHashAlgorithmBitmap
,
503 OUT UINT32
*ActivePcrBanks
507 TPML_PCR_SELECTION Pcrs
;
511 // Get supported PCR and current Active PCRs.
513 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
516 // If error, assume that we have at least SHA-1 (and return the error.)
518 if (EFI_ERROR (Status
)) {
519 DEBUG ((EFI_D_ERROR
, "GetSupportedAndActivePcrs - Tpm2GetCapabilityPcrs fail!\n"));
520 *TpmHashAlgorithmBitmap
= HASH_ALG_SHA1
;
521 *ActivePcrBanks
= HASH_ALG_SHA1
;
524 // Otherwise, process the return data to determine what algorithms are supported
525 // and currently allocated.
528 DEBUG ((EFI_D_INFO
, "GetSupportedAndActivePcrs - Count = %08x\n", Pcrs
.count
));
529 *TpmHashAlgorithmBitmap
= 0;
531 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
532 switch (Pcrs
.pcrSelections
[Index
].hash
) {
534 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 present.\n"));
535 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA1
;
536 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
537 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA1 active.\n"));
538 *ActivePcrBanks
|= HASH_ALG_SHA1
;
542 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 present.\n"));
543 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA256
;
544 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
545 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA256 active.\n"));
546 *ActivePcrBanks
|= HASH_ALG_SHA256
;
550 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 present.\n"));
551 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA384
;
552 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
553 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA384 active.\n"));
554 *ActivePcrBanks
|= HASH_ALG_SHA384
;
558 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 present.\n"));
559 *TpmHashAlgorithmBitmap
|= HASH_ALG_SHA512
;
560 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
561 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SHA512 active.\n"));
562 *ActivePcrBanks
|= HASH_ALG_SHA512
;
565 case TPM_ALG_SM3_256
:
566 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 present.\n"));
567 *TpmHashAlgorithmBitmap
|= HASH_ALG_SM3_256
;
568 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
569 DEBUG ((EFI_D_VERBOSE
, "GetSupportedAndActivePcrs - HASH_ALG_SM3_256 active.\n"));
570 *ActivePcrBanks
|= HASH_ALG_SM3_256
;
581 This command returns the information of TPM AlgorithmSet.
583 This function parse the value got from TPM2_GetCapability and return the AlgorithmSet.
585 @param[out] AlgorithmSet The AlgorithmSet of TPM.
587 @retval EFI_SUCCESS Operation completed successfully.
588 @retval EFI_DEVICE_ERROR The command was unsuccessful.
592 Tpm2GetCapabilityAlgorithmSet (
593 OUT UINT32
*AlgorithmSet
596 TPMS_CAPABILITY_DATA TpmCap
;
597 TPMI_YES_NO MoreData
;
600 Status
= Tpm2GetCapability (
601 TPM_CAP_TPM_PROPERTIES
,
602 TPM_PT_ALGORITHM_SET
,
607 if (EFI_ERROR (Status
)) {
610 *AlgorithmSet
= SwapBytes32 (TpmCap
.data
.tpmProperties
.tpmProperty
->value
);
616 This command is used to check to see if specific combinations of algorithm parameters are supported.
618 @param[in] Parameters Algorithm parameters to be validated
620 @retval EFI_SUCCESS Operation completed successfully.
621 @retval EFI_DEVICE_ERROR Unexpected device behavior.
626 IN TPMT_PUBLIC_PARMS
*Parameters
630 TPM2_TEST_PARMS_COMMAND SendBuffer
;
631 TPM2_TEST_PARMS_RESPONSE RecvBuffer
;
632 UINT32 SendBufferSize
;
633 UINT32 RecvBufferSize
;
639 SendBuffer
.Header
.tag
= SwapBytes16(TPM_ST_NO_SESSIONS
);
640 SendBuffer
.Header
.commandCode
= SwapBytes32(TPM_CC_TestParms
);
642 Buffer
= (UINT8
*)&SendBuffer
.Parameters
;
643 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->type
));
644 Buffer
+= sizeof(UINT16
);
645 switch (Parameters
->type
) {
646 case TPM_ALG_KEYEDHASH
:
647 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
));
648 Buffer
+= sizeof(UINT16
);
649 switch (Parameters
->parameters
.keyedHashDetail
.scheme
.scheme
) {
651 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.hmac
.hashAlg
));
652 Buffer
+= sizeof(UINT16
);
655 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.hashAlg
));
656 Buffer
+= sizeof(UINT16
);
657 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.keyedHashDetail
.scheme
.details
.xor.kdf
));
658 Buffer
+= sizeof(UINT16
);
661 return EFI_INVALID_PARAMETER
;
663 case TPM_ALG_SYMCIPHER
:
664 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.algorithm
));
665 Buffer
+= sizeof(UINT16
);
666 switch (Parameters
->parameters
.symDetail
.algorithm
) {
668 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.aes
));
669 Buffer
+= sizeof(UINT16
);
670 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.aes
));
671 Buffer
+= sizeof(UINT16
);
674 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.SM4
));
675 Buffer
+= sizeof(UINT16
);
676 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.mode
.SM4
));
677 Buffer
+= sizeof(UINT16
);
680 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.symDetail
.keyBits
.xor));
681 Buffer
+= sizeof(UINT16
);
686 return EFI_INVALID_PARAMETER
;
690 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
));
691 Buffer
+= sizeof(UINT16
);
692 switch (Parameters
->parameters
.rsaDetail
.symmetric
.algorithm
) {
694 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.aes
));
695 Buffer
+= sizeof(UINT16
);
696 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.aes
));
697 Buffer
+= sizeof(UINT16
);
700 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.keyBits
.SM4
));
701 Buffer
+= sizeof(UINT16
);
702 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.symmetric
.mode
.SM4
));
703 Buffer
+= sizeof(UINT16
);
708 return EFI_INVALID_PARAMETER
;
710 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.scheme
));
711 Buffer
+= sizeof(UINT16
);
712 switch (Parameters
->parameters
.rsaDetail
.scheme
.scheme
) {
714 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsassa
.hashAlg
));
715 Buffer
+= sizeof(UINT16
);
718 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.rsapss
.hashAlg
));
719 Buffer
+= sizeof(UINT16
);
724 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.scheme
.details
.oaep
.hashAlg
));
725 Buffer
+= sizeof(UINT16
);
730 return EFI_INVALID_PARAMETER
;
732 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.rsaDetail
.keyBits
));
733 Buffer
+= sizeof(UINT16
);
734 WriteUnaligned32 ((UINT32
*)Buffer
, SwapBytes32 (Parameters
->parameters
.rsaDetail
.exponent
));
735 Buffer
+= sizeof(UINT32
);
738 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
));
739 Buffer
+= sizeof(UINT16
);
740 switch (Parameters
->parameters
.eccDetail
.symmetric
.algorithm
) {
742 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.aes
));
743 Buffer
+= sizeof(UINT16
);
744 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.aes
));
745 Buffer
+= sizeof(UINT16
);
748 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.keyBits
.SM4
));
749 Buffer
+= sizeof(UINT16
);
750 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.symmetric
.mode
.SM4
));
751 Buffer
+= sizeof(UINT16
);
756 return EFI_INVALID_PARAMETER
;
758 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.scheme
));
759 Buffer
+= sizeof(UINT16
);
760 switch (Parameters
->parameters
.eccDetail
.scheme
.scheme
) {
762 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdsa
.hashAlg
));
763 Buffer
+= sizeof(UINT16
);
766 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecdaa
.hashAlg
));
767 Buffer
+= sizeof(UINT16
);
769 case TPM_ALG_ECSCHNORR
:
770 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.scheme
.details
.ecSchnorr
.hashAlg
));
771 Buffer
+= sizeof(UINT16
);
778 return EFI_INVALID_PARAMETER
;
780 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.curveID
));
781 Buffer
+= sizeof(UINT16
);
782 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.scheme
));
783 Buffer
+= sizeof(UINT16
);
784 switch (Parameters
->parameters
.eccDetail
.kdf
.scheme
) {
786 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.mgf1
.hashAlg
));
787 Buffer
+= sizeof(UINT16
);
789 case TPM_ALG_KDF1_SP800_108
:
790 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_sp800_108
.hashAlg
));
791 Buffer
+= sizeof(UINT16
);
793 case TPM_ALG_KDF1_SP800_56a
:
794 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf1_SP800_56a
.hashAlg
));
795 Buffer
+= sizeof(UINT16
);
798 WriteUnaligned16 ((UINT16
*)Buffer
, SwapBytes16 (Parameters
->parameters
.eccDetail
.kdf
.details
.kdf2
.hashAlg
));
799 Buffer
+= sizeof(UINT16
);
804 return EFI_INVALID_PARAMETER
;
808 return EFI_INVALID_PARAMETER
;
811 SendBufferSize
= (UINT32
)((UINTN
)Buffer
- (UINTN
)&SendBuffer
);
812 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
817 RecvBufferSize
= sizeof (RecvBuffer
);
818 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
819 if (EFI_ERROR (Status
)) {
823 if (RecvBufferSize
< sizeof (TPM2_RESPONSE_HEADER
)) {
824 DEBUG ((EFI_D_ERROR
, "Tpm2TestParms - RecvBufferSize Error - %x\n", RecvBufferSize
));
825 return EFI_DEVICE_ERROR
;
827 if (SwapBytes32(RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
828 DEBUG ((EFI_D_ERROR
, "Tpm2TestParms - responseCode - %x\n", SwapBytes32(RecvBuffer
.Header
.responseCode
)));
829 return EFI_UNSUPPORTED
;