• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NV_Increment_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_AUTH authHandle,TPMI_RH_NV_INDEX nvIndex)15 TSS2_RC Tss2_Sys_NV_Increment_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_RH_NV_AUTH authHandle,
18     TPMI_RH_NV_INDEX nvIndex)
19 {
20     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
21     TSS2_RC rval;
22 
23     if (!ctx)
24         return TSS2_SYS_RC_BAD_REFERENCE;
25 
26     rval = CommonPreparePrologue(ctx, TPM2_CC_NV_Increment);
27     if (rval)
28         return rval;
29 
30     rval = Tss2_MU_UINT32_Marshal(authHandle, ctx->cmdBuffer,
31                                   ctx->maxCmdSize,
32                                   &ctx->nextData);
33     if (rval)
34         return rval;
35 
36     rval = Tss2_MU_UINT32_Marshal(nvIndex, ctx->cmdBuffer,
37                                   ctx->maxCmdSize,
38                                   &ctx->nextData);
39     if (rval)
40         return rval;
41 
42     ctx->decryptAllowed = 0;
43     ctx->encryptAllowed = 0;
44     ctx->authAllowed = 1;
45 
46     return CommonPrepareEpilogue(ctx);
47 }
48 
Tss2_Sys_NV_Increment_Complete(TSS2_SYS_CONTEXT * sysContext)49 TSS2_RC Tss2_Sys_NV_Increment_Complete (
50     TSS2_SYS_CONTEXT *sysContext)
51 {
52     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
53 
54     if (!ctx)
55         return TSS2_SYS_RC_BAD_REFERENCE;
56 
57     return CommonComplete(ctx);
58 }
59 
Tss2_Sys_NV_Increment(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_AUTH authHandle,TPMI_RH_NV_INDEX nvIndex,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)60 TSS2_RC Tss2_Sys_NV_Increment(
61     TSS2_SYS_CONTEXT *sysContext,
62     TPMI_RH_NV_AUTH authHandle,
63     TPMI_RH_NV_INDEX nvIndex,
64     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
65     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
66 {
67     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
68     TSS2_RC rval;
69 
70     rval = Tss2_Sys_NV_Increment_Prepare(sysContext, authHandle, nvIndex);
71     if (rval)
72         return rval;
73 
74     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
75     if (rval)
76         return rval;
77 
78     return Tss2_Sys_NV_Increment_Complete(sysContext);
79 }
80