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_ChangeAuth_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_INDEX nvIndex,const TPM2B_AUTH * newAuth)15 TSS2_RC Tss2_Sys_NV_ChangeAuth_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_RH_NV_INDEX nvIndex,
18 const TPM2B_AUTH *newAuth)
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_NV_ChangeAuth);
27 if (rval)
28 return rval;
29
30 rval = Tss2_MU_UINT32_Marshal(nvIndex, ctx->cmdBuffer,
31 ctx->maxCmdSize,
32 &ctx->nextData);
33 if (rval)
34 return rval;
35
36 if (!newAuth) {
37 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
38 ctx->maxCmdSize,
39 &ctx->nextData);
40
41 } else {
42
43 rval = Tss2_MU_TPM2B_AUTH_Marshal(newAuth, 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_NV_ChangeAuth_Complete(TSS2_SYS_CONTEXT * sysContext)58 TSS2_RC Tss2_Sys_NV_ChangeAuth_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_NV_ChangeAuth(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_INDEX nvIndex,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_AUTH * newAuth,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)69 TSS2_RC Tss2_Sys_NV_ChangeAuth(
70 TSS2_SYS_CONTEXT *sysContext,
71 TPMI_RH_NV_INDEX nvIndex,
72 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
73 const TPM2B_AUTH *newAuth,
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_NV_ChangeAuth_Prepare(sysContext, nvIndex, newAuth);
80 if (rval)
81 return rval;
82
83 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
84 if (rval)
85 return rval;
86
87 return Tss2_Sys_NV_ChangeAuth_Complete(sysContext);
88 }
89