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 "LoadExternal_fp.h"
37
38 #if CC_LoadExternal // Conditional expansion of this file
39
40 #include "Object_spt_fp.h"
41
42 /*(See part 3 specification)
43 // to load an object that is not a Protected Object into the public portion
44 // of an object into the TPM. The command allows loading of a public area or
45 // both a public and sensitive area
46 */
47 // Return Type: TPM_RC
48 // TPM_RC_ATTRIBUTES 'fixedParent', 'fixedTPM', and 'restricted' must
49 // be CLEAR if sensitive portion of an object is loaded
50 // TPM_RC_BINDING the 'inPublic' and 'inPrivate' structures are not
51 // cryptographically bound
52 // TPM_RC_HASH incorrect hash selection for signing key
53 // TPM_RC_HIERARCHY 'hierarchy' is turned off, or only NULL hierarchy
54 // is allowed when loading public and private parts
55 // of an object
56 // TPM_RC_KDF incorrect KDF selection for decrypting
57 // keyedHash object
58 // TPM_RC_KEY the size of the object's 'unique' field is not
59 // consistent with the indicated size in the object's
60 // parameters
61 // TPM_RC_OBJECT_MEMORY if there is no free slot for an object
62 // TPM_RC_ECC_POINT for a public-only ECC key, the ECC point is not
63 // on the curve
64 // TPM_RC_SCHEME the signing scheme is not valid for the key
65 // TPM_RC_SIZE 'authPolicy' is not zero and is not the size of a
66 // digest produced by the object's 'nameAlg'
67 // TPM_RH_NULL hierarchy
68 // TPM_RC_SYMMETRIC symmetric algorithm not provided when required
69 // TPM_RC_TYPE 'inPublic' and 'inPrivate' are not the same type
70 TPM_RC
TPM2_LoadExternal(LoadExternal_In * in,LoadExternal_Out * out)71 TPM2_LoadExternal(
72 LoadExternal_In *in, // IN: input parameter list
73 LoadExternal_Out *out // OUT: output parameter list
74 )
75 {
76 TPM_RC result;
77 OBJECT *object;
78 TPMT_SENSITIVE *sensitive = NULL;
79
80 // Input Validation
81 // Don't get invested in loading if there is no place to put it.
82 object = FindEmptyObjectSlot(&out->objectHandle);
83 if(object == NULL)
84 return TPM_RC_OBJECT_MEMORY;
85
86
87 // If the hierarchy to be associated with this object is turned off, the object
88 // cannot be loaded.
89 if(!HierarchyIsEnabled(in->hierarchy))
90 return TPM_RCS_HIERARCHY + RC_LoadExternal_hierarchy;
91
92 // For loading an object with both public and sensitive
93 if(in->inPrivate.size != 0)
94 {
95 // An external object with a sensitive area can only be loaded in the
96 // NULL hierarchy
97 if(in->hierarchy != TPM_RH_NULL)
98 return TPM_RCS_HIERARCHY + RC_LoadExternal_hierarchy;
99 // An external object with a sensitive area must have fixedTPM == CLEAR
100 // fixedParent == CLEAR so that it does not appear to be a key created by
101 // this TPM.
102 if(IS_ATTRIBUTE(in->inPublic.publicArea.objectAttributes, TPMA_OBJECT,
103 fixedTPM)
104 || IS_ATTRIBUTE(in->inPublic.publicArea.objectAttributes, TPMA_OBJECT,
105 fixedParent)
106 || IS_ATTRIBUTE(in->inPublic.publicArea.objectAttributes, TPMA_OBJECT,
107 restricted))
108 return TPM_RCS_ATTRIBUTES + RC_LoadExternal_inPublic;
109
110 // Have sensitive point to something other than NULL so that object
111 // initialization will load the sensitive part too
112 sensitive = &in->inPrivate.sensitiveArea;
113 }
114
115 // Need the name to initialize the object structure
116 PublicMarshalAndComputeName(&in->inPublic.publicArea, &out->name);
117
118 // Load and validate key
119 result = ObjectLoad(object, NULL,
120 &in->inPublic.publicArea, sensitive,
121 RC_LoadExternal_inPublic, RC_LoadExternal_inPrivate,
122 &out->name);
123 if(result == TPM_RC_SUCCESS)
124 {
125 object->attributes.external = SET;
126 // Set the common OBJECT attributes for a loaded object.
127 ObjectSetLoadedAttributes(object, in->hierarchy);
128 }
129 return result;
130 }
131
132 #endif // CC_LoadExternal