@ -69,6 +69,7 @@
@@ -69,6 +69,7 @@
# include <boost/program_options/detail/config_file.hpp>
# include <boost/program_options/parsers.hpp>
# include <openssl/crypto.h>
# include <openssl/err.h>
# include <openssl/rand.h>
// Work around clang compilation problem in Boost 1.46:
@ -141,12 +142,14 @@ public:
@@ -141,12 +142,14 @@ public:
}
instance_of_cinit ;
bool GetRandBytes ( unsigned char * buf , int num )
{
if ( RAND_bytes ( buf , num ) = = 0 ) {
LogPrint ( " rand " , " %s : OpenSSL RAND_bytes() failed with error: %s \n " , __func__ , ERR_error_string ( ERR_get_error ( ) , NULL ) ) ;
return false ;
}
return true ;
}
void RandAddSeed ( )
{
@ -207,9 +210,9 @@ uint64_t GetRand(uint64_t nMax)
@@ -207,9 +210,9 @@ uint64_t GetRand(uint64_t nMax)
// to give every possible output value an equal possibility
uint64_t nRange = ( std : : numeric_limits < uint64_t > : : max ( ) / nMax ) * nMax ;
uint64_t nRand = 0 ;
do
RAND_b ytes( ( unsigned char * ) & nRand , sizeof ( nRand ) ) ;
while ( nRand > = nRange ) ;
do {
GetRandB ytes( ( unsigned char * ) & nRand , sizeof ( nRand ) ) ;
} while ( nRand > = nRange ) ;
return ( nRand % nMax ) ;
}
@ -221,7 +224,7 @@ int GetRandInt(int nMax)
@@ -221,7 +224,7 @@ int GetRandInt(int nMax)
uint256 GetRandHash ( )
{
uint256 hash ;
RAND_b ytes( ( unsigned char * ) & hash , sizeof ( hash ) ) ;
GetRandB ytes( ( unsigned char * ) & hash , sizeof ( hash ) ) ;
return hash ;
}
@ -1196,18 +1199,18 @@ uint32_t insecure_rand_Rz = 11;
@@ -1196,18 +1199,18 @@ uint32_t insecure_rand_Rz = 11;
uint32_t insecure_rand_Rw = 11 ;
void seed_insecure_rand ( bool fDeterministic )
{
//The seed values have some unlikely fixed points which we avoid.
// The seed values have some unlikely fixed points which we avoid.
if ( fDeterministic )
{
insecure_rand_Rz = insecure_rand_Rw = 11 ;
} else {
uint32_t tmp ;
do {
RAND_b ytes( ( unsigned char * ) & tmp , 4 ) ;
GetRandB ytes( ( unsigned char * ) & tmp , 4 ) ;
} while ( tmp = = 0 | | tmp = = 0x9068ffffU ) ;
insecure_rand_Rz = tmp ;
do {
RAND_b ytes( ( unsigned char * ) & tmp , 4 ) ;
GetRandB ytes( ( unsigned char * ) & tmp , 4 ) ;
} while ( tmp = = 0 | | tmp = = 0x464fffffU ) ;
insecure_rand_Rw = tmp ;
}