From 748bb81570623b0e6c4e5c705e41386037991016 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 12 Feb 2019 11:26:05 +0100 Subject: [PATCH] include sha1.cpp in the build unconditionally, match build configuration options to using built-in sha1 and defining it --- CMakeLists.txt | 10 ++-------- ChangeLog | 2 ++ Jamfile | 19 ++----------------- include/libtorrent/config.hpp | 16 ++++++++++++++++ include/libtorrent/sha1.hpp | 7 +++++++ include/libtorrent/sha512.hpp | 7 +++++++ src/Makefile.am | 12 +++--------- src/sha1.cpp | 11 +++++++++-- src/sha512.cpp | 7 +++++++ 9 files changed, 55 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49e33d0b6..69f92f624 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -296,6 +296,7 @@ set(sources fingerprint gzip hasher + sha1 hex http_connection http_stream @@ -647,10 +648,6 @@ else(OPENSSL_FOUND) if (LibGcrypt_FOUND) target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_LIBGCRYPT) target_link_libraries(torrent-rasterbar PRIVATE LibGcrypt::LibGcrypt) - else() - if (NOT WIN32 AND NOT APPLE) - target_sources(torrent-rasterbar PRIVATE src/sha1) - endif() endif() endif(OPENSSL_FOUND) @@ -666,12 +663,9 @@ if (dht) ${ed25519_sources} ${libtorrent_kademlia_include_files} src/hasher512 + src/sha512 ) target_include_directories(torrent-rasterbar PRIVATE ed25519/src) - - if (NOT OpenSSL_FOUND AND NOT LibGcrypt_FOUND AND NOT WIN32 AND NOT APPLE) - target_sources(torrent-rasterbar PRIVATE src/sha512) - endif() else() target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_DISABLE_DHT) endif() diff --git a/ChangeLog b/ChangeLog index 69edbc909..45bc5cc6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * fix Mingw build to use native cryptoAPI + 1.2 release * requires boost >= 1.58 to build diff --git a/Jamfile b/Jamfile index b231f03cb..05cacb21c 100644 --- a/Jamfile +++ b/Jamfile @@ -285,23 +285,6 @@ rule building ( properties * ) result += src/pe_crypto.cpp ; } - if built-in in $(properties) - && ! windows in $(properties) - && ! darwin in $(properties) - { - result += src/sha1.cpp ; - if on in $(properties) - { - result += src/sha512.cpp ; - } - } - - if windows in $(properties) - && xp in $(properties) - { - result += src/sha512.cpp ; - } - if ( darwin in $(properties) || gcc in $(properties) || clang in $(properties) @@ -651,6 +634,7 @@ SOURCES = session_call session_udp_sockets settings_pack + sha1 sha1_hash socket_io socket_type @@ -785,6 +769,7 @@ lib torrent on:src/kademlia/$(KADEMLIA_SOURCES).cpp on:ed25519/src/$(ED25519_SOURCES).cpp on:src/hasher512.cpp + on:src/sha512.cpp @building @warnings diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 7af286615..e6034e1e1 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -234,6 +234,22 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_USE_PREADV 1 #define TORRENT_USE_PWRITEV 1 +# if !defined TORRENT_USE_LIBCRYPTO && !defined TORRENT_USE_LIBGCRYPT +// unless some other crypto library has been specified, default to the native +// windows CryptoAPI +#define TORRENT_USE_CRYPTOAPI 1 + +#ifdef NTDDI_VERSION +# if (NTDDI_VERSION > NTDDI_WINXPSP2) +# define TORRENT_USE_CRYPTOAPI_SHA_512 1 +# endif +#else // NTDDI_VERSION not defined so use simple _WIN32_WINNT check +# if _WIN32_WINNT >= 0x0600 +# define TORRENT_USE_CRYPTOAPI_SHA_512 1 +# endif +#endif + +#endif // ==== WINDOWS === #elif defined _WIN32 #define TORRENT_WINDOWS diff --git a/include/libtorrent/sha1.hpp b/include/libtorrent/sha1.hpp index b2eb67a87..091224190 100644 --- a/include/libtorrent/sha1.hpp +++ b/include/libtorrent/sha1.hpp @@ -14,6 +14,12 @@ changelog at the end of sha1.cpp #define TORRENT_SHA1_HPP_INCLUDED #include "libtorrent/config.hpp" + +#if !defined TORRENT_USE_LIBGCRYPT \ + && !TORRENT_USE_COMMONCRYPTO \ + && !TORRENT_USE_CRYPTOAPI \ + && !defined TORRENT_USE_LIBCRYPTO + #include namespace libtorrent { @@ -33,3 +39,4 @@ namespace libtorrent { } #endif +#endif diff --git a/include/libtorrent/sha512.hpp b/include/libtorrent/sha512.hpp index fac3eeadf..ffe93ffc8 100644 --- a/include/libtorrent/sha512.hpp +++ b/include/libtorrent/sha512.hpp @@ -2,6 +2,12 @@ #define TORRENT_SHA512_HPP_INCLUDED #include "libtorrent/config.hpp" + +#if !defined TORRENT_USE_LIBGCRYPT \ + && !TORRENT_USE_COMMONCRYPTO \ + && !TORRENT_USE_CRYPTOAPI_SHA_512 \ + && !defined TORRENT_USE_LIBCRYPTO + #include namespace libtorrent { @@ -21,3 +27,4 @@ namespace libtorrent { } #endif +#endif diff --git a/src/Makefile.am b/src/Makefile.am index 4417d5416..dacdf806f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,12 +35,6 @@ KADEMLIA_SOURCES = \ hasher512.cpp endif -if ! WITH_OPENSSL -BUILTIN_CRYPTO_SOURCES = \ - sha1.cpp \ - sha512.cpp -endif - libtorrent_rasterbar_la_SOURCES = \ web_connection_base.cpp \ alert.cpp \ @@ -166,10 +160,10 @@ libtorrent_rasterbar_la_SOURCES = \ add_torrent_params.cpp \ peer_info.cpp \ stack_allocator.cpp \ + sha1.cpp \ + sha512.cpp \ \ - $(KADEMLIA_SOURCES) \ - \ - $(BUILTIN_CRYPTO_SOURCES) + $(KADEMLIA_SOURCES) AM_CFLAGS = -I$(top_srcdir)/ed25519/src -std=c99 AM_CPPFLAGS = -DTORRENT_BUILDING_LIBRARY -I$(top_srcdir)/include -I$(top_srcdir)/ed25519/src @DEBUGFLAGS@ @OPENSSL_INCLUDES@ diff --git a/src/sha1.cpp b/src/sha1.cpp index 739153fed..839c59088 100644 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -10,11 +10,16 @@ By Steve Reid changelog at the end of the file. */ +#include "libtorrent/sha1.hpp" + +#if !defined TORRENT_USE_LIBGCRYPT \ + && !TORRENT_USE_COMMONCRYPTO \ + && !TORRENT_USE_CRYPTOAPI \ + && !defined TORRENT_USE_LIBCRYPTO + #include #include -#include "libtorrent/sha1.hpp" - #include "libtorrent/aux_/disable_warnings_push.hpp" #include #include "libtorrent/aux_/disable_warnings_pop.hpp" @@ -237,6 +242,8 @@ void SHA1_final(u8* digest, sha1_ctx* context) } // libtorrent namespace +#endif + /************************************************************ ----------------- diff --git a/src/sha512.cpp b/src/sha512.cpp index 64aa61250..63dadd976 100644 --- a/src/sha512.cpp +++ b/src/sha512.cpp @@ -3,6 +3,11 @@ #include "libtorrent/sha512.hpp" +#if !defined TORRENT_USE_LIBGCRYPT \ + && !TORRENT_USE_COMMONCRYPTO \ + && !TORRENT_USE_CRYPTOAPI_SHA_512 \ + && !defined TORRENT_USE_LIBCRYPTO + // ignore warnings in this file #include "libtorrent/aux_/disable_warnings_push.hpp" @@ -280,3 +285,5 @@ int SHA512_final(std::uint8_t* out, sha512_ctx* md) } } // libtorrent namespace + +#endif