tpm2: make I/O buffer sizes adjustable

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2017-11-05 11:28:19 -05:00
parent 5a273f8ead
commit 055f7f313c
4 changed files with 30 additions and 7 deletions

View File

@ -526,7 +526,7 @@ check:
echo "TPM_LIBTPMS_CALLBACK occurrence has changed to $$n from $$exp"; \
exit 1; \
fi; \
n=`grep TPM_BUFFER_MAX tpm2/Implementation.h | grep -E "^#define" | wc -l`; \
n=`grep TPM2_GetBufferSize tpm2/Implementation.h | grep -E "^#define" | wc -l`; \
exp=2; \
if test $$n -ne $$exp; then \
echo "Lost patches to tpm2/Implementation.h ?"; \

View File

@ -376,8 +376,9 @@
#define CONTEXT_ENCRYPT_ALGORITHM AES
#define NV_CLOCK_UPDATE_INTERVAL 12
#define NUM_POLICY_PCR 1
#define MAX_COMMAND_SIZE TPM_BUFFER_MAX
#define MAX_RESPONSE_SIZE TPM_BUFFER_MAX
#include "tpm_library_intern.h"
#define MAX_COMMAND_SIZE TPM2_GetBufferSize()
#define MAX_RESPONSE_SIZE TPM2_GetBufferSize()
#define ORDERLY_BITS 8
#define MAX_SYM_DATA 128
#define MAX_RNG_ENTROPY_SIZE 64

View File

@ -134,4 +134,6 @@ TPM_RESULT CopyCachedState(enum TPMLIB_StateType st,
const char *TPMLIB_StateTypeToName(enum TPMLIB_StateType st);
enum TPMLIB_StateType TPMLIB_NameToStateType(const char *name);
uint32_t TPM2_GetBufferSize(void);
#endif /* TPM_LIBRARY_INTERN_H */

View File

@ -315,16 +315,36 @@ error:
return NULL;
}
static uint32_t tpm2_buffersize = TPM_BUFFER_MAX;
uint32_t TPM2_SetBufferSize(uint32_t wanted_size,
uint32_t *min_size,
uint32_t *max_size)
{
/* FIXME: this needs to become adjustable */
const uint32_t min = MAX_CONTEXT_SIZE + 128;
const uint32_t max = TPM_BUFFER_MAX;
if (min_size)
*min_size = MAX_COMMAND_SIZE;
*min_size = min;
if (max_size)
*max_size = MAX_COMMAND_SIZE;
return MAX_COMMAND_SIZE;
*max_size = max;
if (wanted_size == 0)
return tpm2_buffersize;
if (wanted_size > max)
wanted_size = max;
else if (wanted_size < min)
wanted_size = min;
tpm2_buffersize = wanted_size;
return tpm2_buffersize;
}
uint32_t TPM2_GetBufferSize(void)
{
return TPM2_SetBufferSize(0, NULL, NULL);
}
/*