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_Load_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT parentHandle,const TPM2B_PRIVATE * inPrivate,const TPM2B_PUBLIC * inPublic)15 TSS2_RC Tss2_Sys_Load_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_DH_OBJECT parentHandle,
18 const TPM2B_PRIVATE *inPrivate,
19 const TPM2B_PUBLIC *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 rval = CommonPreparePrologue(ctx, TPM2_CC_Load);
28 if (rval)
29 return rval;
30
31 rval = Tss2_MU_UINT32_Marshal(parentHandle, ctx->cmdBuffer,
32 ctx->maxCmdSize,
33 &ctx->nextData);
34 if (rval)
35 return rval;
36
37 if (!inPrivate) {
38 ctx->decryptNull = 1;
39
40 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
41 ctx->maxCmdSize,
42 &ctx->nextData);
43 } else {
44
45 rval = Tss2_MU_TPM2B_PRIVATE_Marshal(inPrivate, ctx->cmdBuffer,
46 ctx->maxCmdSize,
47 &ctx->nextData);
48 }
49
50 if (rval)
51 return rval;
52
53 if (!inPublic) {
54 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
55 ctx->maxCmdSize,
56 &ctx->nextData);
57
58 } else {
59 rval = ValidatePublicTemplate(inPublic);
60
61 if (rval)
62 return rval;
63
64 rval = Tss2_MU_TPM2B_PUBLIC_Marshal(inPublic, ctx->cmdBuffer,
65 ctx->maxCmdSize,
66 &ctx->nextData);
67 }
68
69 if (rval)
70 return rval;
71
72 ctx->decryptAllowed = 1;
73 ctx->encryptAllowed = 1;
74 ctx->authAllowed = 1;
75
76 return CommonPrepareEpilogue(ctx);
77 }
78
Tss2_Sys_Load_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2_HANDLE * objectHandle,TPM2B_NAME * name)79 TSS2_RC Tss2_Sys_Load_Complete(
80 TSS2_SYS_CONTEXT *sysContext,
81 TPM2_HANDLE *objectHandle,
82 TPM2B_NAME *name)
83 {
84 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
85 TSS2_RC rval;
86
87 if (!ctx)
88 return TSS2_SYS_RC_BAD_REFERENCE;
89
90 rval = Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
91 ctx->maxCmdSize,
92 &ctx->nextData, objectHandle);
93 if (rval)
94 return rval;
95
96 rval = CommonComplete(ctx);
97 if (rval)
98 return rval;
99
100 return Tss2_MU_TPM2B_NAME_Unmarshal(ctx->cmdBuffer,
101 ctx->maxCmdSize,
102 &ctx->nextData, name);
103 }
104
Tss2_Sys_Load(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT parentHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_PRIVATE * inPrivate,const TPM2B_PUBLIC * inPublic,TPM2_HANDLE * objectHandle,TPM2B_NAME * name,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)105 TSS2_RC Tss2_Sys_Load(
106 TSS2_SYS_CONTEXT *sysContext,
107 TPMI_DH_OBJECT parentHandle,
108 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
109 const TPM2B_PRIVATE *inPrivate,
110 const TPM2B_PUBLIC *inPublic,
111 TPM2_HANDLE *objectHandle,
112 TPM2B_NAME *name,
113 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
114 {
115 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
116 TSS2_RC rval;
117
118 rval = Tss2_Sys_Load_Prepare(sysContext, parentHandle, inPrivate, inPublic);
119 if (rval)
120 return rval;
121
122 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
123 if (rval)
124 return rval;
125
126 return Tss2_Sys_Load_Complete(sysContext, objectHandle, name);
127 }
128