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_GetSessionAuditDigest_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_ENDORSEMENT privacyAdminHandle,TPMI_DH_OBJECT signHandle,TPMI_SH_HMAC sessionHandle,const TPM2B_DATA * qualifyingData,const TPMT_SIG_SCHEME * inScheme)15 TSS2_RC Tss2_Sys_GetSessionAuditDigest_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_RH_ENDORSEMENT privacyAdminHandle,
18 TPMI_DH_OBJECT signHandle,
19 TPMI_SH_HMAC sessionHandle,
20 const TPM2B_DATA *qualifyingData,
21 const TPMT_SIG_SCHEME *inScheme)
22 {
23 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
24 TSS2_RC rval;
25
26 if (!ctx || !inScheme)
27 return TSS2_SYS_RC_BAD_REFERENCE;
28
29 rval = CommonPreparePrologue(ctx, TPM2_CC_GetSessionAuditDigest);
30 if (rval)
31 return rval;
32
33 rval = Tss2_MU_UINT32_Marshal(privacyAdminHandle, ctx->cmdBuffer,
34 ctx->maxCmdSize,
35 &ctx->nextData);
36 if (rval)
37 return rval;
38
39 rval = Tss2_MU_UINT32_Marshal(signHandle, ctx->cmdBuffer,
40 ctx->maxCmdSize,
41 &ctx->nextData);
42 if (rval)
43 return rval;
44
45 rval = Tss2_MU_UINT32_Marshal(sessionHandle, ctx->cmdBuffer,
46 ctx->maxCmdSize,
47 &ctx->nextData);
48 if (rval)
49 return rval;
50
51 if (!qualifyingData) {
52 ctx->decryptNull = 1;
53
54 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
55 ctx->maxCmdSize,
56 &ctx->nextData);
57 } else {
58
59 rval = Tss2_MU_TPM2B_DATA_Marshal(qualifyingData, ctx->cmdBuffer,
60 ctx->maxCmdSize,
61 &ctx->nextData);
62 }
63
64 if (rval)
65 return rval;
66
67 rval = Tss2_MU_TPMT_SIG_SCHEME_Marshal(inScheme, ctx->cmdBuffer,
68 ctx->maxCmdSize,
69 &ctx->nextData);
70 if (rval)
71 return rval;
72
73 ctx->decryptAllowed = 1;
74 ctx->encryptAllowed = 1;
75 ctx->authAllowed = 1;
76
77 return CommonPrepareEpilogue(ctx);
78 }
79
Tss2_Sys_GetSessionAuditDigest_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_ATTEST * auditInfo,TPMT_SIGNATURE * signature)80 TSS2_RC Tss2_Sys_GetSessionAuditDigest_Complete(
81 TSS2_SYS_CONTEXT *sysContext,
82 TPM2B_ATTEST *auditInfo,
83 TPMT_SIGNATURE *signature)
84 {
85 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
86 TSS2_RC rval;
87
88 if (!ctx)
89 return TSS2_SYS_RC_BAD_REFERENCE;
90
91 rval = CommonComplete(ctx);
92 if (rval)
93 return rval;
94
95 rval = Tss2_MU_TPM2B_ATTEST_Unmarshal(ctx->cmdBuffer,
96 ctx->maxCmdSize,
97 &ctx->nextData, auditInfo);
98 if (rval)
99 return rval;
100
101 return Tss2_MU_TPMT_SIGNATURE_Unmarshal(ctx->cmdBuffer,
102 ctx->maxCmdSize,
103 &ctx->nextData, signature);
104 }
105
Tss2_Sys_GetSessionAuditDigest(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_ENDORSEMENT privacyAdminHandle,TPMI_DH_OBJECT signHandle,TPMI_SH_HMAC sessionHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DATA * qualifyingData,const TPMT_SIG_SCHEME * inScheme,TPM2B_ATTEST * auditInfo,TPMT_SIGNATURE * signature,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)106 TSS2_RC Tss2_Sys_GetSessionAuditDigest(
107 TSS2_SYS_CONTEXT *sysContext,
108 TPMI_RH_ENDORSEMENT privacyAdminHandle,
109 TPMI_DH_OBJECT signHandle,
110 TPMI_SH_HMAC sessionHandle,
111 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
112 const TPM2B_DATA *qualifyingData,
113 const TPMT_SIG_SCHEME *inScheme,
114 TPM2B_ATTEST *auditInfo,
115 TPMT_SIGNATURE *signature,
116 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
117 {
118 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
119 TSS2_RC rval;
120
121 if (!inScheme)
122 return TSS2_SYS_RC_BAD_REFERENCE;
123
124 rval = Tss2_Sys_GetSessionAuditDigest_Prepare(sysContext, privacyAdminHandle,
125 signHandle, sessionHandle,
126 qualifyingData, inScheme);
127 if (rval)
128 return rval;
129
130 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
131 if (rval)
132 return rval;
133
134 return Tss2_Sys_GetSessionAuditDigest_Complete(sysContext, auditInfo,
135 signature);
136 }
137