-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mbedtls support #512
Mbedtls support #512
Changes from 4 commits
27a2b0d
268eb50
1e8aaa7
53e0746
5db3eed
1c9b6bc
c134959
ad783d3
d7243eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ project(libsrtp2 LANGUAGES C) | |
|
||
set(PACKAGE_VERSION 2.4.0) | ||
set(PACKAGE_STRING "${CMAKE_PROJECT_NAME} ${PACKAGE_VERSION}") | ||
|
||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_MODULE_PATH}") | ||
include(TestBigEndian) | ||
include(CheckIncludeFile) | ||
include(CheckFunctionExists) | ||
|
@@ -54,15 +54,27 @@ set(ENABLE_DEBUG_LOGGING OFF CACHE BOOL "Enable debug logging in all modules") | |
set(ERR_REPORTING_STDOUT OFF CACHE BOOL "Enable logging to stdout") | ||
set(ERR_REPORTING_FILE "" CACHE FILEPATH "Use file for logging") | ||
set(ENABLE_OPENSSL OFF CACHE BOOL "Enable OpenSSL crypto engine") | ||
set(ENABLE_MBEDTLS OFF CACHE BOOL "Enable MbedTLS crypto engine") | ||
set(TEST_APPS ON CACHE BOOL "Build test applications") | ||
option(BUILD_SHARED_LIBS "Build shared library" OFF) | ||
|
||
if(ENABLE_OPENSSL AND ENABLE_MBEDTLS) | ||
message(FATAL_ERROR "ssl conflict. can not enable openssl and mbedtls simultaneously.") | ||
endif() | ||
|
||
if(ENABLE_OPENSSL) | ||
find_package(OpenSSL REQUIRED) | ||
include_directories(${OPENSSL_INCLUDE_DIR}) | ||
set(OPENSSL ${ENABLE_OPENSSL} CACHE BOOL INTERNAL) | ||
set(GCM ${ENABLE_OPENSSL} CACHE BOOL INTERNAL) | ||
endif() | ||
|
||
if(ENABLE_MBEDTLS) | ||
find_package(MbedTLS REQUIRED) | ||
include_directories(${MBEDTLS_INCLUDE_DIRS}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same reason as the above stuff, FindMbedTLS.cmake. |
||
set(MBEDTLS ${ENABLE_MBEDTLS} CACHE BOOL INTERNAL) | ||
set(GCM ${ENABLE_MBEDTLS} CACHE BOOL INTERNAL) | ||
endif() | ||
set(OPENSSL ${ENABLE_OPENSSL} CACHE BOOL INTERNAL) | ||
set(GCM ${ENABLE_OPENSSL} CACHE BOOL INTERNAL) | ||
|
||
set(CONFIG_FILE_DIR ${CMAKE_CURRENT_BINARY_DIR}) | ||
include_directories(${CONFIG_FILE_DIR}) | ||
|
@@ -85,6 +97,11 @@ if(ENABLE_OPENSSL) | |
crypto/cipher/aes_icm_ossl.c | ||
crypto/cipher/aes_gcm_ossl.c | ||
) | ||
elseif(ENABLE_MBEDTLS) | ||
list(APPEND CIPHERS_SOURCES_C | ||
crypto/cipher/aes_icm_mbedtls.c | ||
crypto/cipher/aes_gcm_mbedtls.c | ||
) | ||
else() | ||
list(APPEND CIPHERS_SOURCES_C | ||
crypto/cipher/aes.c | ||
|
@@ -101,6 +118,10 @@ if(ENABLE_OPENSSL) | |
list(APPEND HASHES_SOURCES_C | ||
crypto/hash/hmac_ossl.c | ||
) | ||
elseif(ENABLE_MBEDTLS) | ||
list(APPEND HASHES_SOURCES_C | ||
crypto/hash/hmac_mbedtls.c | ||
) | ||
else() | ||
list(APPEND HASHES_SOURCES_C | ||
crypto/hash/hmac.c | ||
|
@@ -182,6 +203,9 @@ target_include_directories(srtp2 PUBLIC crypto/include include) | |
if(ENABLE_OPENSSL) | ||
target_link_libraries(srtp2 OpenSSL::Crypto) | ||
endif() | ||
if(ENABLE_MBEDTLS) | ||
target_link_libraries(srtp2 ${MBEDTLS_LIBRARIES}) | ||
endif() | ||
if(WIN32) | ||
target_link_libraries(srtp2 ws2_32) | ||
endif() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
find_path(MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h) | ||
|
||
find_library(MBEDTLS_LIBRARY mbedtls) | ||
find_library(MBEDX509_LIBRARY mbedx509) | ||
find_library(MBEDCRYPTO_LIBRARY mbedcrypto) | ||
|
||
set(MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}") | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(MbedTLS DEFAULT_MSG | ||
MBEDTLS_LIBRARY MBEDTLS_INCLUDE_DIRS MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) | ||
|
||
mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) | ||
|
||
if(NOT TARGET MbedTLS) | ||
message("in mbedtls ${MBEDTLS_LIBRARY}") | ||
add_library(MbedTLS UNKNOWN IMPORTED) | ||
set_target_properties(MbedTLS PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIRS}" | ||
IMPORTED_LINK_INTERFACE_LANGUAGES "C" | ||
IMPORTED_LOCATION "${MBEDTLS_LIBRARY}") | ||
endif() | ||
|
||
if(NOT TARGET MbedCrypto) | ||
add_library(MbedCrypto UNKNOWN IMPORTED) | ||
set_target_properties(MbedCrypto PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIRS}" | ||
IMPORTED_LINK_INTERFACE_LANGUAGES "C" | ||
IMPORTED_LOCATION "${MBEDCRYPTO_LIBRARY}") | ||
endif() | ||
|
||
if(NOT TARGET MbedX509) | ||
add_library(MbedX509 UNKNOWN IMPORTED) | ||
set_target_properties(MbedX509 PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIRS}" | ||
IMPORTED_LINK_INTERFACE_LANGUAGES "C" | ||
IMPORTED_LOCATION "${MBEDX509_LIBRARY}") | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
/* Define this to use AES-GCM. */ | ||
#cmakedefine GCM 1 | ||
|
||
/* Define this to use MBEDTLS. */ | ||
#cmakedefine MBEDTLS 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would reorder these to put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I will change the order. |
||
|
||
/* Define if building for a CISC machine (e.g. Intel). */ | ||
#define CPU_CISC 1 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unfortunate. What module are we finding from within the source tree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this for looking for FindMbedTLS.cmake, and it will be used for searching mbedtls related header files and libs. As I remember, I need to use such a cmake files to search mbedtls related stuff. Did I mistake it?