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_Duplicate_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT objectHandle,TPMI_DH_OBJECT newParentHandle,const TPM2B_DATA * encryptionKeyIn,const TPMT_SYM_DEF_OBJECT * symmetricAlg)15 TSS2_RC Tss2_Sys_Duplicate_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_DH_OBJECT objectHandle,
18 TPMI_DH_OBJECT newParentHandle,
19 const TPM2B_DATA *encryptionKeyIn,
20 const TPMT_SYM_DEF_OBJECT *symmetricAlg)
21 {
22 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
23 TSS2_RC rval;
24
25 if (!ctx || !symmetricAlg)
26 return TSS2_SYS_RC_BAD_REFERENCE;
27
28 rval = CommonPreparePrologue(ctx, TPM2_CC_Duplicate);
29 if (rval)
30 return rval;
31
32 rval = Tss2_MU_UINT32_Marshal(objectHandle, ctx->cmdBuffer,
33 ctx->maxCmdSize,
34 &ctx->nextData);
35 if (rval)
36 return rval;
37
38 rval = Tss2_MU_UINT32_Marshal(newParentHandle, ctx->cmdBuffer,
39 ctx->maxCmdSize,
40 &ctx->nextData);
41 if (rval)
42 return rval;
43
44 if (!encryptionKeyIn) {
45 ctx->decryptNull = 1;
46
47 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
48 ctx->maxCmdSize,
49 &ctx->nextData);
50 } else {
51
52 rval = Tss2_MU_TPM2B_DATA_Marshal(encryptionKeyIn, ctx->cmdBuffer,
53 ctx->maxCmdSize,
54 &ctx->nextData);
55 }
56
57 if (rval)
58 return rval;
59
60 rval = Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal(symmetricAlg,
61 ctx->cmdBuffer,
62 ctx->maxCmdSize,
63 &ctx->nextData);
64 if (rval)
65 return rval;
66
67 ctx->decryptAllowed = 1;
68 ctx->encryptAllowed = 1;
69 ctx->authAllowed = 1;
70
71 return CommonPrepareEpilogue(ctx);
72 }
73
Tss2_Sys_Duplicate_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_DATA * encryptionKeyOut,TPM2B_PRIVATE * duplicate,TPM2B_ENCRYPTED_SECRET * outSymSeed)74 TSS2_RC Tss2_Sys_Duplicate_Complete(
75 TSS2_SYS_CONTEXT *sysContext,
76 TPM2B_DATA *encryptionKeyOut,
77 TPM2B_PRIVATE *duplicate,
78 TPM2B_ENCRYPTED_SECRET *outSymSeed)
79 {
80 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
81 TSS2_RC rval;
82
83 if (!ctx)
84 return TSS2_SYS_RC_BAD_REFERENCE;
85
86 rval = CommonComplete(ctx);
87 if (rval)
88 return rval;
89
90 rval = Tss2_MU_TPM2B_DATA_Unmarshal(ctx->cmdBuffer,
91 ctx->maxCmdSize,
92 &ctx->nextData,
93 encryptionKeyOut);
94 if (rval)
95 return rval;
96
97 rval = Tss2_MU_TPM2B_PRIVATE_Unmarshal(ctx->cmdBuffer,
98 ctx->maxCmdSize,
99 &ctx->nextData,
100 duplicate);
101 if (rval)
102 return rval;
103
104 return Tss2_MU_TPM2B_ENCRYPTED_SECRET_Unmarshal(ctx->cmdBuffer,
105 ctx->maxCmdSize,
106 &ctx->nextData,
107 outSymSeed);
108 }
109
Tss2_Sys_Duplicate(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT objectHandle,TPMI_DH_OBJECT newParentHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DATA * encryptionKeyIn,const TPMT_SYM_DEF_OBJECT * symmetricAlg,TPM2B_DATA * encryptionKeyOut,TPM2B_PRIVATE * duplicate,TPM2B_ENCRYPTED_SECRET * outSymSeed,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)110 TSS2_RC Tss2_Sys_Duplicate(
111 TSS2_SYS_CONTEXT *sysContext,
112 TPMI_DH_OBJECT objectHandle,
113 TPMI_DH_OBJECT newParentHandle,
114 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
115 const TPM2B_DATA *encryptionKeyIn,
116 const TPMT_SYM_DEF_OBJECT *symmetricAlg,
117 TPM2B_DATA *encryptionKeyOut,
118 TPM2B_PRIVATE *duplicate,
119 TPM2B_ENCRYPTED_SECRET *outSymSeed,
120 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
121 {
122 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
123 TSS2_RC rval;
124
125 if (!symmetricAlg)
126 return TSS2_SYS_RC_BAD_REFERENCE;
127
128 rval = Tss2_Sys_Duplicate_Prepare(sysContext, objectHandle,
129 newParentHandle, encryptionKeyIn,
130 symmetricAlg);
131 if (rval)
132 return rval;
133
134 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
135 if (rval)
136 return rval;
137
138 return Tss2_Sys_Duplicate_Complete(sysContext, encryptionKeyOut,
139 duplicate, outSymSeed);
140 }
141