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_ContextLoad_Prepare(TSS2_SYS_CONTEXT * sysContext,const TPMS_CONTEXT * context)15 TSS2_RC Tss2_Sys_ContextLoad_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 const TPMS_CONTEXT *context)
18 {
19 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
20 TSS2_RC rval;
21
22 if (!ctx || !context)
23 return TSS2_SYS_RC_BAD_REFERENCE;
24
25 rval = CommonPreparePrologue(ctx, TPM2_CC_ContextLoad);
26 if (rval)
27 return rval;
28
29 rval = Tss2_MU_TPMS_CONTEXT_Marshal(context, ctx->cmdBuffer,
30 ctx->maxCmdSize,
31 &ctx->nextData);
32 if (rval)
33 return rval;
34
35 ctx->decryptAllowed = 0;
36 ctx->encryptAllowed = 0;
37 ctx->authAllowed = 0;
38
39 return CommonPrepareEpilogue(ctx);
40 }
41
Tss2_Sys_ContextLoad_Complete(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_CONTEXT * loadedHandle)42 TSS2_RC Tss2_Sys_ContextLoad_Complete(
43 TSS2_SYS_CONTEXT *sysContext,
44 TPMI_DH_CONTEXT *loadedHandle)
45 {
46 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
47 TSS2_RC rval;
48
49 if (!ctx)
50 return TSS2_SYS_RC_BAD_REFERENCE;
51
52 rval = Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
53 ctx->maxCmdSize,
54 &ctx->nextData,
55 loadedHandle);
56 if (rval)
57 return rval;
58
59 return CommonComplete(ctx);
60 }
61
Tss2_Sys_ContextLoad(TSS2_SYS_CONTEXT * sysContext,const TPMS_CONTEXT * context,TPMI_DH_CONTEXT * loadedHandle)62 TSS2_RC Tss2_Sys_ContextLoad(
63 TSS2_SYS_CONTEXT *sysContext,
64 const TPMS_CONTEXT *context,
65 TPMI_DH_CONTEXT *loadedHandle)
66 {
67 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
68 TSS2_RC rval;
69
70 if (!context)
71 return TSS2_SYS_RC_BAD_REFERENCE;
72
73 rval = Tss2_Sys_ContextLoad_Prepare(sysContext, context);
74 if (rval)
75 return rval;
76
77 rval = CommonOneCall(ctx, 0, 0);
78 if (rval)
79 return rval;
80
81 return Tss2_Sys_ContextLoad_Complete(sysContext, loadedHandle);
82 }
83