|
|
|
@ -1,9 +1,13 @@
@@ -1,9 +1,13 @@
|
|
|
|
|
#include <string.h> |
|
|
|
|
#include <string> |
|
|
|
|
#include <vector> |
|
|
|
|
#include <mutex> |
|
|
|
|
#include <openssl/sha.h> |
|
|
|
|
#include <openssl/dh.h> |
|
|
|
|
#include <openssl/md5.h> |
|
|
|
|
#include <openssl/rand.h> |
|
|
|
|
#include <openssl/ssl.h> |
|
|
|
|
#include <openssl/crypto.h> |
|
|
|
|
#include "Log.h" |
|
|
|
|
//#include "TunnelBase.h"
|
|
|
|
|
#include "Crypto.h" |
|
|
|
@ -677,6 +681,33 @@ namespace crypto
@@ -677,6 +681,33 @@ namespace crypto
|
|
|
|
|
m_IVDecryption.Decrypt ((ChipherBlock *)out, (ChipherBlock *)out); // double iv
|
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::vector <std::unique_ptr<std::mutex> > m_OpenSSLMutexes; |
|
|
|
|
static void OpensslLockingCallback(int mode, int type, const char * file, int line) |
|
|
|
|
{ |
|
|
|
|
if (type > 0 && (size_t)type < m_OpenSSLMutexes.size ()) |
|
|
|
|
{ |
|
|
|
|
if (mode & CRYPTO_LOCK) |
|
|
|
|
m_OpenSSLMutexes[type]->lock (); |
|
|
|
|
else |
|
|
|
|
m_OpenSSLMutexes[type]->unlock (); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void InitCrypto () |
|
|
|
|
{ |
|
|
|
|
SSL_library_init (); |
|
|
|
|
auto numLocks = CRYPTO_num_locks(); |
|
|
|
|
for (int i = 0; i < numLocks; i++) |
|
|
|
|
m_OpenSSLMutexes.emplace_back (new std::mutex); |
|
|
|
|
CRYPTO_set_locking_callback (OpensslLockingCallback); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TerminateCrypto () |
|
|
|
|
{ |
|
|
|
|
CRYPTO_set_locking_callback (nullptr); |
|
|
|
|
m_OpenSSLMutexes.clear (); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|