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_Commit_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT signHandle,const TPM2B_ECC_POINT * P1,const TPM2B_SENSITIVE_DATA * s2,const TPM2B_ECC_PARAMETER * y2)15 TSS2_RC Tss2_Sys_Commit_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_DH_OBJECT signHandle,
18 const TPM2B_ECC_POINT *P1,
19 const TPM2B_SENSITIVE_DATA *s2,
20 const TPM2B_ECC_PARAMETER *y2)
21 {
22 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
23 TSS2_RC rval;
24
25 if (!ctx)
26 return TSS2_SYS_RC_BAD_REFERENCE;
27
28 rval = CommonPreparePrologue(ctx, TPM2_CC_Commit);
29 if (rval)
30 return rval;
31
32 rval = Tss2_MU_UINT32_Marshal(signHandle, ctx->cmdBuffer,
33 ctx->maxCmdSize,
34 &ctx->nextData);
35 if (rval)
36 return rval;
37
38 if (!P1) {
39 ctx->decryptNull = 1;
40
41 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
42 ctx->maxCmdSize,
43 &ctx->nextData);
44 } else {
45 rval = Tss2_MU_TPM2B_ECC_POINT_Marshal(P1, ctx->cmdBuffer,
46 ctx->maxCmdSize,
47 &ctx->nextData);
48 }
49
50 if (rval)
51 return rval;
52
53 if (!s2) {
54 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
55 ctx->maxCmdSize,
56 &ctx->nextData);
57
58 } else {
59
60 rval = Tss2_MU_TPM2B_SENSITIVE_DATA_Marshal(s2, ctx->cmdBuffer,
61 ctx->maxCmdSize,
62 &ctx->nextData);
63 }
64
65 if (rval)
66 return rval;
67
68 if (!y2) {
69 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
70 ctx->maxCmdSize,
71 &ctx->nextData);
72
73 } else {
74
75 rval = Tss2_MU_TPM2B_ECC_PARAMETER_Marshal(y2, ctx->cmdBuffer,
76 ctx->maxCmdSize,
77 &ctx->nextData);
78 }
79
80 if (rval)
81 return rval;
82
83 ctx->decryptAllowed = 1;
84 ctx->encryptAllowed = 1;
85 ctx->authAllowed = 1;
86
87 return CommonPrepareEpilogue(ctx);
88 }
89
Tss2_Sys_Commit_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_ECC_POINT * K,TPM2B_ECC_POINT * L,TPM2B_ECC_POINT * E,UINT16 * counter)90 TSS2_RC Tss2_Sys_Commit_Complete(
91 TSS2_SYS_CONTEXT *sysContext,
92 TPM2B_ECC_POINT *K,
93 TPM2B_ECC_POINT *L,
94 TPM2B_ECC_POINT *E,
95 UINT16 *counter)
96 {
97 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
98 TSS2_RC rval;
99
100 if (!ctx)
101 return TSS2_SYS_RC_BAD_REFERENCE;
102
103 rval = CommonComplete(ctx);
104 if (rval)
105 return rval;
106
107 rval = Tss2_MU_TPM2B_ECC_POINT_Unmarshal(ctx->cmdBuffer,
108 ctx->maxCmdSize,
109 &ctx->nextData, K);
110 if (rval)
111 return rval;
112
113 rval = Tss2_MU_TPM2B_ECC_POINT_Unmarshal(ctx->cmdBuffer,
114 ctx->maxCmdSize,
115 &ctx->nextData, L);
116 if (rval)
117 return rval;
118
119 rval = Tss2_MU_TPM2B_ECC_POINT_Unmarshal(ctx->cmdBuffer,
120 ctx->maxCmdSize,
121 &ctx->nextData, E);
122 if (rval)
123 return rval;
124
125 return Tss2_MU_UINT16_Unmarshal(ctx->cmdBuffer,
126 ctx->maxCmdSize,
127 &ctx->nextData, counter);
128 }
129
Tss2_Sys_Commit(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT signHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_ECC_POINT * P1,const TPM2B_SENSITIVE_DATA * s2,const TPM2B_ECC_PARAMETER * y2,TPM2B_ECC_POINT * K,TPM2B_ECC_POINT * L,TPM2B_ECC_POINT * E,UINT16 * counter,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)130 TSS2_RC Tss2_Sys_Commit(
131 TSS2_SYS_CONTEXT *sysContext,
132 TPMI_DH_OBJECT signHandle,
133 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
134 const TPM2B_ECC_POINT *P1,
135 const TPM2B_SENSITIVE_DATA *s2,
136 const TPM2B_ECC_PARAMETER *y2,
137 TPM2B_ECC_POINT *K,
138 TPM2B_ECC_POINT *L,
139 TPM2B_ECC_POINT *E,
140 UINT16 *counter,
141 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
142 {
143 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
144 TSS2_RC rval;
145
146 rval = Tss2_Sys_Commit_Prepare(sysContext, signHandle, P1, s2, y2);
147 if (rval)
148 return rval;
149
150 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
151 if (rval)
152 return rval;
153
154 return Tss2_Sys_Commit_Complete(sysContext, K, L, E, counter);
155 }
156