Skip to content

Commit 64e03e6

Browse files
sipaWarrows
authored andcommitted
Bugfix: randbytes should seed when needed (non reachable issue)
1 parent e8f12aa commit 64e03e6

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/random.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ uint256 FastRandomContext::rand256()
396396

397397
std::vector<unsigned char> FastRandomContext::randbytes(size_t len)
398398
{
399+
if (requires_seed) RandomSeed();
399400
std::vector<unsigned char> ret(len);
400401
if (len > 0) {
401402
rng.Output(&ret[0], len);

src/test/random_tests.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ BOOST_AUTO_TEST_CASE(fastrandom_tests)
3535
BOOST_CHECK(ctx1.randbytes(50) == ctx2.randbytes(50));
3636

3737
// Check that a nondeterministic ones are not
38-
FastRandomContext ctx3;
39-
FastRandomContext ctx4;
40-
BOOST_CHECK(ctx3.rand64() != ctx4.rand64()); // extremely unlikely to be equal
41-
BOOST_CHECK(ctx3.rand256() != ctx4.rand256());
42-
BOOST_CHECK(ctx3.randbytes(7) != ctx4.randbytes(7));
38+
{
39+
FastRandomContext ctx3, ctx4;
40+
BOOST_CHECK(ctx3.rand64() != ctx4.rand64()); // extremely unlikely to be equal
41+
}
42+
{
43+
FastRandomContext ctx3, ctx4;
44+
BOOST_CHECK(ctx3.rand256() != ctx4.rand256());
45+
}
46+
{
47+
FastRandomContext ctx3, ctx4;
48+
BOOST_CHECK(ctx3.randbytes(7) != ctx4.randbytes(7));
49+
}
4350
}
4451

4552
BOOST_AUTO_TEST_CASE(fastrandom_randbits)

0 commit comments

Comments
 (0)