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_DictionaryAttackParameters_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_LOCKOUT lockHandle,UINT32 newMaxTries,UINT32 newRecoveryTime,UINT32 lockoutRecovery)15 TSS2_RC Tss2_Sys_DictionaryAttackParameters_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_RH_LOCKOUT lockHandle,
18 UINT32 newMaxTries,
19 UINT32 newRecoveryTime,
20 UINT32 lockoutRecovery)
21 {
22 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
23 TSS2_RC rval;
24
25 if (!ctx)
26 return TSS2_SYS_RC_BAD_REFERENCE;
27
28 rval = CommonPreparePrologue(ctx, TPM2_CC_DictionaryAttackParameters);
29 if (rval)
30 return rval;
31
32 rval = Tss2_MU_UINT32_Marshal(lockHandle, ctx->cmdBuffer,
33 ctx->maxCmdSize,
34 &ctx->nextData);
35 if (rval)
36 return rval;
37
38
39 rval = Tss2_MU_UINT32_Marshal(newMaxTries, ctx->cmdBuffer,
40 ctx->maxCmdSize,
41 &ctx->nextData);
42 if (rval)
43 return rval;
44 rval = Tss2_MU_UINT32_Marshal(newRecoveryTime, ctx->cmdBuffer,
45 ctx->maxCmdSize,
46 &ctx->nextData);
47 if (rval)
48 return rval;
49 rval = Tss2_MU_UINT32_Marshal(lockoutRecovery, ctx->cmdBuffer,
50 ctx->maxCmdSize,
51 &ctx->nextData);
52 if (rval)
53 return rval;
54
55 ctx->decryptAllowed = 0;
56 ctx->encryptAllowed = 0;
57 ctx->authAllowed = 1;
58
59 return CommonPrepareEpilogue(ctx);
60 }
61
Tss2_Sys_DictionaryAttackParameters_Complete(TSS2_SYS_CONTEXT * sysContext)62 TSS2_RC Tss2_Sys_DictionaryAttackParameters_Complete (
63 TSS2_SYS_CONTEXT *sysContext)
64 {
65 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
66
67 if (!ctx)
68 return TSS2_SYS_RC_BAD_REFERENCE;
69
70 return CommonComplete(ctx);
71 }
72
Tss2_Sys_DictionaryAttackParameters(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_LOCKOUT lockHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,UINT32 newMaxTries,UINT32 newRecoveryTime,UINT32 lockoutRecovery,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)73 TSS2_RC Tss2_Sys_DictionaryAttackParameters(
74 TSS2_SYS_CONTEXT *sysContext,
75 TPMI_RH_LOCKOUT lockHandle,
76 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
77 UINT32 newMaxTries,
78 UINT32 newRecoveryTime,
79 UINT32 lockoutRecovery,
80 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
81 {
82 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
83 TSS2_RC rval;
84 rval = Tss2_Sys_DictionaryAttackParameters_Prepare(sysContext, lockHandle,
85 newMaxTries, newRecoveryTime,
86 lockoutRecovery);
87 if (rval)
88 return rval;
89
90 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
91 if (rval)
92 return rval;
93
94 return Tss2_Sys_DictionaryAttackParameters_Complete(sysContext);
95 }
96