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_SetPrimaryPolicy_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_HIERARCHY_AUTH authHandle,const TPM2B_DIGEST * authPolicy,TPMI_ALG_HASH hashAlg)15 TSS2_RC Tss2_Sys_SetPrimaryPolicy_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_RH_HIERARCHY_AUTH authHandle,
18 const TPM2B_DIGEST *authPolicy,
19 TPMI_ALG_HASH hashAlg)
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 if (IsAlgorithmWeak(hashAlg, 0))
28 return TSS2_SYS_RC_BAD_VALUE;
29
30 rval = CommonPreparePrologue(ctx, TPM2_CC_SetPrimaryPolicy);
31 if (rval)
32 return rval;
33
34 rval = Tss2_MU_UINT32_Marshal(authHandle, ctx->cmdBuffer,
35 ctx->maxCmdSize,
36 &ctx->nextData);
37 if (rval)
38 return rval;
39
40 if (!authPolicy) {
41 ctx->decryptNull = 1;
42
43 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
44 ctx->maxCmdSize,
45 &ctx->nextData);
46 } else {
47
48 rval = Tss2_MU_TPM2B_DIGEST_Marshal(authPolicy, ctx->cmdBuffer,
49 ctx->maxCmdSize,
50 &ctx->nextData);
51 }
52
53 if (rval)
54 return rval;
55
56 rval = Tss2_MU_UINT16_Marshal(hashAlg, ctx->cmdBuffer,
57 ctx->maxCmdSize,
58 &ctx->nextData);
59 if (rval)
60 return rval;
61
62 ctx->decryptAllowed = 1;
63 ctx->encryptAllowed = 0;
64 ctx->authAllowed = 1;
65
66 return CommonPrepareEpilogue(ctx);
67 }
68
Tss2_Sys_SetPrimaryPolicy_Complete(TSS2_SYS_CONTEXT * sysContext)69 TSS2_RC Tss2_Sys_SetPrimaryPolicy_Complete (
70 TSS2_SYS_CONTEXT *sysContext)
71 {
72 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
73
74 if (!ctx)
75 return TSS2_SYS_RC_BAD_REFERENCE;
76
77 return CommonComplete(ctx);
78 }
79
Tss2_Sys_SetPrimaryPolicy(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_HIERARCHY_AUTH authHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DIGEST * authPolicy,TPMI_ALG_HASH hashAlg,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)80 TSS2_RC Tss2_Sys_SetPrimaryPolicy(
81 TSS2_SYS_CONTEXT *sysContext,
82 TPMI_RH_HIERARCHY_AUTH authHandle,
83 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
84 const TPM2B_DIGEST *authPolicy,
85 TPMI_ALG_HASH hashAlg,
86 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
87 {
88 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
89 TSS2_RC rval;
90
91 rval = Tss2_Sys_SetPrimaryPolicy_Prepare(sysContext, authHandle, authPolicy, hashAlg);
92 if (rval)
93 return rval;
94
95 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
96 if (rval)
97 return rval;
98
99 return Tss2_Sys_SetPrimaryPolicy_Complete(sysContext);
100 }
101