From fa5e328561d08df879c288372b305520ac887d0e Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 6 Dec 2012 10:55:23 -0800 Subject: [PATCH] New 'getRand' function. --- src/cpp/ripple/utils.cpp | 11 +++++++++++ src/cpp/ripple/utils.h | 4 ++++ 2 files changed, 15 insertions(+) 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()) : "";