• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3  * Copyright (c) 2018, 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_PolicyTemplate_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,const TPM2B_DIGEST * templateHash)15 TSS2_RC Tss2_Sys_PolicyTemplate_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_SH_POLICY policySession,
18     const TPM2B_DIGEST *templateHash)
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_PolicyTemplate);
27     if (rval)
28         return rval;
29 
30     rval = Tss2_MU_TPM2_HANDLE_Marshal(policySession, ctx->cmdBuffer,
31                                        ctx->maxCmdSize,
32                                        &ctx->nextData);
33     if (rval)
34         return rval;
35 
36     if (!templateHash) {
37         rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
38                                       ctx->maxCmdSize,
39                                       &ctx->nextData);
40 
41     } else {
42 
43         rval = Tss2_MU_TPM2B_DIGEST_Marshal(templateHash, 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_PolicyTemplate_Complete(TSS2_SYS_CONTEXT * sysContext)58 TSS2_RC Tss2_Sys_PolicyTemplate_Complete(
59     TSS2_SYS_CONTEXT *sysContext)
60 {
61     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
62 
63     if (!ctx)
64         return TSS2_SYS_RC_BAD_REFERENCE;
65 
66     return CommonComplete(ctx);
67 }
68 
Tss2_Sys_PolicyTemplate(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DIGEST * templateHash,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)69 TSS2_RC Tss2_Sys_PolicyTemplate(
70     TSS2_SYS_CONTEXT *sysContext,
71     TPMI_SH_POLICY policySession,
72     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
73     const TPM2B_DIGEST *templateHash,
74     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
75 {
76     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
77     TSS2_RC rval;
78 
79     rval = Tss2_Sys_PolicyTemplate_Prepare(sysContext, policySession,
80                                            templateHash);
81     if (rval)
82         return rval;
83 
84     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
85     if (rval)
86         return rval;
87 
88     return Tss2_Sys_PolicyTemplate_Complete(sysContext);
89 }
90