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_StirRandom_Prepare(TSS2_SYS_CONTEXT * sysContext,const TPM2B_SENSITIVE_DATA * inData)15 TSS2_RC Tss2_Sys_StirRandom_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 const TPM2B_SENSITIVE_DATA *inData)
18 {
19 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
20 TSS2_RC rval;
21
22 if (!ctx)
23 return TSS2_SYS_RC_BAD_REFERENCE;
24
25 rval = CommonPreparePrologue(ctx, TPM2_CC_StirRandom);
26 if (rval)
27 return rval;
28
29 if (!inData) {
30 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
31 ctx->maxCmdSize,
32 &ctx->nextData);
33
34 } else {
35
36 rval = Tss2_MU_TPM2B_SENSITIVE_DATA_Marshal(inData, ctx->cmdBuffer,
37 ctx->maxCmdSize,
38 &ctx->nextData);
39 }
40
41 if (rval)
42 return rval;
43
44 ctx->decryptAllowed = 1;
45 ctx->encryptAllowed = 0;
46 ctx->authAllowed = 1;
47
48 return CommonPrepareEpilogue(ctx);
49 }
50
Tss2_Sys_StirRandom_Complete(TSS2_SYS_CONTEXT * sysContext)51 TSS2_RC Tss2_Sys_StirRandom_Complete (
52 TSS2_SYS_CONTEXT *sysContext)
53 {
54 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
55
56 if (!ctx)
57 return TSS2_SYS_RC_BAD_REFERENCE;
58
59 return CommonComplete(ctx);
60 }
61
Tss2_Sys_StirRandom(TSS2_SYS_CONTEXT * sysContext,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_SENSITIVE_DATA * inData,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)62 TSS2_RC Tss2_Sys_StirRandom(
63 TSS2_SYS_CONTEXT *sysContext,
64 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
65 const TPM2B_SENSITIVE_DATA *inData,
66 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
67 {
68 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
69 TSS2_RC rval;
70
71 rval = Tss2_Sys_StirRandom_Prepare(sysContext, inData);
72 if (rval)
73 return rval;
74
75 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
76 if (rval)
77 return rval;
78
79 return Tss2_Sys_StirRandom_Complete(sysContext);
80 }
81