]> granicus.if.org Git - esp-idf/commitdiff
mbedtls: import mbedtls project w/o modification
authorRenz Christian Bagaporo <renz@espressif.com>
Sun, 11 Nov 2018 07:44:54 +0000 (15:44 +0800)
committerRenz Christian Bagaporo <renz@espressif.com>
Tue, 27 Nov 2018 05:59:26 +0000 (13:59 +0800)
components/mbedtls/CMakeLists.txt
components/mbedtls/mbedtls.c [new file with mode: 0644]
components/mbedtls/port/esp_bignum.c
components/mbedtls/port/esp_hardware.c
components/mbedtls/port/esp_mem.c
components/mbedtls/port/mbedtls_debug.c
components/mbedtls/port/net_sockets.c
components/mbedtls/test/CMakeLists.txt
components/nvs_flash/test_nvs_host/Makefile

index f9964f2e75de6c36d6f1c991671020156fa435ac..c99985d1c875409f44b133f5ba11442a09a846b0 100644 (file)
-set(COMPONENT_ADD_INCLUDEDIRS port/include mbedtls/include)
-set(COMPONENT_SRCS "mbedtls/library/aes.c"
-                   "mbedtls/library/aesni.c"
-                   "mbedtls/library/arc4.c"
-                   "mbedtls/library/aria.c"
-                   "mbedtls/library/asn1parse.c"
-                   "mbedtls/library/asn1write.c"
-                   "mbedtls/library/base64.c"
-                   "mbedtls/library/bignum.c"
-                   "mbedtls/library/blowfish.c"
-                   "mbedtls/library/camellia.c"
-                   "mbedtls/library/ccm.c"
-                   "mbedtls/library/certs.c"
-                   "mbedtls/library/chacha20.c"
-                   "mbedtls/library/chachapoly.c"
-                   "mbedtls/library/cipher.c"
-                   "mbedtls/library/cipher_wrap.c"
-                   "mbedtls/library/cmac.c"
-                   "mbedtls/library/ctr_drbg.c"
-                   "mbedtls/library/debug.c"
-                   "mbedtls/library/des.c"
-                   "mbedtls/library/dhm.c"
-                   "mbedtls/library/ecdh.c"
-                   "mbedtls/library/ecdsa.c"
-                   "mbedtls/library/ecjpake.c"
-                   "mbedtls/library/ecp.c"
-                   "mbedtls/library/ecp_curves.c"
-                   "mbedtls/library/entropy.c"
-                   "mbedtls/library/entropy_poll.c"
-                   "mbedtls/library/error.c"
-                   "mbedtls/library/gcm.c"
-                   "mbedtls/library/havege.c"
-                   "mbedtls/library/hkdf.c"
-                   "mbedtls/library/hmac_drbg.c"
-                   "mbedtls/library/md.c"
-                   "mbedtls/library/md2.c"
-                   "mbedtls/library/md4.c"
-                   "mbedtls/library/md5.c"
-                   "mbedtls/library/md_wrap.c"
-                   "mbedtls/library/memory_buffer_alloc.c"
-                   "mbedtls/library/net_sockets.c"
-                   "mbedtls/library/nist_kw.c"
-                   "mbedtls/library/oid.c"
-                   "mbedtls/library/padlock.c"
-                   "mbedtls/library/pem.c"
-                   "mbedtls/library/pk.c"
-                   "mbedtls/library/pk_wrap.c"
-                   "mbedtls/library/pkcs11.c"
-                   "mbedtls/library/pkcs12.c"
-                   "mbedtls/library/pkcs5.c"
-                   "mbedtls/library/pkparse.c"
-                   "mbedtls/library/pkwrite.c"
-                   "mbedtls/library/platform.c"
-                   "mbedtls/library/platform_util.c"
-                   "mbedtls/library/poly1305.c"
-                   "mbedtls/library/ripemd160.c"
-                   "mbedtls/library/rsa.c"
-                   "mbedtls/library/rsa_internal.c"
-                   "mbedtls/library/sha1.c"
-                   "mbedtls/library/sha256.c"
-                   "mbedtls/library/sha512.c"
-                   "mbedtls/library/ssl_cache.c"
-                   "mbedtls/library/ssl_ciphersuites.c"
-                   "mbedtls/library/ssl_cli.c"
-                   "mbedtls/library/ssl_cookie.c"
-                   "mbedtls/library/ssl_srv.c"
-                   "mbedtls/library/ssl_ticket.c"
-                   "mbedtls/library/ssl_tls.c"
-                   "mbedtls/library/threading.c"
-                   "mbedtls/library/timing.c"
-                   "mbedtls/library/version.c"
-                   "mbedtls/library/version_features.c"
-                   "mbedtls/library/x509.c"
-                   "mbedtls/library/x509_create.c"
-                   "mbedtls/library/x509_crl.c"
-                   "mbedtls/library/x509_crt.c"
-                   "mbedtls/library/x509_csr.c"
-                   "mbedtls/library/x509write_crt.c"
-                   "mbedtls/library/x509write_csr.c"
-                   "mbedtls/library/xtea.c"
-                   "port/esp_bignum.c"
-                   "port/esp_hardware.c"
-                   "port/esp_mem.c"
-                   "port/esp_sha1.c"
-                   "port/esp_sha256.c"
-                   "port/esp_sha512.c"
-                   "port/mbedtls_debug.c"
-                   "port/net_sockets.c")
-
+set(COMPONENT_ADD_INCLUDEDIRS "port/include" "mbedtls/include")
+set(COMPONENT_SRCS "mbedtls.c")
 set(COMPONENT_REQUIRES lwip)
 
 register_component()
 
