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_GetEncryptParam(TSS2_SYS_CONTEXT * sysContext,size_t * encryptParamSize,const uint8_t ** encryptParamBuffer)16TSS2_RC Tss2_Sys_GetEncryptParam( 17 TSS2_SYS_CONTEXT *sysContext, 18 size_t *encryptParamSize, 19 const uint8_t **encryptParamBuffer) 20 { 21 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext); 22 uint8_t *offset; 23 24 if (!encryptParamSize || !encryptParamBuffer || !ctx) 25 return TSS2_SYS_RC_BAD_REFERENCE; 26 27 if (ctx->encryptAllowed == 0) 28 return TSS2_SYS_RC_NO_ENCRYPT_PARAM; 29 30 if (ctx->previousStage != CMD_STAGE_RECEIVE_RESPONSE) 31 return TSS2_SYS_RC_BAD_SEQUENCE; 32 33 if (BE_TO_HOST_16(resp_header_from_cxt(ctx)->tag) == TPM2_ST_NO_SESSIONS) 34 return TSS2_SYS_RC_NO_ENCRYPT_PARAM; 35 36 /* Get first parameter, interpret it as a TPM2B and return its size field 37 * and a pointer to its buffer area. */ 38 offset = ctx->cmdBuffer 39 + sizeof(TPM20_Header_Out) 40 + ctx->numResponseHandles * sizeof(TPM2_HANDLE) 41 + sizeof(TPM2_PARAMETER_SIZE); 42 43 *encryptParamSize = BE_TO_HOST_16(*((UINT16 *)offset)); 44 *encryptParamBuffer = offset + sizeof(UINT16); 45 46 return TSS2_RC_SUCCESS; 47 } 48