diff --git a/AutoConf.cmake b/AutoConf.cmake new file mode 100644 index 00000000..4c4ac085 --- /dev/null +++ b/AutoConf.cmake @@ -0,0 +1,49 @@ +include(CheckIncludeFile) +include(CheckFunctionExists) +include(TestBigEndian) +include(CheckCSourceCompiles) +include(CheckStructHasMember) + +check_include_file(assert.h HAVE_ASSERT_H) +check_include_file(arpa/inet.h HAVE_ARPA_INET_H) +check_include_file(fcntl.h HAVE_FCNTL_H) +check_include_file(inttypes.h HAVE_INTTYPES_H) +check_include_file(memory.h HAVE_MEMORY_H) +check_include_file(netdb.h HAVE_NETDB_H) +check_include_file(netinet/in.h HAVE_NETINET_IN_H) +check_include_file(stddef.h HAVE_STDDEF_H) +check_include_file(stdint.h HAVE_STDINT_H) +check_include_file(stdlib.h HAVE_STDLIB_H) +check_include_file(string.h HAVE_STRING_H) +check_include_file(strings.h HAVE_STRINGS_H) +check_include_file(time.h HAVE_TIME_H) +check_include_file(sys/param.h HAVE_SYS_PARAM_H) +check_include_file(sys/socket.h HAVE_SYS_SOCKET_H) +check_include_file(sys/stat.h HAVE_SYS_STAT_H) +check_include_file(sys/types.h HAVE_SYS_TYPES_H) +check_include_file(sys/time.h HAVE_SYS_TIME_H) +check_include_file(unistd.h HAVE_UNISTD_H) +check_include_file(float.h HAVE_FLOAT_H) +check_include_file(dlfcn.h HAVE_DLFCN_H) + +check_function_exists (memset HAVE_MEMSET) +check_function_exists (select HAVE_SELECT) +check_function_exists (socket HAVE_SOCKET) +check_function_exists (strdup HAVE_STRDUP) +check_function_exists (strerror HAVE_STRERROR) +check_function_exists (strnlen HAVE_STRNLEN) +check_function_exists (fls HAVE_FLS) +check_function_exists (vprintf HAVE_VPRINTF) + +if( ${HAVE_STRING_H} AND ${HAVE_STRINGS_H} AND + ${HAVE_FLOAT_H} AND ${HAVE_STDLIB_H} AND + ${HAVE_STDDEF_H} AND ${HAVE_STDINT_H} AND + ${HAVE_INTTYPES_H} AND ${HAVE_DLFCN_H} ) + set( STDC_HEADERS 1) +endif() + +check_struct_has_member (struct sockaddr_in6.sin6_len netinet/in.h HAVE_SOCKADDR_IN6_SIN6_LEN) +TEST_BIG_ENDIAN(IS_BIG_ENDIAN) +if(IS_BIG_ENDIAN) + set(WORDS_BIGENDIAN 1) +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..76a4a4e9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.5) + +include (AutoConf.cmake) + +option(BUILD_SHARED_LIBS "Link using shared libs" OFF) +option(make_tests "Make test programs" OFF) + +if(NOT PLATFORM) + set(PLATFORM "posix" CACHE STRING "Choose platform." FORCE) + set_property(CACHE PLATFORM PROPERTY STRINGS "contiki" "espidf" "posix" "riot") +endif() + +set(PACKAGE_NAME "tinydtls") +set(PACKAGE_VERSION "0.8.6" ) + +option(DTLS_ECC "disable support for TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" ON ) +option(DTLS_PSK "disable support for TLS_PSK_WITH_AES_128_CCM_8" ON) + +configure_file(dtls_config.h.cmake.in dtls_config.h ) + +file(GLOB SOURCE "*.c" "ecc/ecc.c" "aes/*.c" "sha2/sha2.c" "platform/dtls_prng_${PLATFORM}.c") + +add_library(tinydtls ${SOURCE}) +target_compile_options(tinydtls PRIVATE -Wall -pedantic -std=c99 -DSHA2_USE_INTTYPES_H -fPIC -pedantic -Wall -Wextra -Wformat-security -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wunused -DDTLSv12 -DWITH_SHA256 -DDTLS_CHECK_CONTENTTYPE) +target_compile_options(tinydtls PUBLIC -DDTLSv12 -DWITH_SHA256) +target_include_directories(tinydtls PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +if( ${make_tests} ) + add_subdirectory(tests) +endif() + + +if(${BUILD_SHARED_LIBS}) + install(TARGETS tinydtls DESTINATION /usr/local/lib ) +endif() \ No newline at end of file diff --git a/dtls_config.h.cmake.in b/dtls_config.h.cmake.in new file mode 100644 index 00000000..eed7813d --- /dev/null +++ b/dtls_config.h.cmake.in @@ -0,0 +1,129 @@ +/* dtls_config.h.cmake.in. Generated from cmake */ + +/* Define if building universal (internal helper macro) */ +#cmakedefine AC_APPLE_UNIVERSAL_BUILD + +/* Define to 1 if building with ECC support. */ +#cmakedefine DTLS_ECC 1 + +/* Define to 1 if building with PSK support */ +#cmakedefine DTLS_PSK 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ASSERT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `fls' function. */ +#cmakedefine HAVE_FLS 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#cmakedefine HAVE_MEMSET 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the `select' function. */ +#cmakedefine HAVE_SELECT 1 + +/* Define to 1 if struct sockaddr_in6 has a member sin6_len. */ +#cmakedefine HAVE_SOCKADDR_IN6_SIN6_LEN 1 + +/* Define to 1 if you have the `socket' function. */ +#cmakedefine HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strdup' function. */ +#cmakedefine HAVE_STRDUP 1 + +/* Define to 1 if you have the `strerror' function. */ +#cmakedefine HAVE_STRERROR 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H 1 + +/* Define to 1 if you have the `strnlen' function. */ +#cmakedefine HAVE_STRNLEN 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `vprintf' function. */ +#cmakedefine HAVE_VPRINTF 1 + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "${PACKAGE_NAME}" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "${PACKAGE_NAME}" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "${PACKAGE_VERSION}" + +/* Define to 1 if you have the ANSI C header files. */ +#cmakedefine STDC_HEADERS 1 + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#cmakedefine WORDS_BIGENDIAN 1 + +/* TODO + Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. +#ifndef __cplusplus +#undef inline +#endif + + Define to `unsigned int' if does not define. +#undef size_t */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..12073f2f --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.5) + +add_executable(dtls-server dtls-server.c) +target_link_libraries(dtls-server LINK_PUBLIC tinydtls) +target_compile_options(dtls-server PUBLIC -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) + +add_executable(ccm-test ccm-test.c) +target_link_libraries(ccm-test LINK_PUBLIC tinydtls) +target_compile_options(ccm-test PUBLIC -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) + +add_executable(prf-test prf-test.c) +target_link_libraries(prf-test LINK_PUBLIC tinydtls) +target_compile_options(prf-test PUBLIC -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) + +add_executable(dtls-client dtls-client.c) +target_link_libraries(dtls-client LINK_PUBLIC tinydtls) +target_compile_options(dtls-client PUBLIC -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) +