1 // This file was extracted from the TCG Published
2 // Trusted Platform Module Library
3 // Part 3: Commands
4 // Family "2.0"
5 // Level 00 Revision 01.16
6 // October 30, 2014
7 
8 #include "InternalRoutines.h"
9 //
10 //     This function is called to process a _TPM_Hash_Start() indication.
11 //
12 void
_TPM_Hash_Start(void)13 _TPM_Hash_Start(
14    void
15    )
16 {
17    TPM_RC                 result;
18    TPMI_DH_OBJECT         handle;
19 
20    // If a DRTM sequence object exists, free it up
21    if(g_DRTMHandle != TPM_RH_UNASSIGNED)
22    {
23        ObjectFlush(g_DRTMHandle);
24        g_DRTMHandle = TPM_RH_UNASSIGNED;
25    }
26 
27    // Create an event sequence object and store the handle in global
28    // g_DRTMHandle. A TPM_RC_OBJECT_MEMORY error may be returned at this point
29    // The null value for the 'auth' parameter will cause the sequence structure to
30    // be allocated without being set as present. This keeps the sequence from
31    // being left behind if the sequence is terminated early.
32    result = ObjectCreateEventSequence(NULL, &g_DRTMHandle);
33 
34    // If a free slot was not available, then free up a slot.
35    if(result != TPM_RC_SUCCESS)
36    {
37        // An implementation does not need to have a fixed relationship between
38        // slot numbers and handle numbers. To handle the general case, scan for
39        // a handle that is assigned and free it for the DRTM sequence.
40        // In the reference implementation, the relationship between handles and
41        // slots is fixed. So, if the call to ObjectCreateEvenSequence()
42        // failed indicating that all slots are occupied, then the first handle we
43        // are going to check (TRANSIENT_FIRST) will be occupied. It will be freed
44        // so that it can be assigned for use as the DRTM sequence object.
45        for(handle = TRANSIENT_FIRST; handle < TRANSIENT_LAST; handle++)
46        {
47            // try to flush the first object
48            if(ObjectIsPresent(handle))
49                break;
50        }
51        // If the first call to find a slot fails but none of the slots is occupied
52        // then there's a big problem
53        pAssert(handle < TRANSIENT_LAST);
54 
55         // Free the slot
56         ObjectFlush(handle);
57 
58         // Try to create an event sequence object again. This time, we must
59         // succeed.
60         result = ObjectCreateEventSequence(NULL, &g_DRTMHandle);
61         pAssert(result == TPM_RC_SUCCESS);
62    }
63 
64    return;
65 }
66