#include <assert.h>
#include <string.h>
+#if defined __FreeBSD__
+# define _WITH_DPRINTF
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
# include <openssl/evp.h>
#endif
-#include "tpm12/tpm_debug.h"
+#include "tpm_debug.h"
#include "tpm_error.h"
#include "tpm_library.h"
#include "tpm_library_intern.h"
-#include "tpm_memory.h"
#include "tpm_nvfilename.h"
+#include "tpm_tis.h"
static const struct tags_and_indices {
const char *starttag;
switch (ver) {
case TPMLIB_TPM_VERSION_1_2:
+ if (tpmvers_choice != 0)
+ ClearAllCachedState();
+
tpmvers_choice = 0; // entry 0 in tpm_iface
break;
case TPMLIB_TPM_VERSION_2:
#if WITH_TPM2
+ if (tpmvers_choice != 1)
+ ClearAllCachedState();
+
tpmvers_choice = 1; // entry 1 in tpm_iface
break;
#endif
TPM_RESULT TPMLIB_SetState(enum TPMLIB_StateType st,
const unsigned char *buffer, uint32_t buflen)
{
- return tpm_iface[0]->SetState(st, buffer, buflen);
+ return tpm_iface[tpmvers_choice]->SetState(st, buffer, buflen);
}
TPM_RESULT TPMLIB_GetState(enum TPMLIB_StateType st,
unsigned char **buffer, uint32_t *buflen)
{
- return tpm_iface[0]->GetState(st, buffer, buflen);
+ return tpm_iface[tpmvers_choice]->GetState(st, buffer, buflen);
}
TPM_RESULT TPM_IO_Hash_Start(void)
va_end(args);
}
+/*
+ * TPMLIB_LogArray: Display an array of data
+ *
+ * @indent: how many spaces to indent; indent of ~0 forces logging
+ * with indent 0 even if not debug_level is set
+ * @data: the data to print
+ * @datalen: length of the data
+ */
+void TPMLIB_LogArray(unsigned int indent, const unsigned char *data,
+ size_t datalen)
+{
+ char line[80];
+ size_t i, o = 0;
+
+ for (i = 0; i < datalen; i++) {
+ snprintf(&line[o], sizeof(line) - o, "%02x ", data[i]);
+ o += 3;
+ if (o >= 16 * 3) {
+ TPMLIB_LogPrintfA(indent, "%s\n", line);
+ o = 0;
+ }
+ }
+ if (o > 0) {
+ TPMLIB_LogPrintfA(indent, "%s\n", line);
+ }
+}
+
void ClearCachedState(enum TPMLIB_StateType st)
{
free(cached_blobs[st].buffer);