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_ObjectChangeAuth_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT objectHandle,TPMI_DH_OBJECT parentHandle,const TPM2B_AUTH * newAuth)15 TSS2_RC Tss2_Sys_ObjectChangeAuth_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_DH_OBJECT objectHandle,
18 TPMI_DH_OBJECT parentHandle,
19 const TPM2B_AUTH *newAuth)
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_ObjectChangeAuth);
28 if (rval)
29 return rval;
30
31 rval = Tss2_MU_UINT32_Marshal(objectHandle, ctx->cmdBuffer,
32 ctx->maxCmdSize,
33 &ctx->nextData);
34 if (rval)
35 return rval;
36
37 rval = Tss2_MU_UINT32_Marshal(parentHandle, ctx->cmdBuffer,
38 ctx->maxCmdSize,
39 &ctx->nextData);
40 if (rval)
41 return rval;
42
43 if (!newAuth) {
44 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
45 ctx->maxCmdSize,
46 &ctx->nextData);
47
48 } else {
49
50 rval = Tss2_MU_TPM2B_AUTH_Marshal(newAuth, ctx->cmdBuffer,
51 ctx->maxCmdSize,
52 &ctx->nextData);
53 }
54
55 if (rval)
56 return rval;
57
58 ctx->decryptAllowed = 1;
59 ctx->encryptAllowed = 1;
60 ctx->authAllowed = 1;
61
62 return CommonPrepareEpilogue(ctx);
63 }
64
Tss2_Sys_ObjectChangeAuth_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_PRIVATE * outPrivate)65 TSS2_RC Tss2_Sys_ObjectChangeAuth_Complete(
66 TSS2_SYS_CONTEXT *sysContext,
67 TPM2B_PRIVATE *outPrivate)
68 {
69 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
70 TSS2_RC rval;
71
72 if (!ctx)
73 return TSS2_SYS_RC_BAD_REFERENCE;
74
75 rval = CommonComplete(ctx);
76 if (rval)
77 return rval;
78
79 return Tss2_MU_TPM2B_PRIVATE_Unmarshal(ctx->cmdBuffer,
80 ctx->maxCmdSize,
81 &ctx->nextData,
82 outPrivate);
83 }
84
Tss2_Sys_ObjectChangeAuth(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT objectHandle,TPMI_DH_OBJECT parentHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_AUTH * newAuth,TPM2B_PRIVATE * outPrivate,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)85 TSS2_RC Tss2_Sys_ObjectChangeAuth(
86 TSS2_SYS_CONTEXT *sysContext,
87 TPMI_DH_OBJECT objectHandle,
88 TPMI_DH_OBJECT parentHandle,
89 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
90 const TPM2B_AUTH *newAuth,
91 TPM2B_PRIVATE *outPrivate,
92 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
93 {
94 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
95 TSS2_RC rval;
96
97 rval = Tss2_Sys_ObjectChangeAuth_Prepare(sysContext, objectHandle, parentHandle, newAuth);
98 if (rval)
99 return rval;
100
101 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
102 if (rval)
103 return rval;
104
105 return Tss2_Sys_ObjectChangeAuth_Complete(sysContext, outPrivate);
106 }
107