| 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 "Load_fp.h" |
| 37 |
|
| 38 |
#if CC_Load // Conditional expansion of this file |
| 39 |
|
| 40 |
#include "Object_spt_fp.h" |
| 41 |
|
| 42 |
/*(See part 3 specification) |
| 43 |
// Load an ordinary or temporary object |
| 44 |
*/ |
| 45 |
// Return Type: TPM_RC |
| 46 |
// TPM_RC_ATTRIBUTES 'inPulblic' attributes are not allowed with selected |
| 47 |
// parent |
| 48 |
// TPM_RC_BINDING 'inPrivate' and 'inPublic' are not |
| 49 |
// cryptographically bound |
| 50 |
// TPM_RC_HASH incorrect hash selection for signing key or |
| 51 |
// the 'nameAlg' for 'inPubic is not valid |
| 52 |
// TPM_RC_INTEGRITY HMAC on 'inPrivate' was not valid |
| 53 |
// TPM_RC_KDF KDF selection not allowed |
| 54 |
// TPM_RC_KEY the size of the object's 'unique' field is not |
| 55 |
// consistent with the indicated size in the object's |
| 56 |
// parameters |
| 57 |
// TPM_RC_OBJECT_MEMORY no available object slot |
| 58 |
// TPM_RC_SCHEME the signing scheme is not valid for the key |
| 59 |
// TPM_RC_SENSITIVE the 'inPrivate' did not unmarshal correctly |
| 60 |
// TPM_RC_SIZE 'inPrivate' missing, or 'authPolicy' size for |
| 61 |
// 'inPublic' or is not valid |
| 62 |
// TPM_RC_SYMMETRIC symmetric algorithm not provided when required |
| 63 |
// TPM_RC_TYPE 'parentHandle' is not a storage key, or the object |
| 64 |
// to load is a storage key but its parameters do not |
| 65 |
// match the parameters of the parent. |
| 66 |
// TPM_RC_VALUE decryption failure |
| 67 |
TPM_RC |
| 68 |
TPM2_Load( |
| 69 |
Load_In *in, // IN: input parameter list |
| 70 |
Load_Out *out // OUT: output parameter list |
| 71 |
) |
| 72 |
{ |
| 73 |
TPM_RC result = TPM_RC_SUCCESS; |
| 74 |
TPMT_SENSITIVE sensitive; |
| 75 |
OBJECT *parentObject; |
| 76 |
OBJECT *newObject; |
| 77 |
|
| 78 |
// Input Validation |
| 79 |
// Don't get invested in loading if there is no place to put it. |
| 80 |
newObject = FindEmptyObjectSlot(&out->objectHandle); |
| 81 |
if(newObject == NULL) |
| 82 |
return TPM_RC_OBJECT_MEMORY; |
| 83 |
|
| 84 |
if(in->inPrivate.t.size == 0) |
| 85 |
return TPM_RCS_SIZE + RC_Load_inPrivate; |
| 86 |
|
| 87 |
parentObject = HandleToObject(in->parentHandle); |
| 88 |
pAssert(parentObject != NULL); |
| 89 |
// Is the object that is being used as the parent actually a parent. |
| 90 |
if(!ObjectIsParent(parentObject)) |
| 91 |
return TPM_RCS_TYPE + RC_Load_parentHandle; |
| 92 |
|
| 93 |
// Compute the name of object. If there isn't one, it is because the nameAlg is |
| 94 |
// not valid. |
| 95 |
PublicMarshalAndComputeName(&in->inPublic.publicArea, &out->name); |
| 96 |
if(out->name.t.size == 0) |
| 97 |
return TPM_RCS_HASH + RC_Load_inPublic; |
| 98 |
|
| 99 |
// Retrieve sensitive data. |
| 100 |
result = PrivateToSensitive(&in->inPrivate.b, &out->name.b, parentObject, |
| 101 |
in->inPublic.publicArea.nameAlg, |
| 102 |
&sensitive); |
| 103 |
if(result != TPM_RC_SUCCESS) |
| 104 |
return RcSafeAddToResult(result, RC_Load_inPrivate); |
| 105 |
|
| 106 |
// Internal Data Update |
| 107 |
// Load and validate object |
| 108 |
result = ObjectLoad(newObject, parentObject, |
| 109 |
&in->inPublic.publicArea, &sensitive, |
| 110 |
RC_Load_inPublic, RC_Load_inPrivate, |
| 111 |
&out->name); |
| 112 |
if(result == TPM_RC_SUCCESS) |
| 113 |
{ |
| 114 |
// Set the common OBJECT attributes for a loaded object. |
| 115 |
ObjectSetLoadedAttributes(newObject, in->parentHandle); |
| 116 |
} |
| 117 |
return result; |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
#endif // CC_Load |