1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /***********************************************************************; 3 * Copyright (c) 2015 - 2018, Intel Corporation 4 * All rights reserved. 5 ***********************************************************************/ 6 #ifdef HAVE_CONFIG_H 7 #include <config.h> 8 #endif 9 10 #include <string.h> 11 12 #include "tss2_tpm2_types.h" 13 #include "tss2_mu.h" 14 #include "sysapi_util.h" 15 #include "util/tss2_endian.h" 16 Tss2_Sys_SetEncryptParam(TSS2_SYS_CONTEXT * sysContext,size_t encryptParamSize,const uint8_t * encryptParamBuffer)17TSS2_RC Tss2_Sys_SetEncryptParam( 18 TSS2_SYS_CONTEXT *sysContext, 19 size_t encryptParamSize, 20 const uint8_t *encryptParamBuffer) 21 { 22 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext); 23 size_t currEncryptParamSize; 24 const uint8_t *currEncryptParamBuffer; 25 TSS2_RC rval; 26 27 if (!encryptParamBuffer || !ctx) 28 return TSS2_SYS_RC_BAD_REFERENCE; 29 30 rval = Tss2_Sys_GetEncryptParam(sysContext, 31 &currEncryptParamSize, 32 &currEncryptParamBuffer); 33 if (rval) 34 return rval; 35 36 if (encryptParamSize != currEncryptParamSize) 37 return TSS2_SYS_RC_BAD_SIZE; 38 39 if (currEncryptParamBuffer + encryptParamSize > 40 ctx->cmdBuffer + ctx->maxCmdSize) 41 return TSS2_SYS_RC_INSUFFICIENT_CONTEXT; 42 43 memmove((void *)currEncryptParamBuffer, 44 encryptParamBuffer, encryptParamSize); 45 46 return TSS2_RC_SUCCESS; 47 } 48