• 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_HashSequenceStart_Prepare(TSS2_SYS_CONTEXT * sysContext,const TPM2B_AUTH * auth,TPMI_ALG_HASH hashAlg)15 TSS2_RC Tss2_Sys_HashSequenceStart_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     const TPM2B_AUTH *auth,
18     TPMI_ALG_HASH hashAlg)
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     if (IsAlgorithmWeak(hashAlg, 0))
27         return TSS2_SYS_RC_BAD_VALUE;
28 
29     rval = CommonPreparePrologue(ctx, TPM2_CC_HashSequenceStart);
30     if (rval)
31         return rval;
32 
33     if (!auth) {
34         ctx->decryptNull = 1;
35 
36         rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
37                                       ctx->maxCmdSize,
38                                       &ctx->nextData);
39     } else {
40 
41         rval = Tss2_MU_TPM2B_AUTH_Marshal(auth, ctx->cmdBuffer,
42                                           ctx->maxCmdSize,
43                                           &ctx->nextData);
44     }
45 
46     if (rval)
47         return rval;
48 
49     rval = Tss2_MU_UINT16_Marshal(hashAlg, ctx->cmdBuffer,
50                                   ctx->maxCmdSize,
51                                   &ctx->nextData);
52     if (rval)
53         return rval;
54 
55     ctx->decryptAllowed = 1;
56     ctx->encryptAllowed = 0;
57     ctx->authAllowed = 1;
58 
59     return CommonPrepareEpilogue(ctx);
60 }
61 
Tss2_Sys_HashSequenceStart_Complete(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT * sequenceHandle)62 TSS2_RC Tss2_Sys_HashSequenceStart_Complete(
63     TSS2_SYS_CONTEXT *sysContext,
64     TPMI_DH_OBJECT *sequenceHandle)
65 {
66     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
67     TSS2_RC rval;
68 
69     if (!ctx)
70         return TSS2_SYS_RC_BAD_REFERENCE;
71 
72     rval = Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
73                                     ctx->maxCmdSize,
74                                     &ctx->nextData,
75                                     sequenceHandle);
76     if (rval)
77         return rval;
78 
79     return CommonComplete(ctx);
80 }
81 
Tss2_Sys_HashSequenceStart(TSS2_SYS_CONTEXT * sysContext,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_AUTH * auth,TPMI_ALG_HASH hashAlg,TPMI_DH_OBJECT * sequenceHandle,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)82 TSS2_RC Tss2_Sys_HashSequenceStart(
83     TSS2_SYS_CONTEXT *sysContext,
84     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
85     const TPM2B_AUTH *auth,
86     TPMI_ALG_HASH hashAlg,
87     TPMI_DH_OBJECT *sequenceHandle,
88     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
89 {
90     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
91     TSS2_RC rval;
92 
93     rval = Tss2_Sys_HashSequenceStart_Prepare(sysContext, auth, hashAlg);
94     if (rval)
95         return rval;
96 
97     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
98     if (rval)
99         return rval;
100 
101     return Tss2_Sys_HashSequenceStart_Complete(sysContext, sequenceHandle);
102 }
103