Merge remote-tracking branch 'public/pr/2932' into baremetal
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 746b38a..39808f9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -185,7 +185,10 @@
 
 add_subdirectory(library)
 add_subdirectory(include)
-add_subdirectory(tinycrypt)
+
+if(USE_TINYCRYPT)
+    add_subdirectory(tinycrypt)
+endif()
 
 if(ENABLE_PROGRAMS)
     add_subdirectory(programs)
diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h
index 0d1d9ec..df8f1df 100644
--- a/include/tinycrypt/ecc.h
+++ b/include/tinycrypt/ecc.h
@@ -73,7 +73,6 @@
  *
  */
 
-#if defined(MBEDTLS_USE_TINYCRYPT)
 #ifndef __TC_UECC_H__
 #define __TC_UECC_H__
 
@@ -535,4 +534,3 @@
 #endif
 
 #endif /* __TC_UECC_H__ */
-#endif /* MBEDTLS_USE_TINYCRYPT */
diff --git a/include/tinycrypt/ecc_dh.h b/include/tinycrypt/ecc_dh.h
index a2edb01..d87393d 100644
--- a/include/tinycrypt/ecc_dh.h
+++ b/include/tinycrypt/ecc_dh.h
@@ -71,7 +71,6 @@
  *  Security: The curve NIST p-256 provides approximately 128 bits of security.
  */
 
-#if defined(MBEDTLS_USE_TINYCRYPT)
 #ifndef __TC_ECC_DH_H__
 #define __TC_ECC_DH_H__
 
@@ -135,4 +134,3 @@
 #endif
 
 #endif /* __TC_ECC_DH_H__ */
-#endif /* MBEDTLS_USE_TINYCRYPT */
diff --git a/include/tinycrypt/ecc_dsa.h b/include/tinycrypt/ecc_dsa.h
index 55b9d43..f744319 100644
--- a/include/tinycrypt/ecc_dsa.h
+++ b/include/tinycrypt/ecc_dsa.h
@@ -80,7 +80,6 @@
  *          the signer's public key and the signature values (r and s).
  */
 
-#if defined(MBEDTLS_USE_TINYCRYPT)
 #ifndef __TC_ECC_DSA_H__
 #define __TC_ECC_DSA_H__
 
@@ -143,4 +142,3 @@
 #endif
 
 #endif /* __TC_ECC_DSA_H__ */
-#endif /* MBEDTLS_USE_TINYCRYPT */
diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
index 89f7275..0156856 100644
--- a/library/CMakeLists.txt
+++ b/library/CMakeLists.txt
@@ -1,4 +1,5 @@
 option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
+option(USE_TINYCRYPT "Include TinyCrypt." ON)
 option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF)
 option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF)
 
@@ -123,7 +124,9 @@
     set(libs ${libs} pthread)
 endif()
 
-set(libs ${libs} tinycrypt)
+if(USE_TINYCRYPT)
+    set(libs ${libs} tinycrypt)
+endif()
 
 if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
     message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
diff --git a/library/Makefile b/library/Makefile
index 4154c6a..96a9d60 100644
--- a/library/Makefile
+++ b/library/Makefile
@@ -99,8 +99,7 @@
 		ripemd160.o	rsa_internal.o	rsa.o  		\
 		sha1.o		sha256.o	sha512.o	\
 		threading.o	timing.o	version.o	\
-		version_features.o		xtea.o		\
-		ecc.o		ecc_dh.o	ecc_dsa.o
+		version_features.o		xtea.o
 
 OBJS_X509=	certs.o		pkcs11.o	x509.o
 
@@ -110,6 +109,17 @@
 		ssl_srv.o	ssl_ticket.o		\
 		ssl_tls.o
 
+# Default to always build TinyCrypt
+ifndef TINYCRYPT_BUILD
+TINYCRYPT_BUILD=1
+endif
+
+ifeq ($(TINYCRYPT_BUILD),1)
+# Add TinyCrypt to the targets and Makefile path
+VPATH = ../tinycrypt
+OBJS_CRYPTO += ecc.o           ecc_dh.o        ecc_dsa.o
+endif
+
 .SILENT:
 
 .PHONY: all static shared clean
diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh
index 02f96a9..42ef32d 100755
--- a/tests/scripts/all.sh
+++ b/tests/scripts/all.sh
@@ -1491,7 +1491,7 @@
     msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
     scripts/config.pl baremetal
     scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
-    make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
+    make TINYCRYPT_BUILD=0 CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
     echo "Checking that software 64-bit multiplication is not required"
     if_build_succeeded not grep __aeabi_lmul library/*.o
 }
diff --git a/tests/scripts/list-symbols.sh b/tests/scripts/list-symbols.sh
index 930722c..12b3281 100755
--- a/tests/scripts/list-symbols.sh
+++ b/tests/scripts/list-symbols.sh
@@ -16,7 +16,7 @@
 scripts/config.pl full
 make clean
 make_ret=
-CFLAGS=-fno-asynchronous-unwind-tables make lib \
+CFLAGS=-fno-asynchronous-unwind-tables TINYCRYPT_BUILD=0 make lib \
       >list-symbols.make.log 2>&1 ||
   {
     make_ret=$?
diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c
index 92906fd..38b11d9 100644
--- a/tinycrypt/ecc.c
+++ b/tinycrypt/ecc.c
@@ -63,7 +63,6 @@
 #include MBEDTLS_CONFIG_FILE
 #endif
 
-#if defined(MBEDTLS_USE_TINYCRYPT)
 #include <tinycrypt/ecc.h>
 #include "mbedtls/platform_util.h"
 #include <string.h>
@@ -1114,7 +1113,4 @@
 	curve->num_bytes, curve->num_bytes, _public + curve->num_words);
 	return 1;
 }
-#else
-typedef int mbedtls_dummy_tinycrypt_def;
-#endif /* MBEDTLS_USE_TINYCRYPT */
 
diff --git a/tinycrypt/ecc_dh.c b/tinycrypt/ecc_dh.c
index f9c0a5e..3ab7b15 100644
--- a/tinycrypt/ecc_dh.c
+++ b/tinycrypt/ecc_dh.c
@@ -66,7 +66,6 @@
 #include MBEDTLS_CONFIG_FILE
 #endif
 
-#if defined(MBEDTLS_USE_TINYCRYPT)
 #include <tinycrypt/ecc.h>
 #include <tinycrypt/ecc_dh.h>
 #include <string.h>
@@ -188,6 +187,3 @@
 
 	return r;
 }
-#else
-typedef int mbedtls_dummy_tinycrypt_def;
-#endif /* MBEDTLS_USE_TINYCRYPT */
diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c
index 6c171c3..67b33a4 100644
--- a/tinycrypt/ecc_dsa.c
+++ b/tinycrypt/ecc_dsa.c
@@ -64,7 +64,6 @@
 #include MBEDTLS_CONFIG_FILE
 #endif
 
-#if defined(MBEDTLS_USE_TINYCRYPT)
 #include <tinycrypt/ecc.h>
 #include <tinycrypt/ecc_dsa.h>
 #include "mbedtls/platform_util.h"
@@ -316,6 +315,3 @@
 
 	return UECC_FAILURE;
 }
-#else
-typedef int mbedtls_dummy_tinycrypt_def;
-#endif /* MBEDTLS_USE_TINYCRYPT */