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_ECDH_KeyGen_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT keyHandle)15 TSS2_RC Tss2_Sys_ECDH_KeyGen_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_DH_OBJECT keyHandle)
18 {
19 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
20 TSS2_RC rval;
21
22 if (!ctx)
23 return TSS2_SYS_RC_BAD_REFERENCE;
24
25 rval = CommonPreparePrologue(ctx, TPM2_CC_ECDH_KeyGen);
26 if (rval)
27 return rval;
28
29 rval = Tss2_MU_UINT32_Marshal(keyHandle, ctx->cmdBuffer,
30 ctx->maxCmdSize,
31 &ctx->nextData);
32 if (rval)
33 return rval;
34
35 ctx->decryptAllowed = 0;
36 ctx->encryptAllowed = 1;
37 ctx->authAllowed = 1;
38
39 return CommonPrepareEpilogue(ctx);
40 }
41
Tss2_Sys_ECDH_KeyGen_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_ECC_POINT * zPoint,TPM2B_ECC_POINT * pubPoint)42 TSS2_RC Tss2_Sys_ECDH_KeyGen_Complete(
43 TSS2_SYS_CONTEXT *sysContext,
44 TPM2B_ECC_POINT *zPoint,
45 TPM2B_ECC_POINT *pubPoint)
46 {
47 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
48 TSS2_RC rval;
49
50 if (!ctx)
51 return TSS2_SYS_RC_BAD_REFERENCE;
52
53 rval = CommonComplete(ctx);
54 if (rval)
55 return rval;
56
57 rval = Tss2_MU_TPM2B_ECC_POINT_Unmarshal(ctx->cmdBuffer,
58 ctx->maxCmdSize,
59 &ctx->nextData,
60 zPoint);
61 if (rval)
62 return rval;
63
64 return Tss2_MU_TPM2B_ECC_POINT_Unmarshal(ctx->cmdBuffer,
65 ctx->maxCmdSize,
66 &ctx->nextData,
67 pubPoint);
68 }
69
Tss2_Sys_ECDH_KeyGen(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT keyHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM2B_ECC_POINT * zPoint,TPM2B_ECC_POINT * pubPoint,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)70 TSS2_RC Tss2_Sys_ECDH_KeyGen(
71 TSS2_SYS_CONTEXT *sysContext,
72 TPMI_DH_OBJECT keyHandle,
73 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
74 TPM2B_ECC_POINT *zPoint,
75 TPM2B_ECC_POINT *pubPoint,
76 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
77 {
78 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
79 TSS2_RC rval;
80
81 rval = Tss2_Sys_ECDH_KeyGen_Prepare(sysContext, keyHandle);
82 if (rval)
83 return rval;
84
85 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
86 if (rval)
87 return rval;
88
89 return Tss2_Sys_ECDH_KeyGen_Complete(sysContext, zPoint, pubPoint);
90 }
91