1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3 * Copyright (c) 2018, 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_CreateLoaded_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_HIERARCHY parentHandle,const TPM2B_SENSITIVE_CREATE * inSensitive,const TPM2B_TEMPLATE * inPublic)15 TSS2_RC Tss2_Sys_CreateLoaded_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_RH_HIERARCHY parentHandle,
18 const TPM2B_SENSITIVE_CREATE *inSensitive,
19 const TPM2B_TEMPLATE *inPublic)
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 if (!inPublic)
28 return TSS2_SYS_RC_BAD_REFERENCE;
29
30 rval = CommonPreparePrologue(ctx, TPM2_CC_CreateLoaded);
31 if (rval)
32 return rval;
33
34 rval = Tss2_MU_UINT32_Marshal(parentHandle, ctx->cmdBuffer,
35 ctx->maxCmdSize,
36 &ctx->nextData);
37 if (rval)
38 return rval;
39
40 if (!inSensitive) {
41 ctx->decryptNull = 1;
42
43 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
44 ctx->maxCmdSize,
45 &ctx->nextData);
46 } else {
47 rval = Tss2_MU_TPM2B_SENSITIVE_CREATE_Marshal(inSensitive,
48 ctx->cmdBuffer,
49 ctx->maxCmdSize,
50 &ctx->nextData);
51 }
52
53 if (rval)
54 return rval;
55
56 rval = Tss2_MU_TPM2B_TEMPLATE_Marshal(inPublic, ctx->cmdBuffer,
57 ctx->maxCmdSize,
58 &ctx->nextData);
59 if (rval)
60 return rval;
61
62 ctx->decryptAllowed = 1;
63 ctx->encryptAllowed = 1;
64 ctx->authAllowed = 1;
65
66 rval = CommonPrepareEpilogue(ctx);
67 return rval;
68 }
69
Tss2_Sys_CreateLoaded_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2_HANDLE * objectHandle,TPM2B_PRIVATE * outPrivate,TPM2B_PUBLIC * outPublic,TPM2B_NAME * name)70 TSS2_RC Tss2_Sys_CreateLoaded_Complete(
71 TSS2_SYS_CONTEXT *sysContext,
72 TPM2_HANDLE *objectHandle,
73 TPM2B_PRIVATE *outPrivate,
74 TPM2B_PUBLIC *outPublic,
75 TPM2B_NAME *name)
76 {
77 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
78 TSS2_RC rval;
79
80 if (!ctx)
81 return TSS2_SYS_RC_BAD_REFERENCE;
82
83 rval = Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
84 ctx->maxCmdSize,
85 &ctx->nextData, objectHandle);
86 if (rval)
87 return rval;
88
89 rval = CommonComplete(ctx);
90 if (rval)
91 return rval;
92
93 rval = Tss2_MU_TPM2B_PRIVATE_Unmarshal(ctx->cmdBuffer,
94 ctx->maxCmdSize,
95 &ctx->nextData, outPrivate);
96 if (rval)
97 return rval;
98
99 rval = Tss2_MU_TPM2B_PUBLIC_Unmarshal(ctx->cmdBuffer,
100 ctx->maxCmdSize,
101 &ctx->nextData, outPublic);
102 if (rval)
103 return rval;
104
105 rval = Tss2_MU_TPM2B_NAME_Unmarshal(ctx->cmdBuffer,
106 ctx->maxCmdSize,
107 &ctx->nextData, name);
108 return rval;
109 }
110
Tss2_Sys_CreateLoaded(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_HIERARCHY parentHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_SENSITIVE_CREATE * inSensitive,const TPM2B_TEMPLATE * inPublic,TPM2_HANDLE * objectHandle,TPM2B_PRIVATE * outPrivate,TPM2B_PUBLIC * outPublic,TPM2B_NAME * name,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)111 TSS2_RC Tss2_Sys_CreateLoaded(
112 TSS2_SYS_CONTEXT *sysContext,
113 TPMI_RH_HIERARCHY parentHandle,
114 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
115 const TPM2B_SENSITIVE_CREATE *inSensitive,
116 const TPM2B_TEMPLATE *inPublic,
117 TPM2_HANDLE *objectHandle,
118 TPM2B_PRIVATE *outPrivate,
119 TPM2B_PUBLIC *outPublic,
120 TPM2B_NAME *name,
121 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
122 {
123 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
124 TSS2_RC rval;
125
126 if (!ctx || !objectHandle || !outPrivate || !outPublic || !name)
127 return TSS2_SYS_RC_BAD_REFERENCE;
128
129 rval = Tss2_Sys_CreateLoaded_Prepare(sysContext, parentHandle,
130 inSensitive, inPublic);
131 if (rval)
132 return rval;
133
134 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
135
136 if (rval)
137 return rval;
138
139 rval = Tss2_Sys_CreateLoaded_Complete(sysContext, objectHandle, outPrivate,
140 outPublic, name);
141 return rval;
142 }
143