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