• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3  * Copyright (c) 2015 - 2017, Intel Corporation
4  * All rights reserved.
5  ***********************************************************************/
6 
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10 
11 #include "tss2_tpm2_types.h"
12 #include "tss2_mu.h"
13 #include "sysapi_util.h"
14 
Tss2_Sys_LoadExternal_Prepare(TSS2_SYS_CONTEXT * sysContext,const TPM2B_SENSITIVE * inPrivate,const TPM2B_PUBLIC * inPublic,TPMI_RH_HIERARCHY hierarchy)15 TSS2_RC Tss2_Sys_LoadExternal_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     const TPM2B_SENSITIVE *inPrivate,
18     const TPM2B_PUBLIC *inPublic,
19     TPMI_RH_HIERARCHY hierarchy)
20 {
21     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
22     TSS2_RC rval;
23 
24     if (!ctx)
25         return TSS2_SYS_RC_BAD_REFERENCE;
26 
27     rval = CommonPreparePrologue(ctx, TPM2_CC_LoadExternal);
28     if (rval)
29         return rval;
30 
31     /* If no private key is specified, set the private key size field to 0 */
32     if (!inPrivate) {
33         ctx->decryptNull = 1;
34 
35         rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
36                                       ctx->maxCmdSize,
37                                       &ctx->nextData);
38     } else {
39 
40         rval = Tss2_MU_TPM2B_SENSITIVE_Marshal(inPrivate,
41                                                ctx->cmdBuffer,
42                                                ctx->maxCmdSize,
43                                                &ctx->nextData);
44     }
45 
46     if (rval)
47         return rval;
48 
49     if (!inPublic) {
50         rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
51                                       ctx->maxCmdSize,
52                                       &ctx->nextData);
53 
54     } else {
55         rval = ValidatePublicTemplate(inPublic);
56 
57         if (rval)
58             return rval;
59 
60         rval = Tss2_MU_TPM2B_PUBLIC_Marshal(inPublic, ctx->cmdBuffer,
61                                             ctx->maxCmdSize,
62                                             &ctx->nextData);
63     }
64 
65     if (rval)
66         return rval;
67 
68     rval = Tss2_MU_UINT32_Marshal(hierarchy, ctx->cmdBuffer,
69                                   ctx->maxCmdSize,
70                                   &ctx->nextData);
71     if (rval)
72         return rval;
73 
74     ctx->decryptAllowed = 1;
75     ctx->encryptAllowed = 1;
76     ctx->authAllowed = 1;
77 
78     return CommonPrepareEpilogue(ctx);
79 }
80 
Tss2_Sys_LoadExternal_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2_HANDLE * objectHandle,TPM2B_NAME * name)81 TSS2_RC Tss2_Sys_LoadExternal_Complete(
82     TSS2_SYS_CONTEXT *sysContext,
83     TPM2_HANDLE *objectHandle,
84     TPM2B_NAME *name)
85 {
86     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
87     TSS2_RC rval;
88 
89     if (!ctx)
90         return TSS2_SYS_RC_BAD_REFERENCE;
91 
92     rval = Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
93                                     ctx->maxCmdSize,
94                                     &ctx->nextData,
95                                     objectHandle);
96     if (rval)
97         return rval;
98 
99     rval = CommonComplete(ctx);
100     if (rval)
101         return rval;
102 
103     return Tss2_MU_TPM2B_NAME_Unmarshal(ctx->cmdBuffer,
104                                         ctx->maxCmdSize,
105                                         &ctx->nextData, name);
106 }
107 
Tss2_Sys_LoadExternal(TSS2_SYS_CONTEXT * sysContext,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_SENSITIVE * inPrivate,const TPM2B_PUBLIC * inPublic,TPMI_RH_HIERARCHY hierarchy,TPM2_HANDLE * objectHandle,TPM2B_NAME * name,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)108 TSS2_RC Tss2_Sys_LoadExternal(
109     TSS2_SYS_CONTEXT *sysContext,
110     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
111     const TPM2B_SENSITIVE *inPrivate,
112     const TPM2B_PUBLIC *inPublic,
113     TPMI_RH_HIERARCHY hierarchy,
114     TPM2_HANDLE *objectHandle,
115     TPM2B_NAME *name,
116     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
117 {
118     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
119     TSS2_RC rval;
120 
121     rval = Tss2_Sys_LoadExternal_Prepare(sysContext, inPrivate, inPublic, hierarchy);
122     if (rval)
123         return rval;
124 
125     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
126     if (rval)
127         return rval;
128 
129     return Tss2_Sys_LoadExternal_Complete(sysContext, objectHandle, name);
130 }
131