aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-02-22 08:57:38 -0800
committerGavin Andresen <gavinandresen@gmail.com>2013-02-22 08:57:38 -0800
commitaaeb443791f880351692ac020e8fdea44d2270b0 (patch)
treec32831368135385ed93bbe737b2d441e874b6b87 /src/wallet.cpp
parent1167af7e5ca7f9bccc383e6ec1feb3edbbefa191 (diff)
parent907a2aa4c78833ce93455567ae10ff2f506e752e (diff)
Merge pull request #2312 from gmaxwell/random_random
ApproximateBestSubset internal RNG to prevent degenerate behavior.
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 3892e4b801..eecb7d2d22 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -984,6 +984,8 @@ static void ApproximateBestSubset(vector<pair<int64, pair<const CWalletTx*,unsig
vfBest.assign(vValue.size(), true);
nBest = nTotalLower;
+ seed_insecure_rand();
+
for (int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++)
{
vfIncluded.assign(vValue.size(), false);
@@ -993,7 +995,13 @@ static void ApproximateBestSubset(vector<pair<int64, pair<const CWalletTx*,unsig
{
for (unsigned int i = 0; i < vValue.size(); i++)
{
- if (nPass == 0 ? rand() % 2 : !vfIncluded[i])
+ //The solver here uses a randomized algorithm,
+ //the randomness serves no real security purpose but is just
+ //needed to prevent degenerate behavior and it is important
+ //that the rng fast. We do not use a constant random sequence,
+ //because there may be some privacy improvement by making
+ //the selection random.
+ if (nPass == 0 ? insecure_rand()&1 : !vfIncluded[i])
{
nTotal += vValue[i].first;
vfIncluded[i] = true;