diff -ur tpm2.0-tools-1.1.0/src/tpm2_listpcrs.cpp tpm2.0-tools-1.1.0-new/src/tpm2_listpcrs.cpp --- tpm2.0-tools-1.1.0/src/tpm2_listpcrs.cpp 2017-05-15 15:02:54.844952364 -0700 +++ tpm2.0-tools-1.1.0-new/src/tpm2_listpcrs.cpp 2017-05-15 15:06:26.224438974 -0700 @@ -159,38 +159,36 @@ return 0; } -void preparePcrSelections_g(TPMI_ALG_HASH algId) +int preparePcrSelections(TPMI_ALG_HASH algId) { - UINT32 pcrId = 0; - - g_pcrSelections.count = 1; - g_pcrSelections.pcrSelections[0].hash = algId; - SET_PCR_SELECT_SIZE(g_pcrSelections.pcrSelections[0], 3); - CLEAR_PCR_SELECT_BITS(g_pcrSelections.pcrSelections[0]); - - for(pcrId = 0; pcrId < 24; pcrId++) + TPMI_YES_NO moreData; + TPMS_CAPABILITY_DATA capabilityData; + UINT32 rval; + + rval = Tss2_Sys_GetCapability( sysContext, 0, TPM_CAP_PCRS, 0, 1, + &moreData, &capabilityData, 0 ); + if(rval != TPM_RC_SUCCESS) { - SET_PCR_SELECT_BIT(g_pcrSelections.pcrSelections[0], pcrId ); + printf("\n......GetCapability: Get PCR allocation status Error. TPM Error:0x%x......\n", rval); + return -1; } -} - -void preparePcrSelections() -{ - UINT32 pcrId = 0; g_pcrSelections.count = 0; - for( int i = 0; i < g_banks.count; i++ ) + for( int i=0; i < capabilityData.data.assignedPCR.count; i++ ) { - g_pcrSelections.pcrSelections[i].hash = g_banks.alg[i]; - SET_PCR_SELECT_SIZE(g_pcrSelections.pcrSelections[i], 3); - CLEAR_PCR_SELECT_BITS(g_pcrSelections.pcrSelections[i]); - - for(pcrId = 0; pcrId < 24; pcrId++) - { - SET_PCR_SELECT_BIT(g_pcrSelections.pcrSelections[i], pcrId ); - } + if (algId && (capabilityData.data.assignedPCR.pcrSelections[i].hash != algId)) + continue; + g_pcrSelections.pcrSelections[g_pcrSelections.count].hash = capabilityData.data.assignedPCR.pcrSelections[i].hash; + SET_PCR_SELECT_SIZE(g_pcrSelections.pcrSelections[g_pcrSelections.count], capabilityData.data.assignedPCR.pcrSelections[i].sizeofSelect); + for (int j = 0; j < g_pcrSelections.pcrSelections[g_pcrSelections.count].sizeofSelect; j++) + g_pcrSelections.pcrSelections[g_pcrSelections.count].pcrSelect[j] = capabilityData.data.assignedPCR.pcrSelections[i].pcrSelect[j]; g_pcrSelections.count++; } + + if (g_pcrSelections.count == 0) + return -1; + + return 0; } // show all PCR banks according to g_pcrSelection & g_pcrs. @@ -205,7 +203,7 @@ printf("\nBank/Algorithm: %s(0x%04x)\n", g_algs[alg_i].desc, g_pcrSelections.pcrSelections[i].hash); - for(UINT32 pcrId = 0; pcrId < 24; pcrId++) + for(UINT32 pcrId = 0; pcrId < g_pcrSelections.pcrSelections[i].sizeofSelect * 8; pcrId++) { if(!TEST_PCR_SELECT_BIT(g_pcrSelections.pcrSelections[i], pcrId)) continue; @@ -246,7 +244,8 @@ int showAllPcrValues() { - preparePcrSelections(); + if(preparePcrSelections(0)) + return -1; if(readPcrValues()) return -1; @@ -270,7 +269,8 @@ int showAlgPcrValues(TPMI_ALG_HASH algId) { - preparePcrSelections_g(algId); + if(preparePcrSelections(algId)) + return -1; if(readPcrValues()) return -1;