• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FieldUpgradeData_Prepare(TSS2_SYS_CONTEXT * sysContext,TPM2B_MAX_BUFFER const * fuData)15 TSS2_RC Tss2_Sys_FieldUpgradeData_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPM2B_MAX_BUFFER const *fuData)
18 {
19     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
20     TSS2_RC rval;
21 
22     if (!ctx)
23         return TSS2_SYS_RC_BAD_REFERENCE;
24 
25     rval = CommonPreparePrologue(ctx, TPM2_CC_FieldUpgradeData);
26     if (rval)
27         return rval;
28 
29     if (!fuData) {
30         rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
31                                       ctx->maxCmdSize,
32                                       &ctx->nextData);
33 
34     } else {
35 
36         rval = Tss2_MU_TPM2B_MAX_BUFFER_Marshal(fuData,
37                                                 ctx->cmdBuffer,
38                                                 ctx->maxCmdSize,
39                                                 &ctx->nextData);
40     }
41 
42     if (rval)
43         return rval;
44 
45     ctx->decryptAllowed = 1;
46     ctx->encryptAllowed = 0;
47     ctx->authAllowed = 1;
48 
49     return CommonPrepareEpilogue(ctx);
50 }
51 
Tss2_Sys_FieldUpgradeData_Complete(TSS2_SYS_CONTEXT * sysContext,TPMT_HA * nextDigest,TPMT_HA * firstDigest)52 TSS2_RC Tss2_Sys_FieldUpgradeData_Complete(
53     TSS2_SYS_CONTEXT *sysContext,
54     TPMT_HA *nextDigest,
55     TPMT_HA *firstDigest)
56 {
57     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
58     TSS2_RC rval;
59 
60     if (!ctx)
61         return TSS2_SYS_RC_BAD_REFERENCE;
62 
63     rval = CommonComplete(ctx);
64     if (rval)
65         return rval;
66 
67     rval = Tss2_MU_TPMT_HA_Unmarshal(ctx->cmdBuffer,
68                                      ctx->maxCmdSize,
69                                      &ctx->nextData,
70                                      nextDigest);
71     if (rval)
72         return rval;
73 
74     return Tss2_MU_TPMT_HA_Unmarshal(ctx->cmdBuffer,
75                                      ctx->maxCmdSize,
76                                      &ctx->nextData,
77                                      firstDigest);
78 }
79 
Tss2_Sys_FieldUpgradeData(TSS2_SYS_CONTEXT * sysContext,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM2B_MAX_BUFFER const * fuData,TPMT_HA * nextDigest,TPMT_HA * firstDigest,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)80 TSS2_RC Tss2_Sys_FieldUpgradeData(
81     TSS2_SYS_CONTEXT *sysContext,
82     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
83     TPM2B_MAX_BUFFER const *fuData,
84     TPMT_HA *nextDigest,
85     TPMT_HA *firstDigest,
86     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
87 {
88     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
89     TSS2_RC rval;
90 
91     rval = Tss2_Sys_FieldUpgradeData_Prepare(sysContext, fuData);
92     if (rval)
93         return rval;
94 
95     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
96     if (rval)
97         return rval;
98 
99     return Tss2_Sys_FieldUpgradeData_Complete(sysContext, nextDigest,
100                                               firstDigest);
101 }
102