If libgcrypt is available but /dev/urandom is not, use libgcrypt for RNG
This commit is contained in:
parent
d3eee55445
commit
84f0d2f774
1 changed files with 14 additions and 0 deletions
|
@ -23,6 +23,10 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
#ifdef USE_LIBGCRYPT_SHA256
|
||||||
|
#include <gcrypt.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::string rseed;
|
std::string rseed;
|
||||||
|
@ -119,6 +123,16 @@ void set_random_seed() throw(std::bad_alloc)
|
||||||
return;
|
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.
|
//Fall back to time.
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
str << collect_identifying_information() << " " << time(NULL);
|
str << collect_identifying_information() << " " << time(NULL);
|
||||||
|
|
Loading…
Add table
Reference in a new issue