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