• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3  * Copyright (c) 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_AC_Send_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT sendObject,TPMI_RH_NV_AUTH authHandle,TPMI_RH_AC ac,TPM2B_MAX_BUFFER * acDataIn)15 TSS2_RC Tss2_Sys_AC_Send_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_DH_OBJECT sendObject,
18     TPMI_RH_NV_AUTH authHandle,
19     TPMI_RH_AC ac,
20     TPM2B_MAX_BUFFER *acDataIn)
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_AC_Send);
29     if (rval)
30         return rval;
31 
32     rval = Tss2_MU_TPM2_HANDLE_Marshal(sendObject, ctx->cmdBuffer,
33                                        ctx->maxCmdSize,
34                                        &ctx->nextData);
35     if (rval)
36         return rval;
37 
38     rval = Tss2_MU_TPM2_HANDLE_Marshal(authHandle, ctx->cmdBuffer,
39                                        ctx->maxCmdSize,
40                                        &ctx->nextData);
41     if (rval)
42         return rval;
43 
44     rval = Tss2_MU_TPM2_HANDLE_Marshal(ac, ctx->cmdBuffer,
45                                        ctx->maxCmdSize,
46                                        &ctx->nextData);
47     if (rval)
48         return rval;
49 
50     if (!acDataIn) {
51         ctx->decryptNull = 1;
52 
53         rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
54                                       ctx->maxCmdSize,
55                                       &ctx->nextData);
56     } else {
57 
58         rval = Tss2_MU_TPM2B_MAX_BUFFER_Marshal(acDataIn, ctx->cmdBuffer,
59                                                 ctx->maxCmdSize,
60                                                 &ctx->nextData);
61     }
62     if (rval)
63         return rval;
64 
65     ctx->decryptAllowed = 1;
66     ctx->encryptAllowed = 0;
67     ctx->authAllowed = 1;
68 
69     return CommonPrepareEpilogue(ctx);
70 }
71 
Tss2_Sys_AC_Send_Complete(TSS2_SYS_CONTEXT * sysContext,TPMS_AC_OUTPUT * acDataOut)72 TSS2_RC Tss2_Sys_AC_Send_Complete(
73     TSS2_SYS_CONTEXT *sysContext,
74     TPMS_AC_OUTPUT *acDataOut)
75 {
76     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
77     TSS2_RC rval;
78 
79     if (!ctx)
80         return TSS2_SYS_RC_BAD_REFERENCE;
81 
82     rval = CommonComplete(ctx);
83     if (rval)
84         return rval;
85 
86     return Tss2_MU_TPMS_AC_OUTPUT_Unmarshal(ctx->cmdBuffer,
87                                             ctx->maxCmdSize,
88                                             &ctx->nextData,
89                                             acDataOut);
90 }
91 
Tss2_Sys_AC_Send(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT sendObject,TPMI_RH_NV_AUTH authHandle,TPMI_RH_AC ac,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM2B_MAX_BUFFER * acDataIn,TPMS_AC_OUTPUT * acDataOut,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)92 TSS2_RC Tss2_Sys_AC_Send(
93     TSS2_SYS_CONTEXT *sysContext,
94     TPMI_DH_OBJECT sendObject,
95     TPMI_RH_NV_AUTH authHandle,
96     TPMI_RH_AC ac,
97     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
98     TPM2B_MAX_BUFFER *acDataIn,
99     TPMS_AC_OUTPUT *acDataOut,
100     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
101 {
102     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
103     TSS2_RC rval;
104 
105     rval = Tss2_Sys_AC_Send_Prepare(sysContext, sendObject, authHandle, ac,
106                                     acDataIn);
107     if (rval)
108         return rval;
109 
110     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
111     if (rval)
112         return rval;
113 
114     return Tss2_Sys_AC_Send_Complete(sysContext, acDataOut);
115 }
116