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 "HMAC_Start_fp.h"
37
38 #if CC_HMAC_Start // Conditional expansion of this file
39
40 /*(See part 3 specification)
41 // Initialize a HMAC sequence and create a sequence object
42 */
43 // Return Type: TPM_RC
44 // TPM_RC_ATTRIBUTES key referenced by 'handle' is not a signing key
45 // or is restricted
46 // TPM_RC_OBJECT_MEMORY no space to create an internal object
47 // TPM_RC_KEY key referenced by 'handle' is not an HMAC key
48 // TPM_RC_VALUE 'hashAlg' is not compatible with the hash algorithm
49 // of the scheme of the object referenced by 'handle'
50 TPM_RC
TPM2_HMAC_Start(HMAC_Start_In * in,HMAC_Start_Out * out)51 TPM2_HMAC_Start(
52 HMAC_Start_In *in, // IN: input parameter list
53 HMAC_Start_Out *out // OUT: output parameter list
54 )
55 {
56 OBJECT *keyObject;
57 TPMT_PUBLIC *publicArea;
58 TPM_ALG_ID hashAlg;
59
60 // Input Validation
61
62 // Get HMAC key object and public area pointers
63 keyObject = HandleToObject(in->handle);
64 publicArea = &keyObject->publicArea;
65
66 // Make sure that the key is an HMAC key
67 if(publicArea->type != TPM_ALG_KEYEDHASH)
68 return TPM_RCS_TYPE + RC_HMAC_Start_handle;
69
70 // and that it is unrestricted
71 if(IS_ATTRIBUTE(publicArea->objectAttributes, TPMA_OBJECT, restricted))
72 return TPM_RCS_ATTRIBUTES + RC_HMAC_Start_handle;
73
74 // and that it is a signing key
75 if(!IS_ATTRIBUTE(publicArea->objectAttributes, TPMA_OBJECT, sign))
76 return TPM_RCS_KEY + RC_HMAC_Start_handle;
77
78 // See if the key has a default
79 if(publicArea->parameters.keyedHashDetail.scheme.scheme == TPM_ALG_NULL)
80 // it doesn't so use the input value
81 hashAlg = in->hashAlg;
82 else
83 {
84 // key has a default so use it
85 hashAlg
86 = publicArea->parameters.keyedHashDetail.scheme.details.hmac.hashAlg;
87 // and verify that the input was either the TPM_ALG_NULL or the default
88 if(in->hashAlg != TPM_ALG_NULL && in->hashAlg != hashAlg)
89 hashAlg = TPM_ALG_NULL;
90 }
91 // if we ended up without a hash algorithm then return an error
92 if(hashAlg == TPM_ALG_NULL)
93 return TPM_RCS_VALUE + RC_HMAC_Start_hashAlg;
94
95 // Internal Data Update
96
97 // Create a HMAC sequence object. A TPM_RC_OBJECT_MEMORY error may be
98 // returned at this point
99 return ObjectCreateHMACSequence(hashAlg,
100 keyObject,
101 &in->auth,
102 &out->sequenceHandle);
103 }
104
105 #endif // CC_HMAC_Start