mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-09 14:28:22 +00:00
This commit is contained in:
parent
284021ed7e
commit
08cadbb78e
@ -88,7 +88,6 @@ LIBTORRENT_SOURCES = \
|
||||
libtorrent/src/session.cpp \
|
||||
libtorrent/src/session_impl.cpp \
|
||||
libtorrent/src/settings.cpp \
|
||||
libtorrent/src/sha1.cpp \
|
||||
libtorrent/src/smart_ban.cpp \
|
||||
libtorrent/src/socket_io.cpp \
|
||||
libtorrent/src/socket_type.cpp \
|
||||
|
@ -39,39 +39,11 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
#include <gcrypt.h>
|
||||
|
||||
#elif TORRENT_USE_COMMONCRYPTO
|
||||
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
|
||||
#elif defined TORRENT_USE_OPENSSL
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <openssl/sha.h>
|
||||
}
|
||||
|
||||
#else
|
||||
// from sha1.cpp
|
||||
namespace libtorrent
|
||||
{
|
||||
|
||||
struct TORRENT_EXTRA_EXPORT sha_ctx
|
||||
{
|
||||
boost::uint32_t state[5];
|
||||
boost::uint32_t count[2];
|
||||
boost::uint8_t buffer[64];
|
||||
};
|
||||
|
||||
TORRENT_EXTRA_EXPORT void SHA1_init(sha_ctx* context);
|
||||
TORRENT_EXTRA_EXPORT void SHA1_update(sha_ctx* context, boost::uint8_t const* data, boost::uint32_t len);
|
||||
TORRENT_EXTRA_EXPORT void SHA1_final(boost::uint8_t* digest, sha_ctx* context);
|
||||
} // namespace libtorrent
|
||||
|
||||
#endif
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
class TORRENT_EXTRA_EXPORT hasher
|
||||
@ -81,32 +53,15 @@ namespace libtorrent
|
||||
hasher();
|
||||
hasher(const char* data, int len);
|
||||
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
hasher(hasher const& h);
|
||||
hasher& operator=(hasher const& h);
|
||||
#endif
|
||||
|
||||
void update(std::string const& data) { update(data.c_str(), data.size()); }
|
||||
void update(const char* data, int len);
|
||||
sha1_hash final();
|
||||
|
||||
void reset();
|
||||
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
~hasher();
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
gcry_md_hd_t m_context;
|
||||
#elif TORRENT_USE_COMMONCRYPTO
|
||||
CC_SHA1_CTX m_context;
|
||||
#elif defined TORRENT_USE_OPENSSL
|
||||
SHA_CTX m_context;
|
||||
#else
|
||||
sha_ctx m_context;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -36,100 +36,34 @@ namespace libtorrent
|
||||
{
|
||||
hasher::hasher()
|
||||
{
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
gcry_md_open(&m_context, GCRY_MD_SHA1, 0);
|
||||
#elif TORRENT_USE_COMMONCRYPTO
|
||||
CC_SHA1_Init(&m_context);
|
||||
#elif defined TORRENT_USE_OPENSSL
|
||||
SHA1_Init(&m_context);
|
||||
#else
|
||||
SHA1_init(&m_context);
|
||||
#endif
|
||||
}
|
||||
|
||||
hasher::hasher(const char* data, int len)
|
||||
{
|
||||
TORRENT_ASSERT(data != 0);
|
||||
TORRENT_ASSERT(len > 0);
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
gcry_md_open(&m_context, GCRY_MD_SHA1, 0);
|
||||
gcry_md_write(m_context, data, len);
|
||||
#elif TORRENT_USE_COMMONCRYPTO
|
||||
CC_SHA1_Init(&m_context);
|
||||
CC_SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
|
||||
#elif defined TORRENT_USE_OPENSSL
|
||||
SHA1_Init(&m_context);
|
||||
SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
|
||||
#else
|
||||
SHA1_init(&m_context);
|
||||
SHA1_update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
hasher::hasher(hasher const& h)
|
||||
{
|
||||
gcry_md_copy(&m_context, h.m_context);
|
||||
}
|
||||
|
||||
hasher& hasher::operator=(hasher const& h)
|
||||
{
|
||||
gcry_md_close(m_context);
|
||||
gcry_md_copy(&m_context, h.m_context);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
void hasher::update(const char* data, int len)
|
||||
{
|
||||
TORRENT_ASSERT(data != 0);
|
||||
TORRENT_ASSERT(len > 0);
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
gcry_md_write(m_context, data, len);
|
||||
#elif TORRENT_USE_COMMONCRYPTO
|
||||
CC_SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
|
||||
#elif defined TORRENT_USE_OPENSSL
|
||||
SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
|
||||
#else
|
||||
SHA1_update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
|
||||
#endif
|
||||
}
|
||||
|
||||
sha1_hash hasher::final()
|
||||
{
|
||||
sha1_hash digest;
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
gcry_md_final(m_context);
|
||||
digest.assign((const char*)gcry_md_read(m_context, 0));
|
||||
#elif TORRENT_USE_COMMONCRYPTO
|
||||
CC_SHA1_Final(digest.begin(), &m_context);
|
||||
#elif defined TORRENT_USE_OPENSSL
|
||||
SHA1_Final(digest.begin(), &m_context);
|
||||
#else
|
||||
SHA1_final(digest.begin(), &m_context);
|
||||
#endif
|
||||
return digest;
|
||||
}
|
||||
|
||||
void hasher::reset()
|
||||
{
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
gcry_md_reset(m_context);
|
||||
#elif TORRENT_USE_COMMONCRYPTO
|
||||
CC_SHA1_Init(&m_context);
|
||||
#elif defined TORRENT_USE_OPENSSL
|
||||
SHA1_Init(&m_context);
|
||||
#else
|
||||
SHA1_init(&m_context);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TORRENT_USE_GCRYPT
|
||||
hasher::~hasher()
|
||||
{
|
||||
gcry_md_close(m_context);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user