@@ -605,12 +605,9 @@ void FastRandomContext::RandomSeed()
605605
606606uint256 FastRandomContext::rand256 () noexcept
607607{
608- if (bytebuf_size < 32 ) {
609- FillByteBuffer ();
610- }
608+ if (requires_seed) RandomSeed ();
611609 uint256 ret;
612- memcpy (ret.begin (), bytebuf + 64 - bytebuf_size, 32 );
613- bytebuf_size -= 32 ;
610+ rng.Keystream (ret.data (), ret.size ());
614611 return ret;
615612}
616613
@@ -624,7 +621,7 @@ std::vector<unsigned char> FastRandomContext::randbytes(size_t len)
624621 return ret;
625622}
626623
627- FastRandomContext::FastRandomContext (const uint256& seed) noexcept : requires_seed(false ), bytebuf_size( 0 ), bitbuf_size(0 )
624+ FastRandomContext::FastRandomContext (const uint256& seed) noexcept : requires_seed(false ), bitbuf_size(0 )
628625{
629626 rng.SetKey (seed.begin (), 32 );
630627}
@@ -675,7 +672,7 @@ bool Random_SanityCheck()
675672 return true ;
676673}
677674
678- FastRandomContext::FastRandomContext (bool fDeterministic ) noexcept : requires_seed(!fDeterministic ), bytebuf_size( 0 ), bitbuf_size(0 )
675+ FastRandomContext::FastRandomContext (bool fDeterministic ) noexcept : requires_seed(!fDeterministic ), bitbuf_size(0 )
679676{
680677 if (!fDeterministic ) {
681678 return ;
@@ -688,12 +685,9 @@ FastRandomContext& FastRandomContext::operator=(FastRandomContext&& from) noexce
688685{
689686 requires_seed = from.requires_seed ;
690687 rng = from.rng ;
691- std::copy (std::begin (from.bytebuf ), std::end (from.bytebuf ), std::begin (bytebuf));
692- bytebuf_size = from.bytebuf_size ;
693688 bitbuf = from.bitbuf ;
694689 bitbuf_size = from.bitbuf_size ;
695690 from.requires_seed = true ;
696- from.bytebuf_size = 0 ;
697691 from.bitbuf_size = 0 ;
698692 return *this ;
699693}
0 commit comments