diff --git a/src/cpp/ripple/utils.cpp b/src/cpp/ripple/utils.cpp index 9734e5974..8e94f5a10 100644 --- a/src/cpp/ripple/utils.cpp +++ b/src/cpp/ripple/utils.cpp @@ -5,6 +5,17 @@ #include #include +#include + +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. diff --git a/src/cpp/ripple/utils.h b/src/cpp/ripple/utils.h index 10eae9673..92161ffae 100644 --- a/src/cpp/ripple/utils.h +++ b/src/cpp/ripple/utils.h @@ -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(buf), num); } +inline static void getRand(void *buf, int num) { return getRand(reinterpret_cast(buf), num); } + inline std::string strGetEnv(const std::string& strKey) { return getenv(strKey.c_str()) ? getenv(strKey.c_str()) : "";