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_SetAuthPolicy_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_PLATFORM authHandle,const TPM2B_DIGEST * authPolicy,TPMI_ALG_HASH hashAlg,TPMI_DH_PCR pcrNum)15 TSS2_RC Tss2_Sys_PCR_SetAuthPolicy_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_RH_PLATFORM authHandle,
18 const TPM2B_DIGEST *authPolicy,
19 TPMI_ALG_HASH hashAlg,
20 TPMI_DH_PCR pcrNum)
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 if (IsAlgorithmWeak(hashAlg, 0))
29 return TSS2_SYS_RC_BAD_VALUE;
30
31 rval = CommonPreparePrologue(ctx, TPM2_CC_PCR_SetAuthPolicy);
32 if (rval)
33 return rval;
34
35 rval = Tss2_MU_UINT32_Marshal(authHandle, ctx->cmdBuffer,
36 ctx->maxCmdSize,
37 &ctx->nextData);
38 if (rval)
39 return rval;
40
41 if (!authPolicy) {
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(authPolicy, ctx->cmdBuffer,
50 ctx->maxCmdSize,
51 &ctx->nextData);
52 }
53
54 if (rval)
55 return rval;
56
57 rval = Tss2_MU_UINT16_Marshal(hashAlg, ctx->cmdBuffer,
58 ctx->maxCmdSize,
59 &ctx->nextData);
60 if (rval)
61 return rval;
62
63 rval = Tss2_MU_UINT32_Marshal(pcrNum, ctx->cmdBuffer,
64 ctx->maxCmdSize,
65 &ctx->nextData);
66 if (rval)
67 return rval;
68
69 ctx->decryptAllowed = 1;
70 ctx->encryptAllowed = 0;
71 ctx->authAllowed = 1;
72
73 return CommonPrepareEpilogue(ctx);
74 }
75
Tss2_Sys_PCR_SetAuthPolicy_Complete(TSS2_SYS_CONTEXT * sysContext)76 TSS2_RC Tss2_Sys_PCR_SetAuthPolicy_Complete (
77 TSS2_SYS_CONTEXT *sysContext)
78 {
79 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
80
81 if (!ctx)
82 return TSS2_SYS_RC_BAD_REFERENCE;
83
84 return CommonComplete(ctx);
85 }
86
Tss2_Sys_PCR_SetAuthPolicy(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_PLATFORM authHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DIGEST * authPolicy,TPMI_ALG_HASH hashAlg,TPMI_DH_PCR pcrNum,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)87 TSS2_RC Tss2_Sys_PCR_SetAuthPolicy(
88 TSS2_SYS_CONTEXT *sysContext,
89 TPMI_RH_PLATFORM authHandle,
90 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
91 const TPM2B_DIGEST *authPolicy,
92 TPMI_ALG_HASH hashAlg,
93 TPMI_DH_PCR pcrNum,
94 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
95 {
96 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
97 TSS2_RC rval;
98
99 rval = Tss2_Sys_PCR_SetAuthPolicy_Prepare(sysContext, authHandle, authPolicy, hashAlg, pcrNum);
100 if (rval)
101 return rval;
102
103 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
104 if (rval)
105 return rval;
106
107 return Tss2_Sys_PCR_SetAuthPolicy_Complete(sysContext);
108 }
109