aboutsummaryrefslogtreecommitdiff
path: root/_TPM_Hash_End.c
blob: eb21a63c0086b0c75cf4d9fe2cf3557b2e51f5e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// This file was extracted from the TCG Published
// Trusted Platform Module Library
// Part 3: Commands
// Family "2.0"
// Level 00 Revision 01.16
// October 30, 2014

#include "InternalRoutines.h"
//
//     This function is called to process a _TPM_Hash_End() indication.
//
void
_TPM_Hash_End(
   void
   )
{

   UINT32            i;
   TPM2B_DIGEST      digest;
   HASH_OBJECT      *hashObject;
   TPMI_DH_PCR       pcrHandle;

   // If the DRTM handle is not being used, then either _TPM_Hash_Start has not
   // been called, _TPM_Hash_End was previously called, or some other command
   // was executed and the sequence was aborted.
   if(g_DRTMHandle == TPM_RH_UNASSIGNED)
       return;

   // Get DRTM sequence object
   hashObject = (HASH_OBJECT *)ObjectGet(g_DRTMHandle);

   // Is this _TPM_Hash_End after Startup or before
   if(TPMIsStarted())
   {
       // After

         // Reset the DRTM PCR
         PCRResetDynamics();

         // Extend the DRTM_PCR.
         pcrHandle = PCR_FIRST + DRTM_PCR;

         // DRTM sequence increments restartCount
         gr.restartCount++;
   }
   else
   {
       pcrHandle = PCR_FIRST + HCRTM_PCR;
   }

   // Complete hash and extend PCR, or if this is an HCRTM, complete
   // the hash, reset the H-CRTM register (PCR[0]) to 0...04, and then
   // extend the H-CRTM data
   for(i = 0; i < HASH_COUNT; i++)
   {
       TPMI_ALG_HASH       hash = CryptGetHashAlgByIndex(i);
       // make sure that the PCR is implemented for this algorithm
       if(PcrIsAllocated(pcrHandle,
                           hashObject->state.hashState[i].state.hashAlg))
       {
           // Complete hash
           digest.t.size = CryptGetHashDigestSize(hash);
           CryptCompleteHash2B(&hashObject->state.hashState[i], &digest.b);

              PcrDrtm(pcrHandle, hash, &digest);
         }
   }

   // Flush sequence object.
//
   ObjectFlush(g_DRTMHandle);

   g_DRTMHandle = TPM_RH_UNASSIGNED;

   g_DrtmPreStartup = TRUE;

   return;
}