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_FieldUpgradeStart_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_PLATFORM authorization,TPMI_DH_OBJECT keyHandle,TPM2B_DIGEST const * fuDigest,TPMT_SIGNATURE const * manifestSignature)15 TSS2_RC Tss2_Sys_FieldUpgradeStart_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_RH_PLATFORM authorization,
18 TPMI_DH_OBJECT keyHandle,
19 TPM2B_DIGEST const *fuDigest,
20 TPMT_SIGNATURE const *manifestSignature)
21 {
22 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
23 TSS2_RC rval;
24
25 if (!ctx || !manifestSignature)
26 return TSS2_SYS_RC_BAD_REFERENCE;
27
28 rval = CommonPreparePrologue(ctx, TPM2_CC_FieldUpgradeStart);
29 if (rval)
30 return rval;
31 rval = Tss2_MU_UINT32_Marshal(authorization, ctx->cmdBuffer,
32 ctx->maxCmdSize,
33 &ctx->nextData);
34 if (rval)
35 return rval;
36
37 rval = Tss2_MU_UINT32_Marshal(keyHandle, ctx->cmdBuffer,
38 ctx->maxCmdSize,
39 &ctx->nextData);
40 if (rval)
41 return rval;
42
43 if (!fuDigest) {
44 ctx->decryptNull = 1;
45
46 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
47 ctx->maxCmdSize,
48 &ctx->nextData);
49 } else {
50
51 rval = Tss2_MU_TPM2B_DIGEST_Marshal(fuDigest, ctx->cmdBuffer,
52 ctx->maxCmdSize,
53 &ctx->nextData);
54 }
55
56 if (rval)
57 return rval;
58
59 rval = Tss2_MU_TPMT_SIGNATURE_Marshal(manifestSignature,
60 ctx->cmdBuffer,
61 ctx->maxCmdSize,
62 &ctx->nextData);
63 if (rval)
64 return rval;
65
66 ctx->decryptAllowed = 1;
67 ctx->encryptAllowed = 0;
68 ctx->authAllowed = 1;
69
70 return CommonPrepareEpilogue(ctx);
71 }
72
Tss2_Sys_FieldUpgradeStart_Complete(TSS2_SYS_CONTEXT * sysContext)73 TSS2_RC Tss2_Sys_FieldUpgradeStart_Complete (
74 TSS2_SYS_CONTEXT *sysContext)
75 {
76 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
77
78 if (!ctx)
79 return TSS2_SYS_RC_BAD_REFERENCE;
80
81 return CommonComplete(ctx);
82 }
83
Tss2_Sys_FieldUpgradeStart(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_PLATFORM authorization,TPMI_DH_OBJECT keyHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM2B_DIGEST const * fuDigest,TPMT_SIGNATURE const * manifestSignature,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)84 TSS2_RC Tss2_Sys_FieldUpgradeStart(
85 TSS2_SYS_CONTEXT *sysContext,
86 TPMI_RH_PLATFORM authorization,
87 TPMI_DH_OBJECT keyHandle,
88 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
89 TPM2B_DIGEST const *fuDigest,
90 TPMT_SIGNATURE const *manifestSignature,
91 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
92 {
93 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
94 TSS2_RC rval;
95
96 if (!manifestSignature)
97 return TSS2_SYS_RC_BAD_REFERENCE;
98
99 rval = Tss2_Sys_FieldUpgradeStart_Prepare(sysContext, authorization,
100 keyHandle, fuDigest,
101 manifestSignature);
102 if (rval)
103 return rval;
104
105 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
106 if (rval)
107 return rval;
108
109 return Tss2_Sys_FieldUpgradeStart_Complete(sysContext);
110 }
111