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_Vendor_TCG_Test_Prepare(TSS2_SYS_CONTEXT * sysContext,const TPM2B_DATA * inputData)15 TSS2_RC Tss2_Sys_Vendor_TCG_Test_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 const TPM2B_DATA *inputData)
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_Vendor_TCG_Test);
26 if (rval)
27 return rval;
28
29 if (!inputData) {
30 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
31 ctx->maxCmdSize,
32 &ctx->nextData);
33
34 } else {
35
36 rval = Tss2_MU_TPM2B_DATA_Marshal(inputData, ctx->cmdBuffer,
37 ctx->maxCmdSize,
38 &ctx->nextData);
39 }
40
41 if (rval)
42 return rval;
43
44 ctx->decryptAllowed = 1;
45 ctx->encryptAllowed = 1;
46 ctx->authAllowed = 1;
47
48 return CommonPrepareEpilogue(ctx);
49 }
50
Tss2_Sys_Vendor_TCG_Test_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_DATA * outputData)51 TSS2_RC Tss2_Sys_Vendor_TCG_Test_Complete(
52 TSS2_SYS_CONTEXT *sysContext,
53 TPM2B_DATA *outputData)
54 {
55 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
56 TSS2_RC rval;
57
58 if (!ctx)
59 return TSS2_SYS_RC_BAD_REFERENCE;
60
61 rval = CommonComplete(ctx);
62 if (rval)
63 return rval;
64
65 return Tss2_MU_TPM2B_DATA_Unmarshal(ctx->cmdBuffer,
66 ctx->maxCmdSize,
67 &ctx->nextData, outputData);
68 }
69
Tss2_Sys_Vendor_TCG_Test(TSS2_SYS_CONTEXT * sysContext,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DATA * inputData,TPM2B_DATA * outputData,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)70 TSS2_RC Tss2_Sys_Vendor_TCG_Test(
71 TSS2_SYS_CONTEXT *sysContext,
72 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
73 const TPM2B_DATA *inputData,
74 TPM2B_DATA *outputData,
75 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
76 {
77 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
78 TSS2_RC rval;
79
80 rval = Tss2_Sys_Vendor_TCG_Test_Prepare(sysContext, inputData);
81 if (rval)
82 return rval;
83
84 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
85 if (rval)
86 return rval;
87
88 return Tss2_Sys_Vendor_TCG_Test_Complete(sysContext, outputData);
89 }
90