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_Allocate_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_PLATFORM authHandle,const TPML_PCR_SELECTION * pcrAllocation)15 TSS2_RC Tss2_Sys_PCR_Allocate_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_RH_PLATFORM authHandle,
18     const TPML_PCR_SELECTION *pcrAllocation)
19 {
20     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
21     TSS2_RC rval;
22 
23     if (!ctx || !pcrAllocation)
24         return TSS2_SYS_RC_BAD_REFERENCE;
25 
26     rval = ValidateTPML_PCR_SELECTION(pcrAllocation);
27     if (rval)
28         return rval;
29 
30     rval = CommonPreparePrologue(ctx, TPM2_CC_PCR_Allocate);
31     if (rval)
32         return rval;
33 
34     rval = Tss2_MU_UINT32_Marshal(authHandle, ctx->cmdBuffer,
35                                   ctx->maxCmdSize,
36                                   &ctx->nextData);
37     if (rval)
38         return rval;
39 
40     rval = Tss2_MU_TPML_PCR_SELECTION_Marshal(pcrAllocation,
41                                               ctx->cmdBuffer,
42                                               ctx->maxCmdSize,
43                                               &ctx->nextData);
44     if (rval)
45         return rval;
46 
47     ctx->decryptAllowed = 0;
48     ctx->encryptAllowed = 0;
49     ctx->authAllowed = 1;
50 
51     return CommonPrepareEpilogue(ctx);
52 }
53 
Tss2_Sys_PCR_Allocate_Complete(TSS2_SYS_CONTEXT * sysContext,TPMI_YES_NO * allocationSuccess,UINT32 * maxPCR,UINT32 * sizeNeeded,UINT32 * sizeAvailable)54 TSS2_RC Tss2_Sys_PCR_Allocate_Complete(
55     TSS2_SYS_CONTEXT *sysContext,
56     TPMI_YES_NO *allocationSuccess,
57     UINT32 *maxPCR,
58     UINT32 *sizeNeeded,
59     UINT32 *sizeAvailable)
60 {
61     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
62     TSS2_RC rval;
63 
64     if (!ctx)
65         return TSS2_SYS_RC_BAD_REFERENCE;
66 
67     rval = CommonComplete(ctx);
68     if (rval)
69         return rval;
70 
71     rval = Tss2_MU_UINT8_Unmarshal(ctx->cmdBuffer,
72                                    ctx->maxCmdSize,
73                                    &ctx->nextData,
74                                    allocationSuccess);
75     if (rval)
76         return rval;
77 
78     rval = Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
79                                     ctx->maxCmdSize,
80                                     &ctx->nextData,
81                                     maxPCR);
82     if (rval)
83         return rval;
84 
85     rval = Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
86                                     ctx->maxCmdSize,
87                                     &ctx->nextData,
88                                     sizeNeeded);
89     if (rval)
90         return rval;
91 
92     return Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
93                                     ctx->maxCmdSize,
94                                     &ctx->nextData,
95                                     sizeAvailable);
96 }
97 
Tss2_Sys_PCR_Allocate(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_PLATFORM authHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPML_PCR_SELECTION * pcrAllocation,TPMI_YES_NO * allocationSuccess,UINT32 * maxPCR,UINT32 * sizeNeeded,UINT32 * sizeAvailable,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)98 TSS2_RC Tss2_Sys_PCR_Allocate(
99     TSS2_SYS_CONTEXT *sysContext,
100     TPMI_RH_PLATFORM authHandle,
101     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
102     const TPML_PCR_SELECTION *pcrAllocation,
103     TPMI_YES_NO *allocationSuccess,
104     UINT32 *maxPCR,
105     UINT32 *sizeNeeded,
106     UINT32 *sizeAvailable,
107     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
108 {
109     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
110     TSS2_RC rval;
111 
112     if (!pcrAllocation)
113         return TSS2_SYS_RC_BAD_REFERENCE;
114 
115     rval = Tss2_Sys_PCR_Allocate_Prepare(sysContext, authHandle, pcrAllocation);
116     if (rval)
117         return rval;
118 
119     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
120     if (rval)
121         return rval;
122 
123     return Tss2_Sys_PCR_Allocate_Complete(sysContext, allocationSuccess, maxPCR,
124                                           sizeNeeded, sizeAvailable);
125 }
126