• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SequenceUpdate_fp.h"
37 
38 #if CC_SequenceUpdate  // Conditional expansion of this file
39 
40 /*(See part 3 specification)
41 // This function is used to add data to a sequence object.
42 */
43 //  Return Type: TPM_RC
44 //      TPM_RC_MODE             'sequenceHandle' does not reference a hash or HMAC
45 //                              sequence object
46 TPM_RC
TPM2_SequenceUpdate(SequenceUpdate_In * in)47 TPM2_SequenceUpdate(
48     SequenceUpdate_In   *in             // IN: input parameter list
49     )
50 {
51     OBJECT                  *object;
52     HASH_OBJECT             *hashObject;
53 
54 // Input Validation
55 
56     // Get sequence object pointer
57     object = HandleToObject(in->sequenceHandle);
58     hashObject = (HASH_OBJECT *)object;
59 
60     // Check that referenced object is a sequence object.
61     if(!ObjectIsSequence(object))
62         return TPM_RCS_MODE + RC_SequenceUpdate_sequenceHandle;
63 
64 // Internal Data Update
65 
66     if(object->attributes.eventSeq == SET)
67     {
68         // Update event sequence object
69         UINT32           i;
70         for(i = 0; i < HASH_COUNT; i++)
71         {
72             // Update sequence object
73             CryptDigestUpdate2B(&hashObject->state.hashState[i], &in->buffer.b);
74         }
75     }
76     else
77     {
78         // Update hash/HMAC sequence object
79         if(hashObject->attributes.hashSeq == SET)
80         {
81             // Is this the first block of the sequence
82             if(hashObject->attributes.firstBlock == CLEAR)
83             {
84                 // If so, indicate that first block was received
85                 hashObject->attributes.firstBlock = SET;
86 
87                 // Check the first block to see if the first block can contain
88                 // the TPM_GENERATED_VALUE.  If it does, it is not safe for
89                 // a ticket.
90                 if(TicketIsSafe(&in->buffer.b))
91                     hashObject->attributes.ticketSafe = SET;
92             }
93             // Update sequence object hash/HMAC stack
94             CryptDigestUpdate2B(&hashObject->state.hashState[0], &in->buffer.b);
95         }
96         else if(object->attributes.hmacSeq == SET)
97         {
98             // Update sequence object HMAC stack
99             CryptDigestUpdate2B(&hashObject->state.hmacState.hashState,
100                                 &in->buffer.b);
101         }
102     }
103     return TPM_RC_SUCCESS;
104 }
105 
106 #endif // CC_SequenceUpdate