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_PCR_Read_Prepare(TSS2_SYS_CONTEXT * sysContext,const TPML_PCR_SELECTION * pcrSelectionIn)15 TSS2_RC Tss2_Sys_PCR_Read_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 const TPML_PCR_SELECTION *pcrSelectionIn)
18 {
19 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
20 TSS2_RC rval;
21
22 if (!ctx || !pcrSelectionIn)
23 return TSS2_SYS_RC_BAD_REFERENCE;
24
25 rval = CommonPreparePrologue(ctx, TPM2_CC_PCR_Read);
26 if (rval)
27 return rval;
28
29 rval = Tss2_MU_TPML_PCR_SELECTION_Marshal(pcrSelectionIn,
30 ctx->cmdBuffer,
31 ctx->maxCmdSize,
32 &ctx->nextData);
33 if (rval)
34 return rval;
35
36 ctx->decryptAllowed = 0;
37 ctx->encryptAllowed = 0;
38 ctx->authAllowed = 1;
39
40 return CommonPrepareEpilogue(ctx);
41 }
42
Tss2_Sys_PCR_Read_Complete(TSS2_SYS_CONTEXT * sysContext,UINT32 * pcrUpdateCounter,TPML_PCR_SELECTION * pcrSelectionOut,TPML_DIGEST * pcrValues)43 TSS2_RC Tss2_Sys_PCR_Read_Complete(
44 TSS2_SYS_CONTEXT *sysContext,
45 UINT32 *pcrUpdateCounter,
46 TPML_PCR_SELECTION *pcrSelectionOut,
47 TPML_DIGEST *pcrValues)
48 {
49 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
50 TSS2_RC rval;
51
52 if (!ctx)
53 return TSS2_SYS_RC_BAD_REFERENCE;
54
55 rval = CommonComplete(ctx);
56 if (rval)
57 return rval;
58
59 rval = Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
60 ctx->maxCmdSize,
61 &ctx->nextData,
62 pcrUpdateCounter);
63 if (rval)
64 return rval;
65
66 rval = Tss2_MU_TPML_PCR_SELECTION_Unmarshal(ctx->cmdBuffer,
67 ctx->maxCmdSize,
68 &ctx->nextData,
69 pcrSelectionOut);
70 if (rval)
71 return rval;
72
73 return Tss2_MU_TPML_DIGEST_Unmarshal(ctx->cmdBuffer,
74 ctx->maxCmdSize,
75 &ctx->nextData, pcrValues);
76 }
77
Tss2_Sys_PCR_Read(TSS2_SYS_CONTEXT * sysContext,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPML_PCR_SELECTION * pcrSelectionIn,UINT32 * pcrUpdateCounter,TPML_PCR_SELECTION * pcrSelectionOut,TPML_DIGEST * pcrValues,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)78 TSS2_RC Tss2_Sys_PCR_Read(
79 TSS2_SYS_CONTEXT *sysContext,
80 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
81 const TPML_PCR_SELECTION *pcrSelectionIn,
82 UINT32 *pcrUpdateCounter,
83 TPML_PCR_SELECTION *pcrSelectionOut,
84 TPML_DIGEST *pcrValues,
85 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
86 {
87 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
88 TSS2_RC rval;
89
90 if (!pcrSelectionIn)
91 return TSS2_SYS_RC_BAD_REFERENCE;
92
93 rval = Tss2_Sys_PCR_Read_Prepare(sysContext, pcrSelectionIn);
94 if (rval)
95 return rval;
96
97 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
98 if (rval)
99 return rval;
100
101 return Tss2_Sys_PCR_Read_Complete(sysContext, pcrUpdateCounter,
102 pcrSelectionOut, pcrValues);
103 }
104