ESAPI: Fix includes for non-api-functions

Signed-off-by: Andreas Fuchs <andreas.fuchs@sit.fraunhofer.de>
diff --git a/src/tss2-esys/esys_context.c b/src/tss2-esys/esys_context.c
index e3a4b48..e2b2a4b 100644
--- a/src/tss2-esys/esys_context.c
+++ b/src/tss2-esys/esys_context.c
@@ -24,26 +24,15 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************/
-#include "tss2_mu.h"
-#include "tss2_sys.h"
-#ifndef TSS2_API_VERSION_1_2_1_108
-#error Version missmatch among TSS2 header files !
-#endif                          /* TSS2_API_VERSION_1_2_1_108 */
-#include "tss2_sys.h"
-#include "sysapi_util.h"
-#include <tss2_esys.h>
-#include "esys_types.h"
-#include "esys_crypto.h"
+
+#include <stdlib.h>
+
+#include "tss2_esys.h"
+
 #include "esys_iutil.h"
+#include "esys_tcti_default.h"
 #define LOGMODULE esys
 #include "util/log.h"
-#include "esys_crypto.h"
-#include <inttypes.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "esys_tcti_default.h"
 
 /** Initialize an ESYS_CONTEXT for further use.
  *
diff --git a/src/tss2-esys/esys_crypto.c b/src/tss2-esys/esys_crypto.c
index 756f04a..b8230e9 100644
--- a/src/tss2-esys/esys_crypto.c
+++ b/src/tss2-esys/esys_crypto.c
@@ -24,23 +24,17 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************/
-#include "tss2_mu.h"
-#include "tss2_sys.h"
-#ifndef TSS2_API_VERSION_1_2_1_108
-#error Version missmatch among TSS2 header files !
-#endif                          /* TSS2_API_VERSION_1_2_1_108 */
-
-#include "tss2_sys.h"
-#include "sysapi_util.h"
-#define LOGMODULE sys
-#include "util/log.h"
-
-#include "esys_crypto.h"
-#include "esys_iutil.h"
 
 #include <gcrypt.h>
 
-#include <stdarg.h>
+#include "tss2_esys.h"
+#include "sysapi_util.h"
+
+#include "esys_crypto.h"
+#include "esys_iutil.h"
+#include "esys_mu.h"
+#define LOGMODULE esys
+#include "util/log.h"
 
 /** Context to hold temporary values for iesys_crypto */
 typedef struct _IESYS_CRYPTO_CONTEXT {
diff --git a/src/tss2-esys/esys_crypto.h b/src/tss2-esys/esys_crypto.h
index b21e7d7..0b9a387 100644
--- a/src/tss2-esys/esys_crypto.h
+++ b/src/tss2-esys/esys_crypto.h
@@ -27,18 +27,9 @@
 #ifndef ESYS_CRYPTO_H
 #define ESYS_CRYPTO_H
 
-#include "tss2_common.h"
-#ifndef TSS2_API_VERSION_1_2_1_108
-#error Version missmatch among TSS2 header files !
-#endif  /* TSS2_API_VERSION_1_2_1_108 */
-
-#include <stdint.h>
 #include <stddef.h>
 #include "tss2_tpm2_types.h"
-
-#include <stdarg.h>
-
-#include "util/tpm2b.h"
+#include "tss2-sys/sysapi_util.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/src/tss2-esys/esys_int.h b/src/tss2-esys/esys_int.h
index bc9f849..92fe7ff 100644
--- a/src/tss2-esys/esys_int.h
+++ b/src/tss2-esys/esys_int.h
@@ -27,13 +27,9 @@
 #ifndef ESYS_INT_H
 #define ESYS_INT_H
 
-#include "tss2_mu.h"
-#include "tss2_sys.h"
-#include <stdbool.h>
-#include <tss2_esys.h>
+#include <stdint.h>
 #include "esys_types.h"
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/tss2-esys/esys_iutil.c b/src/tss2-esys/esys_iutil.c
index 3885a4f..2df6942 100644
--- a/src/tss2-esys/esys_iutil.c
+++ b/src/tss2-esys/esys_iutil.c
@@ -24,14 +24,14 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************/
-#include "tss2_mu.h"
-#include "tss2_sys.h"
-#include "esys_iutil.h"
+#include <inttypes.h>
+
 #include "tss2_esys.h"
 #include "esys_mu.h"
+
+#include "esys_iutil.h"
 #include "esys_int.h"
-#include <inttypes.h>
-#define LOGMODULE esys_iutil
+#define LOGMODULE esys
 #include "util/log.h"
 
 /**
diff --git a/src/tss2-esys/esys_iutil.h b/src/tss2-esys/esys_iutil.h
index 05824e9..02fbc04 100644
--- a/src/tss2-esys/esys_iutil.h
+++ b/src/tss2-esys/esys_iutil.h
@@ -27,10 +27,12 @@
 #ifndef ESYS_IUTIL_H
 #define ESYS_IUTIL_H
 
-#include <inttypes.h>
 #include <stdbool.h>
+#include <inttypes.h>
 #include <string.h>
+
 #include "tss2_esys.h"
+
 #include "esys_int.h"
 #include "esys_crypto.h"
 
diff --git a/src/tss2-esys/esys_mu.c b/src/tss2-esys/esys_mu.c
index f5a51b7..458f097 100644
--- a/src/tss2-esys/esys_mu.c
+++ b/src/tss2-esys/esys_mu.c
@@ -24,28 +24,15 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************/
+
+#include <inttypes.h>
+#include <stdlib.h>
 #include <string.h>
 
-#if defined __linux__ || defined __GNU__ || defined __GLIBC__
-#define _DEFAULT_SOURCE 1
-#else
-#define _BSD_SOURCE 1
-#define _SVID_SOURCE 1
-#endif
-
-#include "tss2_mu.h"
-#include "tss2_sys.h"
-#ifndef TSS2_API_VERSION_1_2_1_108
-#error Version missmatch among TSS2 header files !
-#endif /* TSS2_API_VERSION_1_2_1_108 */
-
-#include "sysapi_util.h"
-#include "tss2_mu.h"
-#include <inttypes.h>
-
 #include "tss2_esys.h"
+
 #include "esys_mu.h"
-#define LOGMODULE esys_types
+#define LOGMODULE esys
 #include "util/log.h"
 
 /**
diff --git a/src/tss2-esys/esys_mu.h b/src/tss2-esys/esys_mu.h
index 937ef45..56197b3 100644
--- a/src/tss2-esys/esys_mu.h
+++ b/src/tss2-esys/esys_mu.h
@@ -28,13 +28,9 @@
 #define ESYS_MU_H
 
 #include "tss2_mu.h"
-#include "tss2_sys.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <inttypes.h>
-#include <stdbool.h>
+
 #include "esys_types.h"
-#include "tss2_mu.h"
+
 #ifndef FALSE
 #define FALSE 0
 #endif
diff --git a/src/tss2-esys/esys_tr.c b/src/tss2-esys/esys_tr.c
index 31de95c..bba7219 100644
--- a/src/tss2-esys/esys_tr.c
+++ b/src/tss2-esys/esys_tr.c
@@ -24,26 +24,13 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************/
-#include "tss2_mu.h"
-#include "tss2_sys.h"
-#ifndef TSS2_API_VERSION_1_2_1_108
-#error Version missmatch among TSS2 header files !
-#endif                          /* TSS2_API_VERSION_1_2_1_108 */
-#include "tss2_sys.h"
-#include "tss2_sys.h"
-#include "sysapi_util.h"
-#include "esys_types.h"
-#include "esys_crypto.h"
-#include <tss2_esys.h>
+
+#include "tss2_esys.h"
+#include "esys_mu.h"
+
+#include "esys_iutil.h"
 #define LOGMODULE esys
 #include "util/log.h"
-#include "esys_iutil.h"
-#include "esys_mu.h"
-#include <inttypes.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 /** Serialization of an ESYS_TR into a byte buffer.
  *
diff --git a/src/tss2-esys/esys_types.h b/src/tss2-esys/esys_types.h
index 89be11d..a196f1e 100644
--- a/src/tss2-esys/esys_types.h
+++ b/src/tss2-esys/esys_types.h
@@ -25,8 +25,10 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************/
 
-#ifndef IESYS_TYPES_H
-#define IESYS_TYPES_H
+#ifndef ESYS_TYPES_H
+#define ESYS_TYPES_H
+
+#include "tss2_tpm2_types.h"
 
 #define ESYS_MAX_SIZE_METADATA 3072
 
@@ -152,5 +154,5 @@
     IESYS_METADATA                         esysMetadata;    /**< Meta data of the ESY_TR object */
 } IESYS_CONTEXT_DATA;
 /* @} */
