New 'getRand' function.

This commit is contained in:
JoelKatz
2012-12-06 10:55:23 -08:00
parent c55eb72d76
commit fa5e328561
2 changed files with 15 additions and 0 deletions

View File

@@ -5,6 +5,17 @@
#include <boost/foreach.hpp>
#include <boost/regex.hpp>
#include <openssl/rand.h>
void getRand(unsigned char *buf, int num)
{
if (RAND_bytes(buf, num) != 1)
{
assert(false);
throw std::runtime_error("Entropy pool not seeded");
}
}
//
// Time support
// We have our own epoch.

View File

@@ -189,6 +189,10 @@ bool parseQuality(const std::string& strSource, uint32& uQuality);
DH* DH_der_load(const std::string& strDer);
std::string DH_der_gen(int iKeyLength);
void getRand(unsigned char *buf, int num);
inline static void getRand(char *buf, int num) { return getRand(reinterpret_cast<unsigned char *>(buf), num); }
inline static void getRand(void *buf, int num) { return getRand(reinterpret_cast<unsigned char *>(buf), num); }
inline std::string strGetEnv(const std::string& strKey)
{
return getenv(strKey.c_str()) ? getenv(strKey.c_str()) : "";