• 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_PolicyAuthorizeNV_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_AUTH authHandle,TPMI_RH_NV_INDEX nvIndex,TPMI_SH_POLICY policySession)15 TSS2_RC Tss2_Sys_PolicyAuthorizeNV_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_RH_NV_AUTH authHandle,
18     TPMI_RH_NV_INDEX nvIndex,
19     TPMI_SH_POLICY policySession)
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     rval = CommonPreparePrologue(ctx, TPM2_CC_PolicyAuthorizeNV);
28     if (rval)
29         return rval;
30 
31     rval = Tss2_MU_TPM2_HANDLE_Marshal(authHandle, ctx->cmdBuffer,
32                                        ctx->maxCmdSize,
33                                        &ctx->nextData);
34     if (rval)
35         return rval;
36 
37     rval = Tss2_MU_TPM2_HANDLE_Marshal(nvIndex, ctx->cmdBuffer,
38                                        ctx->maxCmdSize,
39                                        &ctx->nextData);
40     if (rval)
41         return rval;
42 
43     rval = Tss2_MU_TPM2_HANDLE_Marshal(policySession, ctx->cmdBuffer,
44                                        ctx->maxCmdSize,
45                                        &ctx->nextData);
46     if (rval)
47         return rval;
48 
49     ctx->decryptAllowed = 0;
50     ctx->encryptAllowed = 0;
51     ctx->authAllowed = 1;
52 
53     return CommonPrepareEpilogue(ctx);
54 }
55 
Tss2_Sys_PolicyAuthorizeNV_Complete(TSS2_SYS_CONTEXT * sysContext)56 TSS2_RC Tss2_Sys_PolicyAuthorizeNV_Complete(
57     TSS2_SYS_CONTEXT *sysContext)
58 {
59     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
60 
61     if (!ctx)
62         return TSS2_SYS_RC_BAD_REFERENCE;
63 
64     return CommonComplete(ctx);
65 }
66 
Tss2_Sys_PolicyAuthorizeNV(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_AUTH authHandle,TPMI_RH_NV_INDEX nvIndex,TPMI_SH_POLICY policySession,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)67 TSS2_RC Tss2_Sys_PolicyAuthorizeNV(
68     TSS2_SYS_CONTEXT *sysContext,
69     TPMI_RH_NV_AUTH authHandle,
70     TPMI_RH_NV_INDEX nvIndex,
71     TPMI_SH_POLICY policySession,
72     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
73     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
74 {
75     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
76     TSS2_RC rval;
77 
78     rval = Tss2_Sys_PolicyAuthorizeNV_Prepare(sysContext, authHandle,
79                                               nvIndex, policySession);
80     if (rval)
81         return rval;
82 
83     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
84     if (rval)
85         return rval;
86 
87     return Tss2_Sys_PolicyAuthorizeNV_Complete(sysContext);
88 }
89