+Done:\r
+ //\r
+ // Clear AuthSession Content\r
+ //\r
+ ZeroMem (&Cmd, sizeof(Cmd));\r
+ ZeroMem (&Res, sizeof(Res));\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Alloc PCR data.\r
+\r
+ @param[in] PlatformAuth platform auth value. NULL means no platform auth change.\r
+ @param[in] SupportedPCRBanks Supported PCR banks\r
+ @param[in] PCRBanks PCR banks\r
+\r
+ @retval EFI_SUCCESS Operation completed successfully.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tpm2PcrAllocateBanks (\r
+ IN TPM2B_AUTH *PlatformAuth, OPTIONAL\r
+ IN UINT32 SupportedPCRBanks,\r
+ IN UINT32 PCRBanks\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ TPMS_AUTH_COMMAND *AuthSession;\r
+ TPMS_AUTH_COMMAND LocalAuthSession;\r
+ TPML_PCR_SELECTION PcrAllocation;\r
+ TPMI_YES_NO AllocationSuccess;\r
+ UINT32 MaxPCR;\r
+ UINT32 SizeNeeded;\r
+ UINT32 SizeAvailable;\r
+\r
+ if (PlatformAuth == NULL) {\r
+ AuthSession = NULL;\r
+ } else {\r
+ AuthSession = &LocalAuthSession;\r
+ ZeroMem (&LocalAuthSession, sizeof(LocalAuthSession));\r
+ LocalAuthSession.sessionHandle = TPM_RS_PW;\r
+ LocalAuthSession.hmac.size = PlatformAuth->size;\r
+ CopyMem (LocalAuthSession.hmac.buffer, PlatformAuth->buffer, PlatformAuth->size);\r
+ }\r
+\r
+ //\r
+ // Fill input\r
+ //\r
+ ZeroMem (&PcrAllocation, sizeof(PcrAllocation));\r
+ if ((HASH_ALG_SHA1 & SupportedPCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SHA1;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
+ if ((HASH_ALG_SHA1 & PCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0xFF;\r
+ } else {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
+ }\r
+ PcrAllocation.count++;\r
+ }\r
+ if ((HASH_ALG_SHA256 & SupportedPCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SHA256;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
+ if ((HASH_ALG_SHA256 & PCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0xFF;\r
+ } else {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
+ }\r
+ PcrAllocation.count++;\r
+ }\r
+ if ((HASH_ALG_SHA384 & SupportedPCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SHA384;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
+ if ((HASH_ALG_SHA384 & PCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0xFF;\r
+ } else {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
+ }\r
+ PcrAllocation.count++;\r
+ }\r
+ if ((HASH_ALG_SHA512 & SupportedPCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SHA512;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
+ if ((HASH_ALG_SHA512 & PCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0xFF;\r
+ } else {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
+ }\r
+ PcrAllocation.count++;\r
+ }\r
+ if ((HASH_ALG_SM3_256 & SupportedPCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].hash = TPM_ALG_SM3_256;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].sizeofSelect = PCR_SELECT_MAX;\r
+ if ((HASH_ALG_SM3_256 & PCRBanks) != 0) {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0xFF;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0xFF;\r
+ } else {\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[0] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[1] = 0x00;\r
+ PcrAllocation.pcrSelections[PcrAllocation.count].pcrSelect[2] = 0x00;\r
+ }\r
+ PcrAllocation.count++;\r
+ }\r
+ Status = Tpm2PcrAllocate (\r
+ TPM_RH_PLATFORM,\r
+ AuthSession,\r
+ &PcrAllocation,\r
+ &AllocationSuccess,\r
+ &MaxPCR,\r
+ &SizeNeeded,\r
+ &SizeAvailable\r
+ );\r
+ DEBUG ((EFI_D_INFO, "Tpm2PcrAllocateBanks call Tpm2PcrAllocate - %r\n", Status));\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
+ DEBUG ((EFI_D_INFO, "AllocationSuccess - %02x\n", AllocationSuccess));\r
+ DEBUG ((EFI_D_INFO, "MaxPCR - %08x\n", MaxPCR));\r
+ DEBUG ((EFI_D_INFO, "SizeNeeded - %08x\n", SizeNeeded));\r
+ DEBUG ((EFI_D_INFO, "SizeAvailable - %08x\n", SizeAvailable));\r
+\r
+Done:\r
+ ZeroMem(&LocalAuthSession.hmac, sizeof(LocalAuthSession.hmac));\r
+ return Status;\r