Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5187: uuid\seed_rng.hpp sha1_random_digest_state_ not random
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-02-15 01:15:59
#5187: uuid\seed_rng.hpp sha1_random_digest_state_ not random
--------------------------------------------+-------------------------------
Reporter: qiaozhiqiang@⦠| Owner:
Type: Bugs | Status: new
Milestone: To Be Determined | Component: None
Version: Boost 1.45.0 | Severity: Problem
Resolution: | Keywords: seed_rng
--------------------------------------------+-------------------------------
Comment (by qiaozhiqiang@â¦):
see this:
boost_1_45_0\boost\uuid\seed_rng.hpp
first time, state is all zero,sha1_random_digest_() will modify it.
but always return the same pointer of static value, so ps is not random.
{{{
static unsigned int * sha1_random_digest_state_()
{
// intentionally left uninitialized
///////////
// !!!!!!!! first time, state is all zero,sha1_random_digest_()
will modify it.
// but always return the same pointer of static value
///////////
static unsigned int state[ 5 ];
return state;
}
unsigned int * ps = sha1_random_digest_state_();
unsigned int state[ 5 ];
std::memcpy( state, ps, sizeof( state ) ); // harmless data race
sha.process_bytes( (unsigned char const*)state, sizeof( state )
);
/////////////////
// !!!!!!!! ERROR: sha1_random_digest_state_() always return the
same pointer of the static value
// so should delete next line??
////////////////
sha.process_bytes( (unsigned char const*)&ps, sizeof( ps ) );
namespace boost {
namespace uuids {
namespace detail {
// should this be part of Boost.Random?
class seed_rng
{
static unsigned int * sha1_random_digest_state_()
{
// intentionally left uninitialized
static unsigned int state[ 5 ];
return state;
}
void sha1_random_digest_()
{
boost::uuids::detail::sha1 sha;
unsigned int * ps = sha1_random_digest_state_();
unsigned int state[ 5 ];
std::memcpy( state, ps, sizeof( state ) ); // harmless data race
sha.process_bytes( (unsigned char const*)state, sizeof( state )
);
sha.process_bytes( (unsigned char const*)&ps, sizeof( ps ) );
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5187#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:05 UTC