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_PolicyPCR_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,const TPM2B_DIGEST * pcrDigest,const TPML_PCR_SELECTION * pcrs)15 TSS2_RC Tss2_Sys_PolicyPCR_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_SH_POLICY policySession,
18 const TPM2B_DIGEST *pcrDigest,
19 const TPML_PCR_SELECTION *pcrs)
20 {
21 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
22 TSS2_RC rval;
23
24 if (!ctx || !pcrs)
25 return TSS2_SYS_RC_BAD_REFERENCE;
26
27 rval = ValidateTPML_PCR_SELECTION(pcrs);
28 if (rval)
29 return rval;
30
31 rval = CommonPreparePrologue(ctx, TPM2_CC_PolicyPCR);
32 if (rval)
33 return rval;
34
35 rval = Tss2_MU_UINT32_Marshal(policySession, ctx->cmdBuffer,
36 ctx->maxCmdSize,
37 &ctx->nextData);
38 if (rval)
39 return rval;
40
41 if (!pcrDigest) {
42 ctx->decryptNull = 1;
43
44 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
45 ctx->maxCmdSize,
46 &ctx->nextData);
47 } else {
48
49 rval = Tss2_MU_TPM2B_DIGEST_Marshal(pcrDigest, ctx->cmdBuffer,
50 ctx->maxCmdSize,
51 &ctx->nextData);
52 }
53
54 if (rval)
55 return rval;
56
57 rval = Tss2_MU_TPML_PCR_SELECTION_Marshal(pcrs, ctx->cmdBuffer,
58 ctx->maxCmdSize,
59 &ctx->nextData);
60 if (rval)
61 return rval;
62
63 ctx->decryptAllowed = 1;
64 ctx->encryptAllowed = 0;
65 ctx->authAllowed = 1;
66
67 return CommonPrepareEpilogue(ctx);
68 }
69
Tss2_Sys_PolicyPCR_Complete(TSS2_SYS_CONTEXT * sysContext)70 TSS2_RC Tss2_Sys_PolicyPCR_Complete (
71 TSS2_SYS_CONTEXT *sysContext)
72 {
73 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
74
75 if (!ctx)
76 return TSS2_SYS_RC_BAD_REFERENCE;
77
78 return CommonComplete(ctx);
79 }
80
Tss2_Sys_PolicyPCR(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DIGEST * pcrDigest,const TPML_PCR_SELECTION * pcrs,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)81 TSS2_RC Tss2_Sys_PolicyPCR(
82 TSS2_SYS_CONTEXT *sysContext,
83 TPMI_SH_POLICY policySession,
84 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
85 const TPM2B_DIGEST *pcrDigest,
86 const TPML_PCR_SELECTION *pcrs,
87 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
88 {
89 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
90 TSS2_RC rval;
91
92 if (!pcrs)
93 return TSS2_SYS_RC_BAD_REFERENCE;
94
95 rval = Tss2_Sys_PolicyPCR_Prepare(sysContext, policySession, pcrDigest, pcrs);
96 if (rval)
97 return rval;
98
99 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
100 if (rval)
101 return rval;
102
103 return Tss2_Sys_PolicyPCR_Complete(sysContext);
104 }
105