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