diff --git a/Jamfile b/Jamfile index 44a70b86c..9588829d6 100644 --- a/Jamfile +++ b/Jamfile @@ -339,6 +339,12 @@ rule building ( properties * ) } } + if windows in $(properties) + && xp in $(properties) + { + result += src/sha512.cpp ; + } + if ( darwin in $(properties) || gcc in $(properties) || clang in $(properties) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 7fbc20e92..787dbaa27 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -237,6 +237,17 @@ POSSIBILITY OF SUCH DAMAGE. // 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 #define TORRENT_USE_GETADAPTERSADDRESSES 1 @@ -398,6 +409,10 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_USE_CRYPTOAPI 0 #endif +#ifndef TORRENT_USE_CRYPTOAPI_SHA_512 +#define TORRENT_USE_CRYPTOAPI_SHA_512 0 +#endif + #ifndef TORRENT_HAVE_MMAP #define TORRENT_HAVE_MMAP 0 #endif diff --git a/include/libtorrent/hasher512.hpp b/include/libtorrent/hasher512.hpp index 16f64c489..672380804 100644 --- a/include/libtorrent/hasher512.hpp +++ b/include/libtorrent/hasher512.hpp @@ -46,7 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #elif TORRENT_USE_COMMONCRYPTO #include -#elif TORRENT_USE_CRYPTOAPI +#elif TORRENT_USE_CRYPTOAPI_SHA_512 #include #include @@ -59,6 +59,7 @@ extern "C" { #else #include "libtorrent/sha512.hpp" #endif + #include "libtorrent/aux_/disable_warnings_pop.hpp" namespace libtorrent @@ -112,7 +113,7 @@ namespace libtorrent gcry_md_hd_t m_context; #elif TORRENT_USE_COMMONCRYPTO CC_SHA512_CTX m_context; -#elif TORRENT_USE_CRYPTOAPI +#elif TORRENT_USE_CRYPTOAPI_SHA_512 HCRYPTHASH m_context; #elif defined TORRENT_USE_LIBCRYPTO SHA512_CTX m_context; diff --git a/src/hasher512.cpp b/src/hasher512.cpp index 25fc260cc..472db65b6 100644 --- a/src/hasher512.cpp +++ b/src/hasher512.cpp @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/aux_/openssl.hpp" -#if TORRENT_USE_CRYPTOAPI +#if TORRENT_USE_CRYPTOAPI_SHA_512 namespace { HCRYPTPROV make_crypt_provider() @@ -76,7 +76,7 @@ namespace libtorrent gcry_md_open(&m_context, GCRY_MD_SHA512, 0); #elif TORRENT_USE_COMMONCRYPTO CC_SHA512_Init(&m_context); -#elif TORRENT_USE_CRYPTOAPI +#elif TORRENT_USE_CRYPTOAPI_SHA_512 if (CryptCreateHash(get_crypt_provider(), CALG_SHA_512, 0, 0, &m_context) == false) { #ifndef BOOST_NO_EXCEPTIONS @@ -111,7 +111,7 @@ namespace libtorrent gcry_md_copy(&m_context, h.m_context); return *this; } -#elif TORRENT_USE_CRYPTOAPI +#elif TORRENT_USE_CRYPTOAPI_SHA_512 hasher512::hasher512(hasher512 const& h) { if (CryptDuplicateHash(h.m_context, 0, 0, &m_context) == false) @@ -150,7 +150,7 @@ namespace libtorrent gcry_md_write(m_context, data.data(), data.size()); #elif TORRENT_USE_COMMONCRYPTO CC_SHA512_Update(&m_context, reinterpret_cast(data.data()), data.size()); -#elif TORRENT_USE_CRYPTOAPI +#elif TORRENT_USE_CRYPTOAPI_SHA_512 if (CryptHashData(m_context, reinterpret_cast(data.data()), int(data.size()), 0) == false) { #ifndef BOOST_NO_EXCEPTIONS @@ -175,7 +175,7 @@ namespace libtorrent digest.assign((char const*)gcry_md_read(m_context, 0)); #elif TORRENT_USE_COMMONCRYPTO CC_SHA512_Final(reinterpret_cast(digest.data()), &m_context); -#elif TORRENT_USE_CRYPTOAPI +#elif TORRENT_USE_CRYPTOAPI_SHA_512 DWORD size = DWORD(digest.size()); if (CryptGetHashParam(m_context, HP_HASHVAL @@ -202,7 +202,7 @@ namespace libtorrent gcry_md_reset(m_context); #elif TORRENT_USE_COMMONCRYPTO CC_SHA512_Init(&m_context); -#elif TORRENT_USE_CRYPTOAPI +#elif TORRENT_USE_CRYPTOAPI_SHA_512 CryptDestroyHash(m_context); if (CryptCreateHash(get_crypt_provider(), CALG_SHA_512, 0, 0, &m_context) == false) { @@ -221,7 +221,7 @@ namespace libtorrent hasher512::~hasher512() { -#if TORRENT_USE_CRYPTOAPI +#if TORRENT_USE_CRYPTOAPI_SHA_512 CryptDestroyHash(m_context); #elif defined TORRENT_USE_LIBGCRYPT gcry_md_close(m_context);