Subject: [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-14 08:09:54
#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
Keywords: seed_rng |
-------------------------------------------+--------------------------------
boost_1_45_0\boost\uuid\seed_rng.hpp
static unsigned int * sha1_random_digest_state_()
{
// intentionally left uninitialized
// ERROR 1: not uninitialized! static value always zero all.
// ERROR 2: always return the same pointer of static value
// should delete 'static'
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
// ERROR 1: not uninitialized! static value always zero all.
// so state is all zero
sha.process_bytes( (unsigned char const*)state, sizeof( state ) );
// ERROR 2: always return the same pointer of static value
// so ps is same ( ps === ps)
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> 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