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_Extend_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_PCR pcrHandle,const TPML_DIGEST_VALUES * digests)15 TSS2_RC Tss2_Sys_PCR_Extend_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_DH_PCR pcrHandle,
18     const TPML_DIGEST_VALUES *digests)
19 {
20     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
21     TSS2_RC rval;
22 
23     if (!ctx || !digests)
24         return TSS2_SYS_RC_BAD_REFERENCE;
25 
26     rval = CommonPreparePrologue(ctx, TPM2_CC_PCR_Extend);
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     rval = Tss2_MU_TPML_DIGEST_VALUES_Marshal(digests, ctx->cmdBuffer,
37                                               ctx->maxCmdSize,
38                                               &ctx->nextData);
39     if (rval)
40         return rval;
41 
42     ctx->decryptAllowed = 0;
43     ctx->encryptAllowed = 0;
44     ctx->authAllowed = 1;
45 
46     return CommonPrepareEpilogue(ctx);
47 }
48 
Tss2_Sys_PCR_Extend_Complete(TSS2_SYS_CONTEXT * sysContext)49 TSS2_RC Tss2_Sys_PCR_Extend_Complete (
50     TSS2_SYS_CONTEXT *sysContext)
51 {
52     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
53 
54     if (!ctx)
55         return TSS2_SYS_RC_BAD_REFERENCE;
56 
57     return CommonComplete(ctx);
58 }
59 
Tss2_Sys_PCR_Extend(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_PCR pcrHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPML_DIGEST_VALUES * digests,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)60 TSS2_RC Tss2_Sys_PCR_Extend(
61     TSS2_SYS_CONTEXT *sysContext,
62     TPMI_DH_PCR pcrHandle,
63     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
64     const TPML_DIGEST_VALUES *digests,
65     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
66 {
67     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
68     TSS2_RC rval;
69 
70     if (!digests)
71         return TSS2_SYS_RC_BAD_REFERENCE;
72 
73     rval = Tss2_Sys_PCR_Extend_Prepare(sysContext, pcrHandle, digests);
74     if (rval)
75         return rval;
76 
77     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
78     if (rval)
79         return rval;
80 
81     return Tss2_Sys_PCR_Extend_Complete(sysContext);
82 }
83