diff --git a/src/Makefile.am b/src/Makefile.am index 38ab4647..08bd613a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 ?"; \ diff --git a/src/tpm2/Implementation.h b/src/tpm2/Implementation.h index f7e6a2e2..f1e4d163 100644 --- a/src/tpm2/Implementation.h +++ b/src/tpm2/Implementation.h @@ -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 diff --git a/src/tpm_library_intern.h b/src/tpm_library_intern.h index 136357f6..796522e5 100644 --- a/src/tpm_library_intern.h +++ b/src/tpm_library_intern.h @@ -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 */ diff --git a/src/tpm_tpm2_interface.c b/src/tpm_tpm2_interface.c index fa4268a5..a53db0f0 100644 --- a/src/tpm_tpm2_interface.c +++ b/src/tpm_tpm2_interface.c @@ -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); } /*