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_PCR_Event_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_PCR pcrHandle,const TPM2B_EVENT * eventData)15 TSS2_RC Tss2_Sys_PCR_Event_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_DH_PCR pcrHandle,
18     const TPM2B_EVENT *eventData)
19 {
20     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
21     TSS2_RC rval;
22 
23     if (!ctx)
24         return TSS2_SYS_RC_BAD_REFERENCE;
25 
26     rval = CommonPreparePrologue(ctx, TPM2_CC_PCR_Event);
27     if (rval)
28         return rval;
29 
30     rval = Tss2_MU_UINT32_Marshal(pcrHandle, ctx->cmdBuffer,
31                                   ctx->maxCmdSize,
32                                   &ctx->nextData);
33     if (rval)
34         return rval;
35 
36     if (!eventData) {
37         rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
38                                       ctx->maxCmdSize,
39                                       &ctx->nextData);
40 
41     } else {
42 
43         rval = Tss2_MU_TPM2B_EVENT_Marshal(eventData, ctx->cmdBuffer,
44                                            ctx->maxCmdSize,
45                                            &ctx->nextData);
46     }
47 
48     if (rval)
49         return rval;
50 
51     ctx->decryptAllowed = 1;
52     ctx->encryptAllowed = 0;
53     ctx->authAllowed = 1;
54 
55     return CommonPrepareEpilogue(ctx);
56 }
57 
Tss2_Sys_PCR_Event_Complete(TSS2_SYS_CONTEXT * sysContext,TPML_DIGEST_VALUES * digests)58 TSS2_RC Tss2_Sys_PCR_Event_Complete(
59     TSS2_SYS_CONTEXT *sysContext,
60     TPML_DIGEST_VALUES *digests)
61 {
62     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
63     TSS2_RC rval;
64 
65     if (!ctx)
66         return TSS2_SYS_RC_BAD_REFERENCE;
67 
68     rval = CommonComplete(ctx);
69     if (rval)
70         return rval;
71 
72     return Tss2_MU_TPML_DIGEST_VALUES_Unmarshal(ctx->cmdBuffer,
73                                                 ctx->maxCmdSize,
74                                                 &ctx->nextData,
75                                                 digests);
76 }
77 
Tss2_Sys_PCR_Event(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_PCR pcrHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_EVENT * eventData,TPML_DIGEST_VALUES * digests,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)78 TSS2_RC Tss2_Sys_PCR_Event(
79     TSS2_SYS_CONTEXT *sysContext,
80     TPMI_DH_PCR pcrHandle,
81     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
82     const TPM2B_EVENT *eventData,
83     TPML_DIGEST_VALUES *digests,
84     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
85 {
86     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
87     TSS2_RC rval;
88 
89     rval = Tss2_Sys_PCR_Event_Prepare(sysContext, pcrHandle, eventData);
90     if (rval)
91         return rval;
92 
93     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
94     if (rval)
95         return rval;
96 
97     return Tss2_Sys_PCR_Event_Complete(sysContext, digests);
98 }
99