49 lines
1.0 KiB
C++
49 lines
1.0 KiB
C++
#ifndef _WIN32
|
|
#include "CryptoInit.h"
|
|
|
|
#include <iostream>
|
|
#include <stdlib.h>
|
|
#include <tbb/spin_mutex.h>
|
|
|
|
namespace openssl {
|
|
#include <openssl/bio.h>
|
|
#include <openssl/bn.h>
|
|
#include <openssl/pem.h>
|
|
#include <openssl/rand.h>
|
|
#include <openssl/rsa.h>
|
|
} // namespace openssl
|
|
|
|
namespace bts {
|
|
namespace crypto {
|
|
|
|
static const char rnd_seed[] =
|
|
"string to make the random number generator think it has entropy";
|
|
bool CryptoInit::init = false;
|
|
|
|
tbb::spin_mutex _lock;
|
|
|
|
void CryptoInit::initialize() {
|
|
if (!init) {
|
|
tbb::spin_mutex::scoped_lock lock(_lock);
|
|
if (!init) {
|
|
openssl::OpenSSL_add_all_algorithms();
|
|
openssl::OpenSSL_add_all_ciphers();
|
|
openssl::OpenSSL_add_all_digests();
|
|
openssl::RAND_seed(rnd_seed, sizeof rnd_seed);
|
|
init = true;
|
|
}
|
|
}
|
|
}
|
|
void CryptoInit::cleanup() {
|
|
if (init) {
|
|
tbb::spin_mutex::scoped_lock lock(_lock);
|
|
if (init) {
|
|
init = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace crypto
|
|
} // namespace bts
|
|
#endif
|