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_PolicyOR_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,const TPML_DIGEST * pHashList)15 TSS2_RC Tss2_Sys_PolicyOR_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_SH_POLICY policySession,
18     const TPML_DIGEST *pHashList)
19 {
20     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
21     TSS2_RC rval;
22 
23     if (!ctx || !pHashList)
24         return TSS2_SYS_RC_BAD_REFERENCE;
25 
26     rval = CommonPreparePrologue(ctx, TPM2_CC_PolicyOR);
27     if (rval)
28         return rval;
29 
30     rval = Tss2_MU_UINT32_Marshal(policySession, ctx->cmdBuffer,
31                                   ctx->maxCmdSize,
32                                   &ctx->nextData);
33     if (rval)
34         return rval;
35 
36     rval = Tss2_MU_TPML_DIGEST_Marshal(pHashList, 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_PolicyOR_Complete(TSS2_SYS_CONTEXT * sysContext)49 TSS2_RC Tss2_Sys_PolicyOR_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_PolicyOR(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPML_DIGEST * pHashList,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)60 TSS2_RC Tss2_Sys_PolicyOR(
61     TSS2_SYS_CONTEXT *sysContext,
62     TPMI_SH_POLICY policySession,
63     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
64     const TPML_DIGEST *pHashList,
65     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
66 {
67     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
68     TSS2_RC rval;
69 
70     if (!pHashList)
71         return TSS2_SYS_RC_BAD_REFERENCE;
72 
73     rval = Tss2_Sys_PolicyOR_Prepare(sysContext, policySession, pHashList);
74     if (rval)
75         return rval;
76 
77     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
78     if (rval)
79         return rval;
80 
81     return Tss2_Sys_PolicyOR_Complete(sysContext);
82 }
83