diff --git a/TPMCmd/tpm/include/private/prototypes/Object_fp.h b/TPMCmd/tpm/include/private/prototypes/Object_fp.h index d6fba7d..3179775 100644 --- a/TPMCmd/tpm/include/private/prototypes/Object_fp.h +++ b/TPMCmd/tpm/include/private/prototypes/Object_fp.h @@ -154,6 +154,16 @@ ObjectCreateEventSequence(TPM2B_AUTH* auth, // IN: authValue TPMI_DH_OBJECT* newHandle // OUT: sequence object handle ); +//*** ObjectCreateEventSequenceHcrtmDrtm() +// This function creates an event sequence object for Hcrtm/Drtm case, +// it is called in _TPM_Hash_Start(). +// Return Type: TPM_RC +// TPM_RC_OBJECT_MEMORY if there is no free slot for an object +TPM_RC +ObjectCreateEventSequenceHcrtmDrtm(TPM2B_AUTH* auth, // IN: authValue + TPMI_DH_OBJECT* newHandle // OUT: sequence object handle +); + //*** ObjectTerminateEvent() // This function is called to close out the event sequence and clean up the hash // context states. diff --git a/TPMCmd/tpm/src/events/_TPM_Hash_Start.c b/TPMCmd/tpm/src/events/_TPM_Hash_Start.c index 8f5a0e4..6d72801 100644 --- a/TPMCmd/tpm/src/events/_TPM_Hash_Start.c +++ b/TPMCmd/tpm/src/events/_TPM_Hash_Start.c @@ -18,12 +18,12 @@ LIB_EXPORT BOOL _TPM_Hash_Start(void) VERIFY(FlushObject(oldHandle), FATAL_ERROR_INTERNAL, FALSE); } - // Create an event sequence object and store the handle in global + // Create an event sequence object for Hcrtm/Drtm and store the handle in global // g_DRTMHandle. A TPM_RC_OBJECT_MEMORY error may be returned at this point // The NULL value for the first parameter will cause the sequence structure to // be allocated without being set as present. This keeps the sequence from // being left behind if the sequence is terminated early. - result = ObjectCreateEventSequence(NULL, &g_DRTMHandle); + result = ObjectCreateEventSequenceHcrtmDrtm(NULL, &g_DRTMHandle); // If a free slot was not available, then free up a slot. if(result != TPM_RC_SUCCESS) @@ -51,7 +51,7 @@ LIB_EXPORT BOOL _TPM_Hash_Start(void) // Try to create an event sequence object again. This time, we must // succeed. - result = ObjectCreateEventSequence(NULL, &g_DRTMHandle); + result = ObjectCreateEventSequenceHcrtmDrtm(NULL, &g_DRTMHandle); if(result != TPM_RC_SUCCESS) FAIL_BOOL(FATAL_ERROR_INTERNAL); } diff --git a/TPMCmd/tpm/src/subsystem/Object.c b/TPMCmd/tpm/src/subsystem/Object.c index 171d02d..233cf20 100644 --- a/TPMCmd/tpm/src/subsystem/Object.c +++ b/TPMCmd/tpm/src/subsystem/Object.c @@ -538,6 +538,38 @@ ObjectCreateEventSequence(TPM2B_AUTH* auth, // IN: authValue return TPM_RC_SUCCESS; } +//*** ObjectCreateEventSequenceHcrtmDrtm() +// This function creates an event sequence object for HCRTM/DRTM use case. +// Return Type: TPM_RC +// TPM_RC_OBJECT_MEMORY if there is no free slot for an object +TPM_RC +ObjectCreateEventSequenceHcrtmDrtm( + TPM2B_AUTH *auth, // IN: authValue + TPMI_DH_OBJECT *newHandle // OUT: sequence object handle + ) +{ + HASH_OBJECT* hashObject = AllocateSequenceSlot(newHandle, auth); + TPMI_DH_PCR pcrHandle = TPMIsStarted()? PCR_FIRST + DRTM_PCR : PCR_FIRST + HCRTM_PCR; + UINT32 i; + TPM_ALG_ID hash; + // + // See if slot allocated + if(hashObject == NULL) + return TPM_RC_OBJECT_MEMORY; + // Set the event sequence attribute + hashObject->attributes.eventSeq = SET; + + // Initialize hash states for each implemented PCR algorithms + for(i = 0; i < HASH_COUNT; i++) + { + hash = CryptHashGetAlgByIndex(i); + // make sure that the PCR is implemented for this algorithm + if(PcrIsAllocated(pcrHandle, hash)) + CryptHashStart(&hashObject->state.hashState[i], hash); + } + return TPM_RC_SUCCESS; +} + //*** ObjectTerminateEvent() // This function is called to close out the event sequence and clean up the hash // context states.