Re: [Boost-bugs] [Boost C++ Libraries] #5187: uuid\seed_rng.hpp sha1_random_digest_state_ not random

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: 2012-09-09 19:12:43


#5187: uuid\seed_rng.hpp sha1_random_digest_state_ not random
--------------------------------------------+-------------------------------
  Reporter: qiaozhiqiang@… | Owner: atompkins
      Type: Bugs | Status: closed
 Milestone: To Be Determined | Component: uuid
   Version: Boost 1.45.0 | Severity: Problem
Resolution: invalid | Keywords: seed_rng
--------------------------------------------+-------------------------------
Changes (by atompkins):

  * status: new => closed
  * resolution: => invalid

Comment:

 I'm finally getting back to this after some research and thinking.

 The static variable in {{{sha1_random_digest_state_()}}},
   {{{static unsigned int state[5];}}}
 may be set to zero with some compilers / flags (often in debug builds).
 But the program _does_ change the values in it every time
 {{{sha1_random_digest_()}}} is called (at the bottom of the function).
 Thus the values in the {{{static unsigned int state[5];}}} are not
 constant for the duration of the program. So at worst it is initialized
 to zero, at best it does contain random data initially, but in either case
 it is changing data that is mixed in.

 The function {{{sha1_random_digest_();}}} uses many different kinds of
 allocation for unitialized data. It uses a static array in
 {{{sha1_random_digest_state_();}}}, it uses a local array in
 {{{sha1_random_digest_();}}}, {{{unsigned int state[5]}}}. It uses data
 on the heap as well, {{{unsigned int * p = new unsigned int}}}.

 {{{sha1_random_digest_state_()}}} does always return the same pointer and
 so in {{{sha1_random_digest_()}}}, {{{unsigned int * ps =
 sha1_random_digest_state_();}}}
 {{{ps}}} always points to the same data but the line we use it in,

 {{{sha.process_bytes( (unsigned char const*)&ps, sizeof( ps ) );}}}

 does not use the value of {{{ps}}}, but the address of {{{ps}}},
 {{{&ps}}}, which is a value on the stack since this is a local variable.
 Thus {{{&ps}}} is different each time.

 I still believe the code is correct.

 I am closing the ticket as "invalid" since the other choices do not seem
 to apply.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5187#comment:5>
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:10 UTC