1 /* Microsoft Reference Implementation for TPM 2.0
2 *
3 * The copyright in this software is being made available under the BSD License,
4 * included below. This software may be subject to other third party and
5 * contributor rights, including patent rights, and no such rights are granted
6 * under this license.
7 *
8 * Copyright (c) Microsoft Corporation
9 *
10 * All rights reserved.
11 *
12 * BSD License
13 *
14 * Redistribution and use in source and binary forms, with or without modification,
15 * are permitted provided that the following conditions are met:
16 *
17 * Redistributions of source code must retain the above copyright notice, this list
18 * of conditions and the following disclaimer.
19 *
20 * Redistributions in binary form must reproduce the above copyright notice, this
21 * list of conditions and the following disclaimer in the documentation and/or
22 * other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 #include "Tpm.h"
36 #include "EventSequenceComplete_fp.h"
37
38 #if CC_EventSequenceComplete // Conditional expansion of this file
39
40 /*(See part 3 specification)
41 Complete an event sequence and flush the object.
42 */
43 // Return Type: TPM_RC
44 // TPM_RC_LOCALITY PCR extension is not allowed at the current locality
45 // TPM_RC_MODE input handle is not a valid event sequence object
46 TPM_RC
TPM2_EventSequenceComplete(EventSequenceComplete_In * in,EventSequenceComplete_Out * out)47 TPM2_EventSequenceComplete(
48 EventSequenceComplete_In *in, // IN: input parameter list
49 EventSequenceComplete_Out *out // OUT: output parameter list
50 )
51 {
52 HASH_OBJECT *hashObject;
53 UINT32 i;
54 TPM_ALG_ID hashAlg;
55 // Input validation
56 // get the event sequence object pointer
57 hashObject = (HASH_OBJECT *)HandleToObject(in->sequenceHandle);
58
59 // input handle must reference an event sequence object
60 if(hashObject->attributes.eventSeq != SET)
61 return TPM_RCS_MODE + RC_EventSequenceComplete_sequenceHandle;
62
63 // see if a PCR extend is requested in call
64 if(in->pcrHandle != TPM_RH_NULL)
65 {
66 // see if extend of the PCR is allowed at the locality of the command,
67 if(!PCRIsExtendAllowed(in->pcrHandle))
68 return TPM_RC_LOCALITY;
69 // if an extend is going to take place, then check to see if there has
70 // been an orderly shutdown. If so, and the selected PCR is one of the
71 // state saved PCR, then the orderly state has to change. The orderly state
72 // does not change for PCR that are not preserved.
73 // NOTE: This doesn't just check for Shutdown(STATE) because the orderly
74 // state will have to change if this is a state-saved PCR regardless
75 // of the current state. This is because a subsequent Shutdown(STATE) will
76 // check to see if there was an orderly shutdown and not do anything if
77 // there was. So, this must indicate that a future Shutdown(STATE) has
78 // something to do.
79 if(PCRIsStateSaved(in->pcrHandle))
80 RETURN_IF_ORDERLY;
81 }
82 // Command Output
83 out->results.count = 0;
84
85 for(i = 0; i < HASH_COUNT; i++)
86 {
87 hashAlg = CryptHashGetAlgByIndex(i);
88 // Update last piece of data
89 CryptDigestUpdate2B(&hashObject->state.hashState[i], &in->buffer.b);
90 // Complete hash
91 out->results.digests[out->results.count].hashAlg = hashAlg;
92 CryptHashEnd(&hashObject->state.hashState[i],
93 CryptHashGetDigestSize(hashAlg),
94 (BYTE *)&out->results.digests[out->results.count].digest);
95 // Extend PCR
96 if(in->pcrHandle != TPM_RH_NULL)
97 PCRExtend(in->pcrHandle, hashAlg,
98 CryptHashGetDigestSize(hashAlg),
99 (BYTE *)&out->results.digests[out->results.count].digest);
100 out->results.count++;
101 }
102 // Internal Data Update
103 // mark sequence object as evict so it will be flushed on the way out
104 hashObject->attributes.evict = SET;
105
106 return TPM_RC_SUCCESS;
107 }
108
109 #endif // CC_EventSequenceComplete