Add Crypto

This commit is contained in:
Michael Harding committed 2019-05-28 09:44:29 -04:00
1 parent 07fa55d317
commit f13a3325bc
15 files changed
+1087

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
#include "CryptoInit.h"
#include <tbb/spin_mutex.h>
namespace openssl
{
#include <openssl/bio.h>
#include <openssl/rand.h>
#include <openssl/bn.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
}
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)
{
//openssl::EVP_cleanup();
init = false;
}
}
}
}
}