1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3  * Copyright (c) 2015 - 2018, 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 #include "util/tss2_endian.h"
15 
Tss2_Sys_GetDecryptParam(TSS2_SYS_CONTEXT * sysContext,size_t * decryptParamSize,const uint8_t ** decryptParamBuffer)16 TSS2_RC Tss2_Sys_GetDecryptParam(
17     TSS2_SYS_CONTEXT *sysContext,
18     size_t *decryptParamSize,
19     const uint8_t **decryptParamBuffer)
20 {
21     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
22     TPM2B *decryptParam;
23 
24     if (!decryptParamSize || !decryptParamBuffer || !ctx)
25         return TSS2_SYS_RC_BAD_REFERENCE;
26 
27     if (ctx->previousStage != CMD_STAGE_PREPARE)
28         return TSS2_SYS_RC_BAD_SEQUENCE;
29 
30     if (ctx->decryptAllowed == 0)
31         return TSS2_SYS_RC_NO_DECRYPT_PARAM;
32 
33     /* Get first parameter and return its size and a pointer to it. */
34     decryptParam = (TPM2B *)(ctx->cpBuffer);
35     *decryptParamSize = BE_TO_HOST_16(decryptParam->size);
36     *decryptParamBuffer = decryptParam->buffer;
37 
38     return TSS2_RC_SUCCESS;
39 }
40