• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EC_Ephemeral_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_ECC_CURVE curveID)15 TSS2_RC Tss2_Sys_EC_Ephemeral_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_ECC_CURVE curveID)
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_EC_Ephemeral);
26     if (rval)
27         return rval;
28 
29     rval = Tss2_MU_UINT16_Marshal(curveID, 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_EC_Ephemeral_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_ECC_POINT * Q,UINT16 * counter)42 TSS2_RC Tss2_Sys_EC_Ephemeral_Complete(
43     TSS2_SYS_CONTEXT *sysContext,
44     TPM2B_ECC_POINT *Q,
45     UINT16 *counter)
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     rval = Tss2_MU_TPM2B_ECC_POINT_Unmarshal(ctx->cmdBuffer,
57                                              ctx->maxCmdSize,
58                                              &ctx->nextData, Q);
59     if (rval)
60         return rval;
61 
62     return Tss2_MU_UINT16_Unmarshal(ctx->cmdBuffer,
63                                     ctx->maxCmdSize,
64                                     &ctx->nextData, counter);
65 }
66 
Tss2_Sys_EC_Ephemeral(TSS2_SYS_CONTEXT * sysContext,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPMI_ECC_CURVE curveID,TPM2B_ECC_POINT * Q,UINT16 * counter,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)67 TSS2_RC Tss2_Sys_EC_Ephemeral(
68     TSS2_SYS_CONTEXT *sysContext,
69     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
70     TPMI_ECC_CURVE curveID,
71     TPM2B_ECC_POINT *Q,
72     UINT16 *counter,
73     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
74 {
75     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
76     TSS2_RC rval;
77 
78     rval = Tss2_Sys_EC_Ephemeral_Prepare(sysContext, curveID);
79     if (rval)
80         return rval;
81 
82     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
83     if (rval)
84         return rval;
85 
86     return Tss2_Sys_EC_Ephemeral_Complete(sysContext, Q, counter);
87 }
88