blob: 00106178e97253396f494bd48faad10117499046 [file] [log] [blame]
Vadim Bendebury56797522015-05-20 10:32:25 -07001// 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#include "PCR_Event_fp.h"
10//
11//
12// Error Returns Meaning
13//
14// TPM_RC_LOCALITY current command locality is not allowed to extend the PCR
15// referenced by pcrHandle
16//
17TPM_RC
18TPM2_PCR_Event(
19 PCR_Event_In *in, // IN: input parameter list
20 PCR_Event_Out *out // OUT: output parameter list
21 )
22{
23 TPM_RC result;
24 HASH_STATE hashState;
25 UINT32 i;
26 UINT16 size;
27
28// Input Validation
29
30 // If a PCR extend is required
31 if(in->pcrHandle != TPM_RH_NULL)
32 {
33 // If the PCR is not allow to extend, return error
34 if(!PCRIsExtendAllowed(in->pcrHandle))
35 return TPM_RC_LOCALITY;
36
37 // If PCR is state saved and we need to update orderlyState, check NV
38 // availability
39 if(PCRIsStateSaved(in->pcrHandle) && gp.orderlyState != SHUTDOWN_NONE)
40 {
41 result = NvIsAvailable();
42 if(result != TPM_RC_SUCCESS) return result;
43 g_clearOrderly = TRUE;
44 }
45 }
46
47// Internal Data Update
48
49 out->digests.count = HASH_COUNT;
50
51 // Iterate supported PCR bank algorithms to extend
52 for(i = 0; i < HASH_COUNT; i++)
53 {
54 TPM_ALG_ID hash = CryptGetHashAlgByIndex(i);
Jocelyn Bohra4ed3aa2015-07-30 10:44:16 -070055 out->digests.digests[i].hashAlg = hash;
Vadim Bendebury56797522015-05-20 10:32:25 -070056 size = CryptStartHash(hash, &hashState);
57 CryptUpdateDigest2B(&hashState, &in->eventData.b);
58 CryptCompleteHash(&hashState, size,
Jocelyn Bohra4ed3aa2015-07-30 10:44:16 -070059 (BYTE *) &out->digests.digests[i].digest);
Vadim Bendebury56797522015-05-20 10:32:25 -070060 if(in->pcrHandle != TPM_RH_NULL)
61 PCRExtend(in->pcrHandle, hash, size,
Jocelyn Bohra4ed3aa2015-07-30 10:44:16 -070062 (BYTE *) &out->digests.digests[i].digest);
Vadim Bendebury56797522015-05-20 10:32:25 -070063 }
64
65 return TPM_RC_SUCCESS;
66}