@@ -605,12 +605,9 @@ void FastRandomContext::RandomSeed()
605
605
606
606
uint256 FastRandomContext::rand256 () noexcept
607
607
{
608
- if (bytebuf_size < 32 ) {
609
- FillByteBuffer ();
610
- }
608
+ if (requires_seed) RandomSeed ();
611
609
uint256 ret;
612
- memcpy (ret.begin (), bytebuf + 64 - bytebuf_size, 32 );
613
- bytebuf_size -= 32 ;
610
+ rng.Keystream (ret.data (), ret.size ());
614
611
return ret;
615
612
}
616
613
@@ -624,7 +621,7 @@ std::vector<unsigned char> FastRandomContext::randbytes(size_t len)
624
621
return ret;
625
622
}
626
623
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 )
628
625
{
629
626
rng.SetKey (seed.begin (), 32 );
630
627
}
@@ -675,7 +672,7 @@ bool Random_SanityCheck()
675
672
return true ;
676
673
}
677
674
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 )
679
676
{
680
677
if (!fDeterministic ) {
681
678
return ;
@@ -688,12 +685,9 @@ FastRandomContext& FastRandomContext::operator=(FastRandomContext&& from) noexce
688
685
{
689
686
requires_seed = from.requires_seed ;
690
687
rng = from.rng ;
691
- std::copy (std::begin (from.bytebuf ), std::end (from.bytebuf ), std::begin (bytebuf));
692
- bytebuf_size = from.bytebuf_size ;
693
688
bitbuf = from.bitbuf ;
694
689
bitbuf_size = from.bitbuf_size ;
695
690
from.requires_seed = true ;
696
- from.bytebuf_size = 0 ;
697
691
from.bitbuf_size = 0 ;
698
692
return *this ;
699
693
}
0 commit comments