-#endif /* IESYS_TYPES_H */
+#endif /* ESYS_TYPES_H */
 /* @} */
diff --git a/test/integration/esys-get-random.int.c b/test/integration/esys-get-random.int.c
index 8a5688f..4a4d1a8 100644
--- a/test/integration/esys-get-random.int.c
+++ b/test/integration/esys-get-random.int.c
@@ -25,6 +25,8 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************/
 
+#include <stdlib.h>
+
 #include "tss2_esys.h"
 
 #include "esys_iutil.h"
diff --git a/test/integration/main-esapi.c b/test/integration/main-esapi.c
index 2557e72..39ffabf 100644
--- a/test/integration/main-esapi.c
+++ b/test/integration/main-esapi.c
@@ -1,15 +1,42 @@
-#include <stdbool.h>
+/*******************************************************************************
+ * Copyright 2017, Fraunhofer SIT sponsored by Infineon Technologies AG
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *******************************************************************************/
 
-#define LOGMODULE test
-#include "util/log.h"
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tss2_esys.h"
+
 #include "test-esapi.h"
 #include "test-options.h"
 #include "context-util.h"
-#include "tss2_esys.h"
-#include "esys_types.h"
-#include "esys_iutil.h"
-#include "tss2_tcti.h"
-#include "tss2-tcti/tcti.h"
+#include "tss2-esys/esys_int.h"
+#define LOGMODULE test
+#include "util/log.h"
 
 /** Define a proxy tcti that returns yielded on every second invocation
  * thus the corresponding handling code in ESAPI can be tested.
@@ -130,7 +157,7 @@
     /* Init TCTI context */
     memset(tcti_proxy, 0, sizeof(*tcti_proxy));
     TSS2_TCTI_MAGIC (tctiContext) = TCTI_PROXY_MAGIC;
-    TSS2_TCTI_VERSION (tctiContext) = TCTI_VERSION;
+    TSS2_TCTI_VERSION (tctiContext) = TCTI_PROXY_VERSION;
     TSS2_TCTI_TRANSMIT (tctiContext) = tcti_proxy_transmit;
     TSS2_TCTI_RECEIVE (tctiContext) = tcti_proxy_receive;
     TSS2_TCTI_FINALIZE (tctiContext) = tcti_proxy_finalize;
diff --git a/test/unit/esys-resubmissions.c b/test/unit/esys-resubmissions.c
index de1d3b1..cb8a0bf 100644
--- a/test/unit/esys-resubmissions.c
+++ b/test/unit/esys-resubmissions.c
@@ -26,6 +26,7 @@
  ******************************************************************************/
 
 #include <stdarg.h>
+#include <stdlib.h>
 #include <inttypes.h>
 #include <string.h>