From 84f0d2f774eb5de986e11fe5bb313ec4c07d0027 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Wed, 16 Oct 2013 12:50:40 +0300 Subject: [PATCH] If libgcrypt is available but /dev/urandom is not, use libgcrypt for RNG --- src/core/misc.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core/misc.cpp b/src/core/misc.cpp index c606347f..ce0ea9af 100644 --- a/src/core/misc.cpp +++ b/src/core/misc.cpp @@ -23,6 +23,10 @@ #include #include +#ifdef USE_LIBGCRYPT_SHA256 +#include +#endif + namespace { std::string rseed; @@ -119,6 +123,16 @@ void set_random_seed() throw(std::bad_alloc) return; } } + //If libgcrypt is available, use that. +#ifdef USE_LIBGCRYPT_SHA256 + { + char buf[64]; + gcry_randomize((unsigned char*)buf, sizeof(buf), GCRY_STRONG_RANDOM); + std::string s(buf, sizeof(buf)); + set_random_seed(s); + return; + } +#endif //Fall back to time. std::ostringstream str; str << collect_identifying_information() << " " << time(NULL);