-target_compile_definitions(${COMPONENT_TARGET} PUBLIC
-    -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h"
-)
+# Only build mbedtls libraries
+set(ENABLE_TESTING CACHE BOOL OFF)
+set(ENABLE_PROGRAMS CACHE BOOL OFF)
+
+# Use same policy between IDF and mbedtls build
+function(project)
+    set(_args ARGV)
+    _project(${${_args}})
+    cmake_policy(SET CMP0022 NEW)
+endfunction()
+
+# Needed to for include_next includes to work from within mbedtls
+include_directories("${COMPONENT_PATH}/port/include")
+
+# Import mbedtls library targets
+add_subdirectory(mbedtls)
+
+set(mbedtls_targets mbedtls mbedcrypto mbedx509)
+
+# Add port files to mbedtls targets
+target_sources(mbedtls PRIVATE "${COMPONENT_PATH}/port/esp_bignum.c"
+                                "${COMPONENT_PATH}/port/esp_hardware.c"
+                                "${COMPONENT_PATH}/port/esp_mem.c"
+                                "${COMPONENT_PATH}/port/esp_sha1.c"
+                                "${COMPONENT_PATH}/port/esp_sha256.c"
+                                "${COMPONENT_PATH}/port/esp_sha512.c"
+                                "${COMPONENT_PATH}/port/mbedtls_debug.c"
+                                "${COMPONENT_PATH}/port/net_sockets.c")
+
+foreach(target ${mbedtls_targets})
+    # Propagate compile options to mbedtls library targets
+    target_include_directories(${target} PRIVATE "${IDF_INCLUDE_DIRECTORIES}")
+    target_compile_options(${target} PRIVATE "${IDF_COMPILE_OPTIONS};${IDF_C_COMPILE_OPTIONS}")
+    target_compile_definitions(${target} PRIVATE "${IDF_COMPILE_DEFINITIONS}")
+    target_compile_definitions(${target} PUBLIC -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h")
+
+    # The mbedtls targets also depends on core components
+    foreach(common ${IDF_COMPONENT_REQUIRES_COMMON})
+        component_get_target(common_target ${common})
+        set_property(TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${common_target})
+        set_property(TARGET ${target} APPEND PROPERTY LINK_LIBRARIES ${common_target})
+    endforeach()
+endforeach()
+
+# Link mbedtls libraries to component library
+target_link_libraries(${COMPONENT_TARGET} ${mbedtls_targets})
 
 # Catch usage of deprecated mbedTLS functions when building tests
 if(mbedtls_test IN_LIST BUILD_TEST_COMPONENTS)
     add_definitions(-DMBEDTLS_DEPRECATED_WARNING)
-endif()
+endif()
\ No newline at end of file
diff --git a/components/mbedtls/mbedtls.c b/components/mbedtls/mbedtls.c
new file mode 100644 (file)
index 0000000..fab17ac
--- /dev/null
@@ -0,0 +1 @@
+// Empty file
index 4dac2b5102aa8f6b3902bc8683a18d7b3ced8590..ebcd208cc2605054cdd009e0f9fcb1726c299b98 100644 (file)
@@ -27,7 +27,6 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <sys/param.h>
-#include "mbedtls/bignum.h"
 #include "rom/bigint.h"
 #include "soc/hwcrypto_reg.h"
 #include "esp_system.h"
@@ -36,6 +35,8 @@
 #include "esp_intr_alloc.h"
 #include "esp_attr.h"
 
+#include <mbedtls/bignum.h>
+
 #include "soc/dport_reg.h"
 
 #include "freertos/FreeRTOS.h"
index 09ededb186e39a0c450cd61dfcaa745ad4b38a93..a919ca34030fbecd749d4b731986d5605b16fe0b 100644 (file)
@@ -9,6 +9,8 @@
 #include <stdio.h>
 #include <esp_system.h>
 
+#include "mbedtls/entropy_poll.h"
+
 #ifndef MBEDTLS_ENTROPY_HARDWARE_ALT
 #error "MBEDTLS_ENTROPY_HARDWARE_ALT should always be set in ESP-IDF"
 #endif
index 198c0c6cc0e25bc651e4c4cb183adf5f42e206a2..c7b8e706f9870b26137d851c07cab5c8b7d0d073 100644 (file)
@@ -15,6 +15,7 @@
 #include <esp_attr.h>
 #include <esp_heap_caps.h>
 #include <sdkconfig.h>
+#include "esp_mem.h"
 
 #ifndef CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC
 
index 316a76a990a6fe8ed41fa67fe57163032c6c2861..f7b5541453e66316e21a8a6d909c1b2fcf41de98 100644 (file)
@@ -20,6 +20,7 @@
 #include "mbedtls/ssl.h"
 #include "mbedtls/esp_debug.h"
 
+#ifdef CONFIG_MBEDTLS_DEBUG
 static const char *TAG = "mbedtls";
 
 static void mbedtls_esp_debug(void *ctx, int level,
@@ -28,9 +29,9 @@ static void mbedtls_esp_debug(void *ctx, int level,
 
 void mbedtls_esp_enable_debug_log(mbedtls_ssl_config *conf, int threshold)
 {
+    esp_log_level_t level = ESP_LOG_NONE;
     mbedtls_debug_set_threshold(threshold);
     mbedtls_ssl_conf_dbg(conf, mbedtls_esp_debug, NULL);
-    esp_log_level_t level = ESP_LOG_NONE;
     switch(threshold) {
     case 1:
         level = ESP_LOG_WARN;
@@ -53,6 +54,7 @@ void mbedtls_esp_disable_debug_log(mbedtls_ssl_config *conf)
     mbedtls_ssl_conf_dbg(conf, NULL, NULL);
 }
 
+
 /* Default mbedtls debug function that translates mbedTLS debug output
    to ESP_LOGx debug output.
 */
@@ -89,3 +91,4 @@ static void mbedtls_esp_debug(void *ctx, int level,
         break;
     }
 }
+#endif
\ No newline at end of file
index 1a182d8f487994fd82e9422fb11a657576331e3a..6d8a1cc550063917cbc7919a58c8904cbd54b451 100644 (file)
@@ -131,6 +131,10 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
 {
     int ret;
     struct addrinfo hints, *addr_list, *cur;
+    struct sockaddr_in *serv_addr = NULL;
+#if SO_REUSE
+    int n = 1;
+#endif
 
     if ( ( ret = net_prepare() ) != 0 ) {
         return ( ret );
@@ -157,7 +161,6 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
 
         /*SO_REUSEADDR option dafault is disable in source code(lwip)*/
 #if SO_REUSE
-        int n = 1;
         if ( setsockopt( fd, SOL_SOCKET, SO_REUSEADDR,
                          (const char *) &n, sizeof( n ) ) != 0 ) {
             close( fd );
@@ -166,7 +169,6 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
         }
 #endif
         /*bind interface dafault don't process the addr is 0xffffffff for TCP Protocol*/
-        struct sockaddr_in *serv_addr = NULL;
         serv_addr = (struct sockaddr_in *)cur->ai_addr;
         serv_addr->sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
         if ( bind( fd, (struct sockaddr *)serv_addr, cur->ai_addrlen ) != 0 ) {
index 0c2125acc5a2ebc4ace2c1c7d716dfba23e70361..e1aad74fac8b476221b6f294201705b2e4c83203 100644 (file)
@@ -3,4 +3,4 @@ set(COMPONENT_ADD_INCLUDEDIRS ".")
 
 set(COMPONENT_REQUIRES unity test_utils mbedtls)
 
-register_component()
\ No newline at end of file
+register_component()
index 73aec3253f9bc7740db5d0597df761f49970af3d..b125aaffe1444c1c3c9dce160ea23fbfe3c8cf45 100644 (file)
@@ -21,7 +21,7 @@ SOURCE_FILES = \
        crc.cpp \
        main.cpp
 
-CPPFLAGS += -I../include -I../src -I./ -I../../esp32/include -I ../../esp_mbedtls/mbedtls/include -I ../../spi_flash/include -I ../../../tools/catch -fprofile-arcs -ftest-coverage -DCONFIG_NVS_ENCRYPTION
+CPPFLAGS += -I../include -I../src -I./ -I../../esp32/include -I ../../mbedtls/mbedtls/include -I ../../spi_flash/include -I ../../../tools/catch -fprofile-arcs -ftest-coverage -DCONFIG_NVS_ENCRYPTION
 CFLAGS += -fprofile-arcs -ftest-coverage
 CXXFLAGS += -std=c++11 -Wall -Werror
 LDFLAGS += -lstdc++ -Wall -fprofile-arcs -ftest-coverage
@@ -33,8 +33,8 @@ COVERAGE_FILES = $(OBJ_FILES:.o=.gc*)
 $(OBJ_FILES): %.o: %.cpp
 
 $(TEST_PROGRAM): $(OBJ_FILES)
-       $(MAKE) -C ../../esp_mbedtls/mbedtls/ lib
-       g++ $(LDFLAGS) -o $(TEST_PROGRAM) $(OBJ_FILES) ../../esp_mbedtls/mbedtls/library/libmbedcrypto.a
+       $(MAKE) -C ../../mbedtls/mbedtls/ lib
+       g++ $(LDFLAGS) -o $(TEST_PROGRAM) $(OBJ_FILES) ../../mbedtls/mbedtls/library/libmbedcrypto.a
 
 $(OUTPUT_DIR):
        mkdir -p $(OUTPUT_DIR)
@@ -56,7 +56,7 @@ coverage_report: coverage.info
        @echo "Coverage report is in coverage_report/index.html"
 
 clean:
-       $(MAKE) -C ../../esp_mbedtls/mbedtls/ clean
+       $(MAKE) -C ../../mbedtls/mbedtls/ clean
        rm -f $(OBJ_FILES) $(TEST_PROGRAM)
        rm -f $(COVERAGE_FILES) *.gcov
        rm -rf coverage_report/