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_SequenceComplete_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT sequenceHandle,const TPM2B_MAX_BUFFER * buffer,TPMI_RH_HIERARCHY hierarchy)15 TSS2_RC Tss2_Sys_SequenceComplete_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_DH_OBJECT sequenceHandle,
18 const TPM2B_MAX_BUFFER *buffer,
19 TPMI_RH_HIERARCHY hierarchy)
20 {
21 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
22 TSS2_RC rval;
23
24 if (!ctx)
25 return TSS2_SYS_RC_BAD_REFERENCE;
26
27 rval = CommonPreparePrologue(ctx, TPM2_CC_SequenceComplete);
28 if (rval)
29 return rval;
30
31 rval = Tss2_MU_UINT32_Marshal(sequenceHandle, ctx->cmdBuffer,
32 ctx->maxCmdSize,
33 &ctx->nextData);
34 if (rval)
35 return rval;
36
37 if (!buffer) {
38 ctx->decryptNull = 1;
39
40 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
41 ctx->maxCmdSize,
42 &ctx->nextData);
43 } else {
44
45 rval = Tss2_MU_TPM2B_MAX_BUFFER_Marshal(buffer, ctx->cmdBuffer,
46 ctx->maxCmdSize,
47 &ctx->nextData);
48 }
49
50 if (rval)
51 return rval;
52
53 rval = Tss2_MU_UINT32_Marshal(hierarchy, ctx->cmdBuffer,
54 ctx->maxCmdSize,
55 &ctx->nextData);
56 if (rval)
57 return rval;
58
59 ctx->decryptAllowed = 1;
60 ctx->encryptAllowed = 1;
61 ctx->authAllowed = 1;
62
63 return CommonPrepareEpilogue(ctx);
64 }
65
Tss2_Sys_SequenceComplete_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_DIGEST * result,TPMT_TK_HASHCHECK * validation)66 TSS2_RC Tss2_Sys_SequenceComplete_Complete(
67 TSS2_SYS_CONTEXT *sysContext,
68 TPM2B_DIGEST *result,
69 TPMT_TK_HASHCHECK *validation)
70 {
71 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
72 TSS2_RC rval;
73
74 if (!ctx)
75 return TSS2_SYS_RC_BAD_REFERENCE;
76
77 rval = CommonComplete(ctx);
78 if (rval)
79 return rval;
80
81 rval = Tss2_MU_TPM2B_DIGEST_Unmarshal(ctx->cmdBuffer,
82 ctx->maxCmdSize,
83 &ctx->nextData, result);
84 if (rval)
85 return rval;
86
87 return Tss2_MU_TPMT_TK_HASHCHECK_Unmarshal(ctx->cmdBuffer,
88 ctx->maxCmdSize,
89 &ctx->nextData, validation);
90 }
91
Tss2_Sys_SequenceComplete(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT sequenceHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_MAX_BUFFER * buffer,TPMI_RH_HIERARCHY hierarchy,TPM2B_DIGEST * result,TPMT_TK_HASHCHECK * validation,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)92 TSS2_RC Tss2_Sys_SequenceComplete(
93 TSS2_SYS_CONTEXT *sysContext,
94 TPMI_DH_OBJECT sequenceHandle,
95 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
96 const TPM2B_MAX_BUFFER *buffer,
97 TPMI_RH_HIERARCHY hierarchy,
98 TPM2B_DIGEST *result,
99 TPMT_TK_HASHCHECK *validation,
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_SequenceComplete_Prepare(sysContext, sequenceHandle,
106 buffer, hierarchy);
107 if (rval)
108 return rval;
109
110 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
111 if (rval)
112 return rval;
113
114 return Tss2_Sys_SequenceComplete_Complete(sysContext, result, validation);
115 }
116