diff --git a/INSTALL.md b/INSTALL.md index 769211ec5..9bd85d553 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -223,3 +223,31 @@ $ make doxygen-doc The generated documentation will appear here: * doxygen-doc/html HTML format (start with file doxygen-doc/html/index.html) * doxygen-doc/rtf/refman.rtf RTF format + +# Building for embedded + +The libraries SYS, ESYS, MU, RC, tctildr, tcti-spi-helper, tcti-i2c-helper +can also be build for embedded devices. The following is an example to build +for cortex-m4: +``` +./bootstrap +./configure \ + --disable-fapi \ + --disable-esys \ + --disable-policy \ + --disable-tcti-cmd \ + --disable-tcti-device \ + --disable-tcti-libtpms \ + --disable-tcti-mssim \ + --disable-tcti-pcap \ + --disable-tcti-spi-lt2go \ + --disable-tcti-spi-ftdi \ + --disable-tcti-swtpm \ + --disable-doxygen-doc \ + --enable-nodl \ + --host=arm-none-eabi \ + --prefix=/home/afuchs/tpm2-software/INSTALL.uC \ + CFLAGS='-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb' \ + LDFLAGS='--specs=nosys.specs' +make +``` \ No newline at end of file diff --git a/Makefile-test.am b/Makefile-test.am index 827c4736e..0f2c02f5c 100644 --- a/Makefile-test.am +++ b/Makefile-test.am @@ -8,7 +8,7 @@ TESTS_CFLAGS = $(AM_CFLAGS) $(CRYPTO_CFLAGS) -I$(srcdir)/include -I$(srcdir)/src -I$(srcdir)/test/data -Wno-unused-parameter -Wno-missing-field-initializers \ -DTOP_SOURCEDIR"=\"$(top_srcdir)\"" TESTS_LDADD = $(check_LTLIBRARIES) $(lib_LTLIBRARIES) \ - $(CRYPTO_LIBS) $(libutil) + $(CRYPTO_LIBS) $(libutil) $(libutilio) check_LTLIBRARIES = # test harness configuration @@ -483,7 +483,7 @@ CLEANFILES += \ if UNIT if ENABLE_TCTI_DEVICE test_unit_tcti_device_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS) -test_unit_tcti_device_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) +test_unit_tcti_device_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) $(libutilio) test_unit_tcti_device_LDFLAGS = -Wl,--wrap=read -Wl,--wrap=write -Wl,--wrap=poll \ -Wl,--wrap=open test_unit_tcti_device_SOURCES = test/unit/tcti-device.c \ @@ -493,7 +493,7 @@ endif if ENABLE_TCTI_MSSIM test_unit_tcti_mssim_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS) -test_unit_tcti_mssim_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) +test_unit_tcti_mssim_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) $(libutilio) test_unit_tcti_mssim_LDFLAGS = -Wl,--wrap=connect -Wl,--wrap=read -Wl,--wrap=write -Wl,--wrap=poll test_unit_tcti_mssim_SOURCES = test/unit/tcti-mssim.c \ src/tss2-tcti/tcti-common.c \ @@ -502,7 +502,7 @@ endif if ENABLE_TCTI_SWTPM test_unit_tcti_swtpm_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS) -test_unit_tcti_swtpm_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) +test_unit_tcti_swtpm_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) $(libutilio) test_unit_tcti_swtpm_LDFLAGS = -Wl,--wrap=connect,--wrap=read,--wrap=select,--wrap=write test_unit_tcti_swtpm_SOURCES = test/unit/tcti-swtpm.c \ src/tss2-tcti/tcti-common.c \ @@ -522,7 +522,7 @@ endif if ENABLE_TCTI_PCAP test_unit_tcti_pcap_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS) -test_unit_tcti_pcap_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) +test_unit_tcti_pcap_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) $(libutilio) test_unit_tcti_pcap_LDFLAGS = -Wl,--wrap=getenv -Wl,--wrap=rand -Wl,--wrap=clock_gettime \ -Wl,--wrap=open -Wl,--wrap=read -Wl,--wrap=write -Wl,--wrap=close \ -Wl,--wrap=__clock_gettime64 @@ -652,7 +652,7 @@ test_unit_tctildr_getinfo_SOURCES = test/unit/tctildr-getinfo.c \ src/tss2-tcti/tctildr.c test_unit_io_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS) -test_unit_io_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) +test_unit_io_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil) $(libutilio) test_unit_io_LDFLAGS = -Wl,--wrap=connect,--wrap=read,--wrap=socket,--wrap=write test_unit_key_value_parse_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS) diff --git a/Makefile.am b/Makefile.am index 2a743660d..12de494fc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -249,6 +249,12 @@ libutil = libutil.la noinst_LTLIBRARIES += $(libutil) libutil_la_SOURCES = $(UTIL_SRC) +if ENABLE_UTIL_IO +libutilio = libutil-io.la +noinst_LTLIBRARIES += $(libutilio) +libutil_io_la_SOURCES = $(UTIL_IO_SRC) +endif + ### TCG TSS Marshaling/Unmarshaling spec library ### libtss2_mu = src/tss2-mu/libtss2-mu.la tss2_HEADERS += $(srcdir)/include/tss2/tss2_mu.h @@ -301,7 +307,7 @@ pkgconfig_DATA += lib/tss2-tcti-device.pc if HAVE_LD_VERSION_SCRIPT src_tss2_tcti_libtss2_tcti_device_la_LDFLAGS = -Wl,--version-script=$(srcdir)/lib/tss2-tcti-device.map endif # HAVE_LD_VERSION_SCRIPT -src_tss2_tcti_libtss2_tcti_device_la_LIBADD = $(libtss2_mu) $(libutil) +src_tss2_tcti_libtss2_tcti_device_la_LIBADD = $(libtss2_mu) $(libutil) $(libutilio) src_tss2_tcti_libtss2_tcti_device_la_SOURCES = \ src/tss2-tcti/tcti-common.c \ src/tss2-tcti/tcti-device.c @@ -318,7 +324,7 @@ pkgconfig_DATA += lib/tss2-tcti-swtpm.pc if HAVE_LD_VERSION_SCRIPT src_tss2_tcti_libtss2_tcti_swtpm_la_LDFLAGS = -Wl,--version-script=$(srcdir)/lib/tss2-tcti-swtpm.map endif # HAVE_LD_VERSION_SCRIPT -src_tss2_tcti_libtss2_tcti_swtpm_la_LIBADD = $(libtss2_mu) $(libutil) +src_tss2_tcti_libtss2_tcti_swtpm_la_LIBADD = $(libtss2_mu) $(libutil) $(libutilio) src_tss2_tcti_libtss2_tcti_swtpm_la_SOURCES = \ src/tss2-tcti/tcti-common.c \ src/tss2-tcti/tcti-swtpm.c \ @@ -336,7 +342,7 @@ pkgconfig_DATA += lib/tss2-tcti-mssim.pc if HAVE_LD_VERSION_SCRIPT src_tss2_tcti_libtss2_tcti_mssim_la_LDFLAGS = -Wl,--version-script=$(srcdir)/lib/tss2-tcti-mssim.map endif # HAVE_LD_VERSION_SCRIPT -src_tss2_tcti_libtss2_tcti_mssim_la_LIBADD = $(libtss2_mu) $(libutil) +src_tss2_tcti_libtss2_tcti_mssim_la_LIBADD = $(libtss2_mu) $(libutil) $(libutilio) src_tss2_tcti_libtss2_tcti_mssim_la_SOURCES = \ src/tss2-tcti/tcti-common.c \ src/tss2-tcti/tcti-mssim.c @@ -355,7 +361,7 @@ pkgconfig_DATA += lib/tss2-tcti-pcap.pc if HAVE_LD_VERSION_SCRIPT src_tss2_tcti_libtss2_tcti_pcap_la_LDFLAGS = -Wl,--version-script=$(srcdir)/lib/tss2-tcti-pcap.map endif # HAVE_LD_VERSION_SCRIPT -src_tss2_tcti_libtss2_tcti_pcap_la_LIBADD = $(libtss2_tctildr) $(libtss2_mu) $(libutil) +src_tss2_tcti_libtss2_tcti_pcap_la_LIBADD = $(libtss2_tctildr) $(libtss2_mu) $(libutil) $(libutilio) src_tss2_tcti_libtss2_tcti_pcap_la_SOURCES = \ src/tss2-tcti/tcti-common.c \ src/tss2-tcti/tcti-pcap-builder.c \ diff --git a/bootstrap b/bootstrap index c25c9a374..f70ff0366 100755 --- a/bootstrap +++ b/bootstrap @@ -52,6 +52,10 @@ echo "Generating file lists: ${VARS_FILE}" src_listvar "src/util" "*.h" "UTIL_H" printf "UTIL_SRC = \$(UTIL_C) \$(UTIL_H)\n" + src_listvar "src/util-io" "*.c" "UTIL_IO_C" + src_listvar "src/util-io" "*.h" "UTIL_IO_H" + printf "UTIL_IO_SRC = \$(UTIL_IO_C) \$(UTIL_IO_H)\n" + src_listvar "src/tss2-sys/" "*.c" "TSS2_SYS_C" src_listvar "src/tss2-sys/" "*.h" "TSS2_SYS_H" printf "TSS2_SYS_SRC = \$(TSS2_SYS_H) \$(TSS2_SYS_C)\n" diff --git a/configure.ac b/configure.ac index d47adc1cf..717dcef86 100644 --- a/configure.ac +++ b/configure.ac @@ -151,7 +151,7 @@ AS_IF([test "x$enable_fapi_async_tests" = "xyes"], [AC_MSG_WARN("FAPI compiled with asynchronous spinning testing. NOT FOR PRODUCTION!")]) AC_ARG_ENABLE([policy], - [AS_HELP_STRING([--enable-policy], + [AS_HELP_STRING([--disable-policy], [build the tss2-policy library (default is yes)])], [enable_policy=$enableval], [enable_policy=yes]) @@ -226,6 +226,13 @@ AC_CHECK_LIB([curl], [curl_url_strerror], [AC_DEFINE([HAVE_CURL_URL_STRERROR],[1 AS_IF([test "x$enable_fapi" = xyes -o "x$enable_policy" = xyes ], [PKG_CHECK_MODULES([UUID], [uuid])]) +AC_ARG_ENABLE([util-io], + [AS_HELP_STRING([--disable-util-io], + [don't build the util-io])],, + [enable_util_io=yes]) + +AM_CONDITIONAL(ENABLE_UTIL_IO, test "x$enable_util_io" = "xyes") + AC_ARG_WITH([tctidefaultmodule], [AS_HELP_STRING([--with-tctidefaultmodule], [The default TCTI module for ESYS. (Default: libtss2-tcti-default.so)])], diff --git a/doc/tcti-spi-helper.md b/doc/tcti-spi-helper.md index 9723b564a..21907d749 100644 --- a/doc/tcti-spi-helper.md +++ b/doc/tcti-spi-helper.md @@ -222,7 +222,7 @@ TSS2_TCTI_CONTEXT* create_tcti_ctx() // Get requested TCTI context size rc = Tss2_Tcti_Spi_Helper_Init(NULL, &size, &tcti_platform); if (rc != TSS2_RC_SUCCESS) { - printf("Failed to get allocation size for device tcti context: 0x%x\n", rc); + printf("Failed to get allocation size for device tcti context: 0x%"PRIx32"\n", rc); return NULL; } @@ -236,7 +236,7 @@ TSS2_TCTI_CONTEXT* create_tcti_ctx() // Initialize TCTI context rc = Tss2_Tcti_Spi_Helper_Init(tcti_ctx, &size, &tcti_platform); if (rc != TSS2_RC_SUCCESS) { - printf("Failed to initialize device TCTI context: 0x%x\n", rc); + printf("Failed to initialize device TCTI context: 0x%"PRIx32"\n", rc); free(tcti_ctx); return NULL; } diff --git a/src/tss2-esys/api/Esys_StartAuthSession.c b/src/tss2-esys/api/Esys_StartAuthSession.c index c1834e938..d9319eb20 100644 --- a/src/tss2-esys/api/Esys_StartAuthSession.c +++ b/src/tss2-esys/api/Esys_StartAuthSession.c @@ -436,14 +436,14 @@ Esys_StartAuthSession_Finish( tpmKeyNode->rsrc.misc.rsrc_key_pub.publicArea.nameAlg, & keyHash_size); if (r != TSS2_RC_SUCCESS) { - LOG_ERROR("Error: initialize auth session (%x).", r); + LOG_ERROR("Error: initialize auth session (0x%08"PRIx32").", r); return r; } } r = iesys_crypto_hash_get_digest_size(esysContext->in.StartAuthSession. authHash,&authHash_size); if (r != TSS2_RC_SUCCESS) { - LOG_ERROR("Error: initialize auth session (%x).", r); + LOG_ERROR("Error: initialize auth session (0x%08"PRIx32").", r); return r; } /* compute session key except for an unbound session */ diff --git a/src/tss2-esys/esys_iutil.c b/src/tss2-esys/esys_iutil.c index 79e614371..3f4fe2b48 100644 --- a/src/tss2-esys/esys_iutil.c +++ b/src/tss2-esys/esys_iutil.c @@ -392,7 +392,7 @@ iesys_handle_to_tpm_handle(ESYS_TR esys_handle, TPM2_HANDLE * tpm_handle) *tpm_handle = TPM2_NV_AC_FIRST + (esys_handle - ESYS_TR_RH_AC_FIRST); return TPM2_RC_SUCCESS; } - LOG_ERROR("Error: Esys invalid ESAPI handle (%x).", esys_handle); + LOG_ERROR("Error: Esys invalid ESAPI handle (%"PRIx32").", esys_handle); return TSS2_ESYS_RC_BAD_VALUE; } @@ -413,7 +413,7 @@ iesys_is_platform_handle(ESYS_TR handle) { case TPM2_RH_PLATFORM_NV: case TPM2_RH_ENDORSEMENT: case TPM2_RH_NULL: - LOG_WARNING("Convert handle from TPM2_RH to ESYS_TR, got: 0x%x", + LOG_WARNING("Convert handle from TPM2_RH to ESYS_TR, got: 0x%"PRIx32, handle); return true; default: @@ -574,7 +574,7 @@ iesys_gen_caller_nonces(ESYS_CONTEXT * esys_context) r = iesys_crypto_get_random2b(&esys_context->crypto_backend, &session->rsrc.misc.rsrc_session.nonceCaller, session->rsrc.misc.rsrc_session.nonceCaller.size); - return_if_error(r, "Error: computing caller nonce (%x)."); + return_if_error(r, "Error: computing caller nonce."); } return TSS2_RC_SUCCESS; } @@ -612,7 +612,7 @@ iesys_update_session_flags(ESYS_CONTEXT * esys_context, rsrc_session->sessionAttributes &= ~(TPMA_SESSION_ENCRYPT); } - LOG_DEBUG("Session Attrs 0x%x orig 0x%x", + LOG_DEBUG("Session Attrs 0x%"PRIx32" orig 0x%"PRIx32, rsrc_session->sessionAttributes, rsrc_session->origSessionAttributes); } @@ -633,7 +633,7 @@ iesys_restore_session_flags(ESYS_CONTEXT *esys_context) if (session == NULL) continue; IESYS_SESSION *rsrc_session = &session->rsrc.misc.rsrc_session; - LOG_DEBUG("Orig Session %i Attrs 0x%x, altered Attrs x%x", i, + LOG_DEBUG("Orig Session %i Attrs 0x%"PRIx8", altered Attrs x%"PRIx8, i, rsrc_session->origSessionAttributes, rsrc_session->sessionAttributes); @@ -1166,7 +1166,7 @@ esys_GetResourceObject(ESYS_CONTEXT * esys_context, /* All objects with a TR-handle larger than ESYS_TR_MIN_OBJECT must have been initialized previously. Therefore the TR handle was erroneous. */ if (esys_handle >= ESYS_TR_MIN_OBJECT) { - LOG_ERROR("Error: Esys handle does not exist (%x).", + LOG_ERROR("Error: Esys handle does not exist (0x%08"PRIx32").", TSS2_ESYS_RC_BAD_TR); return TSS2_ESYS_RC_BAD_TR; } diff --git a/src/tss2-esys/esys_tr.c b/src/tss2-esys/esys_tr.c index 63c7f3896..a32929b0f 100644 --- a/src/tss2-esys/esys_tr.c +++ b/src/tss2-esys/esys_tr.c @@ -431,7 +431,7 @@ Esys_TR_Close(ESYS_CONTEXT * esys_context, ESYS_TR * object) return TSS2_RC_SUCCESS; } } - LOG_ERROR("Error: Esys handle does not exist (%x).", TSS2_ESYS_RC_BAD_TR); + LOG_ERROR("Error: Esys handle does not exist (0x%08"PRIx32").", TSS2_ESYS_RC_BAD_TR); return TSS2_ESYS_RC_BAD_TR; } diff --git a/src/tss2-mu/tpmu-types.c b/src/tss2-mu/tpmu-types.c index a615a9baf..2c1720947 100644 --- a/src/tss2-mu/tpmu-types.c +++ b/src/tss2-mu/tpmu-types.c @@ -285,7 +285,7 @@ TSS2_RC Tss2_MU_##type##_Marshal(type const *src, uint32_t selector, uint8_t buf return TSS2_MU_RC_BAD_REFERENCE; \ } \ \ - LOG_DEBUG("Marshalling " #type ", selector %x", selector); \ + LOG_DEBUG("Marshalling " #type ", selector 0x%"PRIx32, selector); \ switch (selector) { \ case sel: \ ret = fn(op src->m, buffer, buffer_size, offset); \ @@ -328,7 +328,7 @@ TSS2_RC Tss2_MU_##type##_Marshal(type const *src, uint32_t selector, uint8_t buf ret = TSS2_RC_SUCCESS; \ break; \ default: \ - LOG_DEBUG("wrong selector %x return error", selector); \ + LOG_DEBUG("wrong selector 0x%"PRIx32" return error", selector); \ break; \ } \ return ret; \ @@ -382,7 +382,7 @@ TSS2_RC Tss2_MU_##type##_Unmarshal(uint8_t const buffer[], size_t buffer_size, \ { \ TSS2_RC ret = TSS2_MU_RC_BAD_VALUE; \ \ - LOG_DEBUG("Unmarshalling " #type ", selector %x", selector); \ + LOG_DEBUG("Unmarshalling " #type ", selector 0x%"PRIx32, selector); \ switch (selector) { \ case sel: \ ret = fn(buffer, buffer_size, offset, dest ? &dest->m : NULL); \ @@ -425,7 +425,7 @@ TSS2_RC Tss2_MU_##type##_Unmarshal(uint8_t const buffer[], size_t buffer_size, \ ret = TSS2_RC_SUCCESS; \ break; \ default: \ - LOG_DEBUG("wrong selector %x return error", selector); \ + LOG_DEBUG("wrong selector 0x%"PRIx32" return error", selector); \ break; \ } \ return ret; \ diff --git a/src/tss2-policy/tss2_policy.c b/src/tss2-policy/tss2_policy.c index 5cf3f394a..e8c6b2520 100644 --- a/src/tss2-policy/tss2_policy.c +++ b/src/tss2-policy/tss2_policy.c @@ -250,7 +250,7 @@ Tss2_PolicyExecute( through all execution stages / states of this invocation. */ } while (is_try_again(r)); - LOG_TRACE("finished, returning: 0x%x", r); + LOG_TRACE("finished, returning: 0x%"PRIx32, r); return r; } diff --git a/src/tss2-rc/tss2_rc.c b/src/tss2-rc/tss2_rc.c index 304908e46..b5d386443 100644 --- a/src/tss2-rc/tss2_rc.c +++ b/src/tss2-rc/tss2_rc.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "tss2_rc.h" #include "tss2_sys.h" @@ -641,7 +642,7 @@ tpm2_err_handler_fmt1(TPM2_RC rc) if (m) { catbuf(buf, "%s", m); } else { - catbuf(buf, "unknown error num: 0x%X", errnum); + catbuf(buf, "unknown error num: 0x%"PRIX8, errnum); } return buf; @@ -663,7 +664,7 @@ tpm2_err_handler_fmt0(TSS2_RC rc) if (tpm2_rc_tpm_fmt0_V_get(rc)) { /* TCG specific error code */ if (tpm2_rc_fmt0_T_get(rc)) { - catbuf(buf, "Vendor specific error: 0x%X", errnum); + catbuf(buf, "Vendor specific error: 0x%"PRIX8, errnum); return buf; } @@ -884,7 +885,7 @@ unknown_layer_handler(TSS2_RC rc) static __thread char buf[32]; clearbuf(buf); - catbuf(buf, "0x%X", rc); + catbuf(buf, "0x%"PRIX32, rc); return buf; } @@ -992,7 +993,7 @@ Tss2_RC_Decode(TSS2_RC rc) if (e) { catbuf(buf, "%s", e); } else { - catbuf(buf, "0x%X", err_bits); + catbuf(buf, "0x%"PRIX16, err_bits); } } else { /* @@ -1076,7 +1077,7 @@ Tss2_RC_DecodeInfoError(TSS2_RC_INFO *info) if (m) { catbuf(buf, "%s", m); } else { - catbuf(buf, "0x%X", info->error); + catbuf(buf, "0x%"PRIX32, info->error); } return buf; diff --git a/src/tss2-sys/api/Tss2_Sys_Execute.c b/src/tss2-sys/api/Tss2_Sys_Execute.c index 8935940ac..ae5a77fd6 100644 --- a/src/tss2-sys/api/Tss2_Sys_Execute.c +++ b/src/tss2-sys/api/Tss2_Sys_Execute.c @@ -75,7 +75,7 @@ TSS2_RC Tss2_Sys_ExecuteFinish(TSS2_SYS_CONTEXT *sysContext, int32_t timeout) } if (response_size > ctx->maxCmdSize) { ctx->previousStage = CMD_STAGE_PREPARE; - LOG_ERROR("Response size to big: %zu > %u", response_size, ctx->maxCmdSize); + LOG_ERROR("Response size to big: %zu > %"PRIu32, response_size, ctx->maxCmdSize); return TSS2_SYS_RC_INSUFFICIENT_CONTEXT; } diff --git a/src/tss2-tcti/tcti-cmd.h b/src/tss2-tcti/tcti-cmd.h index cd7bdf567..923e66c5e 100644 --- a/src/tss2-tcti/tcti-cmd.h +++ b/src/tss2-tcti/tcti-cmd.h @@ -10,7 +10,7 @@ #include #include "tcti-common.h" -#include "util/io.h" +#include "util-io/io.h" #define TCTI_CMD_NAME "tcti-cmd" #define TCTI_CMD_DESCRIPTION "TCTI module for using a process to send and receive data." diff --git a/src/tss2-tcti/tcti-device.c b/src/tss2-tcti/tcti-device.c index 87e365e8f..68a9392d2 100644 --- a/src/tss2-tcti/tcti-device.c +++ b/src/tss2-tcti/tcti-device.c @@ -52,7 +52,7 @@ #include "tss2_mu.h" #include "tcti-common.h" #include "tcti-device.h" -#include "util/io.h" +#include "util-io/io.h" #include "util/aux_util.h" #define LOGMODULE tcti #include "util/log.h" diff --git a/src/tss2-tcti/tcti-i2c-ftdi.c b/src/tss2-tcti/tcti-i2c-ftdi.c index 4bb0e8c7d..3c7c809be 100644 --- a/src/tss2-tcti/tcti-i2c-ftdi.c +++ b/src/tss2-tcti/tcti-i2c-ftdi.c @@ -36,7 +36,6 @@ #include "tss2_tcti_i2c_ftdi.h" #include "tcti-i2c-helper.h" #include "tss2_mu.h" -#include "util/io.h" #define LOGMODULE tcti #include "util/log.h" diff --git a/src/tss2-tcti/tcti-i2c-helper.c b/src/tss2-tcti/tcti-i2c-helper.c index 7147cda9d..3dc6f5045 100644 --- a/src/tss2-tcti/tcti-i2c-helper.c +++ b/src/tss2-tcti/tcti-i2c-helper.c @@ -37,7 +37,6 @@ #include "tss2_mu.h" #include "tcti-common.h" #include "tcti-i2c-helper.h" -#include "util/io.h" #include "util/tss2_endian.h" #define LOGMODULE tcti #include "util/log.h" @@ -257,10 +256,10 @@ static TSS2_RC i2c_tpm_sanity_check_read (uint8_t reg, uint8_t *buffer, size_t c value = buffer[0]; break; case sizeof (uint16_t): - value = le16toh (*((uint16_t *)buffer)); + value = LE_TO_HOST_16 (*((uint16_t *)buffer)); break; case sizeof (uint32_t): - value = le32toh (*((uint32_t *)buffer)); + value = LE_TO_HOST_32 (*((uint32_t *)buffer)); break; default: return TSS2_RC_SUCCESS; @@ -349,12 +348,12 @@ static uint32_t i2c_tpm_helper_read_sts_reg (TSS2_TCTI_I2C_HELPER_CONTEXT* ctx) { uint32_t status = 0; i2c_tpm_helper_read_reg (ctx, TCTI_I2C_HELPER_TPM_STS_REG, &status, sizeof(status)); - return le32toh (status); + return LE_TO_HOST_32 (status); } static void i2c_tpm_helper_write_sts_reg (TSS2_TCTI_I2C_HELPER_CONTEXT* ctx, uint32_t status) { - status = htole32 (status); + status = HOST_TO_LE_32 (status); i2c_tpm_helper_write_reg (ctx, TCTI_I2C_HELPER_TPM_STS_REG, &status, sizeof (status)); } @@ -415,7 +414,7 @@ static TSS2_RC i2c_tpm_helper_init_guard_time (TSS2_TCTI_I2C_HELPER_CONTEXT* ctx return rc; } - i2c_caps = le32toh (i2c_caps); + i2c_caps = LE_TO_HOST_32 (i2c_caps); ctx->guard_time_read = (i2c_caps & TCTI_I2C_HELPER_TPM_GUARD_TIME_RR_MASK) || (i2c_caps & TCTI_I2C_HELPER_TPM_GUARD_TIME_RW_MASK); @@ -488,7 +487,7 @@ static TSS2_RC i2c_tpm_helper_verify_crc (TSS2_TCTI_I2C_HELPER_CONTEXT* ctx, con return rc; } - crc_tpm = le16toh (crc_tpm); + crc_tpm = LE_TO_HOST_16 (crc_tpm); /* Reflect crc result, regardless of host endianness */ crc_tpm = ((crc_tpm >> 8) & 0xFFu) | ((crc_tpm << 8) & 0xFF00u); crc_host = crc_ccitt (buffer, size); @@ -552,7 +551,7 @@ TSS2_RC tcti_i2c_helper_transmit (TSS2_TCTI_CONTEXT *tcti_ctx, size_t size, cons return TSS2_TCTI_RC_BAD_VALUE; } - LOGBLOB_DEBUG (cmd_buf, size, "Sending command with TPM_CC %#x and size %" PRIu32, + LOGBLOB_DEBUG (cmd_buf, size, "Sending command with TPM_CC %#"PRIx32" and size %" PRIu32, header.code, header.size); /* Tell TPM to expect command */ @@ -653,7 +652,7 @@ TSS2_RC tcti_i2c_helper_receive (TSS2_TCTI_CONTEXT* tcti_context, size_t *respon /* Verify that there is still data to read */ uint32_t status = i2c_tpm_helper_read_sts_reg (ctx); if ((status & expected_status_bits) != expected_status_bits) { - LOG_ERROR ("Unexpected intermediate status %#x",status); + LOG_ERROR ("Unexpected intermediate status %#"PRIx32,status); return TSS2_TCTI_RC_IO_ERROR; } @@ -666,7 +665,7 @@ TSS2_RC tcti_i2c_helper_receive (TSS2_TCTI_CONTEXT* tcti_context, size_t *respon /* Verify that there is no more data available */ status = i2c_tpm_helper_read_sts_reg (ctx); if ((status & expected_status_bits) != TCTI_I2C_HELPER_TPM_STS_VALID) { - LOG_ERROR ("Unexpected final status %#x", status); + LOG_ERROR ("Unexpected final status %#"PRIx32, status); return TSS2_TCTI_RC_IO_ERROR; } @@ -783,7 +782,7 @@ TSS2_RC Tss2_Tcti_I2c_Helper_Init (TSS2_TCTI_CONTEXT* tcti_context, size_t* size /* In case of failed read div_vid is set to zero */ i2c_tpm_helper_read_reg (ctx, TCTI_I2C_HELPER_TPM_DID_VID_REG, &did_vid, sizeof(did_vid)); if (did_vid != 0) { - did_vid = le32toh (did_vid); + did_vid = LE_TO_HOST_32 (did_vid); break; } /* TPM might be resetting, let's retry in a bit */ diff --git a/src/tss2-tcti/tcti-libtpms.h b/src/tss2-tcti/tcti-libtpms.h index c811548cd..a5b90800d 100644 --- a/src/tss2-tcti/tcti-libtpms.h +++ b/src/tss2-tcti/tcti-libtpms.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -17,7 +18,6 @@ #include #include "tcti-common.h" -#include "util/io.h" #include "util/aux_util.h" #define TCTI_LIBTPMS_MAGIC 0x49E299A554504D32ULL diff --git a/src/tss2-tcti/tcti-mssim.h b/src/tss2-tcti/tcti-mssim.h index c1001d72f..e2aacc30e 100644 --- a/src/tss2-tcti/tcti-mssim.h +++ b/src/tss2-tcti/tcti-mssim.h @@ -10,7 +10,7 @@ #include #include "tcti-common.h" -#include "util/io.h" +#include "util-io/io.h" /* * longest possible conf string: diff --git a/src/tss2-tcti/tcti-pcap-builder.c b/src/tss2-tcti/tcti-pcap-builder.c index 6aa2dec5d..f6b6af7e8 100644 --- a/src/tss2-tcti/tcti-pcap-builder.c +++ b/src/tss2-tcti/tcti-pcap-builder.c @@ -20,7 +20,7 @@ #include "tss2_common.h" #include "tcti-pcap-builder.h" -#include "util/io.h" +#include "util-io/io.h" #define LOGMODULE tcti #include "util/log.h" diff --git a/src/tss2-tcti/tcti-spi-ftdi.c b/src/tss2-tcti/tcti-spi-ftdi.c index c8336283d..d75e17b46 100644 --- a/src/tss2-tcti/tcti-spi-ftdi.c +++ b/src/tss2-tcti/tcti-spi-ftdi.c @@ -36,7 +36,6 @@ #include "tss2_tcti_spi_ftdi.h" #include "tcti-spi-helper.h" #include "tss2_mu.h" -#include "util/io.h" #define LOGMODULE tcti #include "util/log.h" diff --git a/src/tss2-tcti/tcti-spi-helper.c b/src/tss2-tcti/tcti-spi-helper.c index 515a53639..b753defd3 100644 --- a/src/tss2-tcti/tcti-spi-helper.c +++ b/src/tss2-tcti/tcti-spi-helper.c @@ -18,7 +18,6 @@ #include "tss2_mu.h" #include "tcti-common.h" #include "tcti-spi-helper.h" -#include "util/io.h" #define LOGMODULE tcti #include "util/log.h" @@ -155,12 +154,12 @@ static void spi_tpm_helper_log_register_access(enum TCTI_SPI_HELPER_REGISTER_ACC char* access_str = (access == TCTI_SPI_HELPER_REGISTER_READ) ? "READ" : "WRITE"; if (err != NULL) { - LOG_ERROR("%s register %#02x (%zu bytes) %s", access_str, reg_number, cnt, err); + LOG_ERROR("%s register %#02"PRIx32" (%zu bytes) %s", access_str, reg_number, cnt, err); } else { #if MAXLOGLEVEL < LOGL_TRACE (void) buffer; #else - LOGBLOB_TRACE(buffer, cnt, "%s register %#02x (%zu bytes)", access_str, reg_number, cnt); + LOGBLOB_TRACE(buffer, cnt, "%s register %#02"PRIx32" (%zu bytes)", access_str, reg_number, cnt); #endif } #endif @@ -545,7 +544,7 @@ TSS2_RC tcti_spi_helper_receive (TSS2_TCTI_CONTEXT* tcti_context, size_t *respon // Verify that there is still data to read uint32_t status = spi_tpm_helper_read_sts_reg(ctx); if ((status & expected_status_bits) != expected_status_bits) { - LOG_ERROR("Unexpected intermediate status %#x",status); + LOG_ERROR("Unexpected intermediate status %#"PRIx32,status); return TSS2_TCTI_RC_IO_ERROR; } @@ -558,7 +557,7 @@ TSS2_RC tcti_spi_helper_receive (TSS2_TCTI_CONTEXT* tcti_context, size_t *respon // Verify that there is no more data available status = spi_tpm_helper_read_sts_reg(ctx); if ((status & expected_status_bits) != TCTI_SPI_HELPER_TPM_STS_VALID) { - LOG_ERROR("Unexpected final status %#x", status); + LOG_ERROR("Unexpected final status %#"PRIx32, status); return TSS2_TCTI_RC_IO_ERROR; } @@ -613,7 +612,7 @@ TSS2_RC tcti_spi_helper_transmit (TSS2_TCTI_CONTEXT *tcti_ctx, size_t size, cons return TSS2_TCTI_RC_BAD_VALUE; } - LOGBLOB_DEBUG (cmd_buf, size, "Sending command with TPM_CC %#x and size %" PRIu32, + LOGBLOB_DEBUG (cmd_buf, size, "Sending command with TPM_CC %#"PRIx32" and size %" PRIu32, header.code, header.size); // Tell TPM to expect command diff --git a/src/tss2-tcti/tcti-spi-ltt2go.c b/src/tss2-tcti/tcti-spi-ltt2go.c index f1e3875fa..ec0daa531 100644 --- a/src/tss2-tcti/tcti-spi-ltt2go.c +++ b/src/tss2-tcti/tcti-spi-ltt2go.c @@ -18,7 +18,6 @@ #include "tss2_tcti_spi_ltt2go.h" #include "tcti-spi-helper.h" #include "tss2_mu.h" -#include "util/io.h" #define LOGMODULE tcti #include "util/log.h" diff --git a/src/tss2-tcti/tcti-swtpm.h b/src/tss2-tcti/tcti-swtpm.h index 320b8c195..eef88c851 100644 --- a/src/tss2-tcti/tcti-swtpm.h +++ b/src/tss2-tcti/tcti-swtpm.h @@ -10,7 +10,7 @@ #include #include "tcti-common.h" -#include "util/io.h" +#include "util-io/io.h" /* * longest possible conf string: diff --git a/src/tss2-tcti/tctildr-dl.c b/src/tss2-tcti/tctildr-dl.c index 622637dce..363d32b66 100644 --- a/src/tss2-tcti/tctildr-dl.c +++ b/src/tss2-tcti/tctildr-dl.c @@ -202,7 +202,14 @@ get_info_default(const TSS2_TCTI_INFO **info, return TSS2_TCTI_RC_IO_ERROR; #else size_t i; + if (ARRAY_SIZE(tctis) == 0) { + LOG_ERROR("No default TCTIs configured during compilation"); + return TSS2_TCTI_RC_IO_ERROR; + } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" for (i = 0; i < ARRAY_SIZE(tctis); i++) { +#pragma GCC diagnostic pop name = tctis[i].file; LOG_DEBUG("name: %s", name); if (name == NULL) { @@ -256,7 +263,14 @@ tctildr_get_default(TSS2_TCTI_CONTEXT ** tcticontext, void **dlhandle) TSS2_RC r; size_t i; + if (ARRAY_SIZE(tctis) == 0) { + LOG_ERROR("No default TCTIs configured during compilation"); + return TSS2_TCTI_RC_IO_ERROR; + } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" for (i = 0; i < ARRAY_SIZE(tctis); i++) { +#pragma GCC diagnostic pop LOG_DEBUG("Attempting to connect using standard TCTI: %s", tctis[i].description); r = tcti_from_file(tctis[i].file, tctis[i].conf, tcticontext, diff --git a/src/tss2-tcti/tctildr-nodl.c b/src/tss2-tcti/tctildr-nodl.c index 7489b542a..32cd8b3b5 100644 --- a/src/tss2-tcti/tctildr-nodl.c +++ b/src/tss2-tcti/tctildr-nodl.c @@ -137,7 +137,14 @@ tctildr_get_default(TSS2_TCTI_CONTEXT ** tcticontext, void **dlhandle) } *tcticontext = NULL; + if (ARRAY_SIZE(tctis) == 0) { + LOG_ERROR("No default TCTIs configured during compilation"); + return TSS2_TCTI_RC_IO_ERROR; + } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" for (size_t i = 0; i < ARRAY_SIZE(tctis); i++) { +#pragma GCC diagnostic pop LOG_DEBUG("Attempting to connect using standard TCTI: %s", tctis[i].description); rc = tcti_from_init (tctis[i].init, @@ -168,7 +175,14 @@ tctildr_get_tcti (const char *name, return tctildr_get_default (tcti, data); } + if (ARRAY_SIZE(tctis) == 0) { + LOG_ERROR("No default TCTIs configured during compilation"); + return TSS2_TCTI_RC_IO_ERROR; + } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" for (size_t i = 0; i < ARRAY_SIZE(tctis); ++i) { +#pragma GCC diagnostic pop for (size_t j = 0; j < NAME_ARRAY_SIZE; ++j) { if (strcmp (name, tctis[i].names[j])) continue; diff --git a/src/tss2-tcti/tctildr.c b/src/tss2-tcti/tctildr.c index 96b11c70f..3deecc4aa 100644 --- a/src/tss2-tcti/tctildr.c +++ b/src/tss2-tcti/tctildr.c @@ -39,6 +39,9 @@ static char *strndup(const char* s, size_t n) #endif #else #include +#ifndef PATH_MAX +#define PATH_MAX 256 +#endif #endif #include #include diff --git a/src/tss2-tcti/tss2-tcti-mssim.vcxproj b/src/tss2-tcti/tss2-tcti-mssim.vcxproj index d9df3fb32..77e778cee 100644 --- a/src/tss2-tcti/tss2-tcti-mssim.vcxproj +++ b/src/tss2-tcti/tss2-tcti-mssim.vcxproj @@ -120,14 +120,14 @@ - + - + diff --git a/src/tss2-tcti/tss2-tcti-swtpm.vcxproj b/src/tss2-tcti/tss2-tcti-swtpm.vcxproj index fa9e9eeb6..c8812a93f 100644 --- a/src/tss2-tcti/tss2-tcti-swtpm.vcxproj +++ b/src/tss2-tcti/tss2-tcti-swtpm.vcxproj @@ -137,14 +137,14 @@ - + - + diff --git a/src/util/io.c b/src/util-io/io.c similarity index 100% rename from src/util/io.c rename to src/util-io/io.c diff --git a/src/util/io.h b/src/util-io/io.h similarity index 100% rename from src/util/io.h rename to src/util-io/io.h diff --git a/src/util/aux_util.h b/src/util/aux_util.h index fbe1a61af..11a7b30b0 100644 --- a/src/util/aux_util.h +++ b/src/util/aux_util.h @@ -19,7 +19,7 @@ extern "C" { #define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0])) -#define TPM2_ERROR_FORMAT "%s%s (0x%08x)" +#define TPM2_ERROR_FORMAT "%s%s (0x%08"PRIx32")" #define TPM2_ERROR_TEXT(r) "Error", "Code", r #define SIZE_OF_ARY(ary) (sizeof(ary) / sizeof(ary[0])) diff --git a/src/util/tss2_endian.h b/src/util/tss2_endian.h index 0406feab4..ad82a318d 100644 --- a/src/util/tss2_endian.h +++ b/src/util/tss2_endian.h @@ -22,18 +22,15 @@ #define BE_TO_HOST_32(value) be32toh(value) #define BE_TO_HOST_64(value) be64toh(value) -#else /* linux || unix */ - -#if defined(WORDS_BIGENDIAN) +#define HOST_TO_LE_16(value) htole16(value) +#define HOST_TO_LE_32(value) htole32(value) +#define HOST_TO_LE_64(value) htole64(value) +#define LE_TO_HOST_16(value) le16toh(value) +#define LE_TO_HOST_32(value) le32toh(value) +#define LE_TO_HOST_64(value) le64toh(value) -#define HOST_TO_BE_16(value) (value) -#define HOST_TO_BE_32(value) (value) -#define HOST_TO_BE_64(value) (value) -#define BE_TO_HOST_16(value) (value) -#define BE_TO_HOST_32(value) (value) -#define BE_TO_HOST_64(value) (value) +#else /* linux || unix */ -#else #include static inline uint16_t endian_conv_16(uint16_t value) @@ -62,6 +59,24 @@ static inline uint64_t endian_conv_64(uint64_t value) ((value & (0xffULL << 56)) >> 56); } +#if defined(WORDS_BIGENDIAN) + +#define HOST_TO_BE_16(value) (value) +#define HOST_TO_BE_32(value) (value) +#define HOST_TO_BE_64(value) (value) +#define BE_TO_HOST_16(value) (value) +#define BE_TO_HOST_32(value) (value) +#define BE_TO_HOST_64(value) (value) + +#define HOST_TO_LE_16(value) endian_conv_16(value) +#define HOST_TO_LE_32(value) endian_conv_32(value) +#define HOST_TO_LE_64(value) endian_conv_64(value) +#define LE_TO_HOST_16(value) endian_conv_16(value) +#define LE_TO_HOST_32(value) endian_conv_32(value) +#define LE_TO_HOST_64(value) endian_conv_64(value) + +#else /* WORDS_BIGENDIAN */ + #define HOST_TO_BE_16(value) endian_conv_16(value) #define HOST_TO_BE_32(value) endian_conv_32(value) #define HOST_TO_BE_64(value) endian_conv_64(value) @@ -69,6 +84,13 @@ static inline uint64_t endian_conv_64(uint64_t value) #define BE_TO_HOST_32(value) endian_conv_32(value) #define BE_TO_HOST_64(value) endian_conv_64(value) -#endif /* WORDS_BIGENDIAN */ +#define HOST_TO_LE_16(value) (value) +#define HOST_TO_LE_32(value) (value) +#define HOST_TO_LE_64(value) (value) +#define LE_TO_HOST_16(value) (value) +#define LE_TO_HOST_32(value) (value) +#define LE_TO_HOST_64(value) (value) + +#endif /* WORDS_BIGENDIAN else */ #endif /* linux || unix */ #endif /* TSS2_ENDIAN_H */ diff --git a/test/fuzz/tcti-spi-helper-fuzz-test.c b/test/fuzz/tcti-spi-helper-fuzz-test.c index 2535bd882..6e19582c5 100644 --- a/test/fuzz/tcti-spi-helper-fuzz-test.c +++ b/test/fuzz/tcti-spi-helper-fuzz-test.c @@ -6,6 +6,7 @@ #include #include +#include #define LOGMODULE test #include "tss2_sys.h" diff --git a/test/fuzz/tcti/tcti-fuzzing.c b/test/fuzz/tcti/tcti-fuzzing.c index a4cda8453..a5acd18d5 100644 --- a/test/fuzz/tcti/tcti-fuzzing.c +++ b/test/fuzz/tcti/tcti-fuzzing.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "tss2_mu.h" #include "tss2_tcti_fuzzing.h" diff --git a/test/fuzz/tcti/tcti-fuzzing.h b/test/fuzz/tcti/tcti-fuzzing.h index 09a396a18..c4c00265b 100644 --- a/test/fuzz/tcti/tcti-fuzzing.h +++ b/test/fuzz/tcti/tcti-fuzzing.h @@ -10,7 +10,6 @@ #include #include "tss2-tcti/tcti-common.h" -#include "util/io.h" #include "tss2-sys/sysapi_util.h" #define TCTI_FUZZING_MAGIC 0x66757a7a696e6700ULL diff --git a/test/unit/io.c b/test/unit/io.c index bbb452541..fa0e25288 100644 --- a/test/unit/io.c +++ b/test/unit/io.c @@ -18,7 +18,7 @@ #include "tss2_tpm2_types.h" -#include "util/io.h" +#include "util-io/io.h" #define LOGMODULE test #include "util/log.h" diff --git a/test/unit/log.c b/test/unit/log.c index 7106641ce..ad83c1593 100644 --- a/test/unit/log.c +++ b/test/unit/log.c @@ -18,7 +18,7 @@ #include "tss2_tpm2_types.h" -#include "util/io.h" +#include "util-io/io.h" #define LOGMODULE test #include "util/log.h"