diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 7a6e7ff55..3e5231b6e 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -20,6 +20,7 @@ */ #include "CommonData.h" +#include #include #include "Exceptions.h" #include "Log.h" diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 973bc174e..8beb3bec7 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -149,18 +149,16 @@ public: /// @returns a constant reference to the object's data as an STL array. std::array const& asArray() const { return m_data; } - /// @returns a randomly-valued hash + /// Populate with random data. template - static FixedHash random(Engine& _eng) + void randomize(Engine& _eng) { - FixedHash ret; - for (auto& i: ret.m_data) + for (auto& i: m_data) i = (uint8_t)boost::random::uniform_int_distribution(0, 255)(_eng); - return ret; } /// @returns a random valued object. - static FixedHash random() { return random(s_fixedHashEngine); } + static FixedHash random() { FixedHash ret; ret.randomize(s_fixedHashEngine); return ret; } struct hash { @@ -293,7 +291,7 @@ public: bytesConstRef ref() const { return FixedHash::ref(); } byte const* data() const { return FixedHash::data(); } - static SecureFixedHash random() { SecureFixedHash ret; ret.FixedHash::ref().randomize(); return ret; } + static SecureFixedHash random() { SecureFixedHash ret; ret.randomize(s_fixedHashEngine); return ret; } using FixedHash::firstBitSet; void clear() { ref().cleanse(); } diff --git a/libdevcore/vector_ref.h b/libdevcore/vector_ref.h index b5d0453a6..6fb9ad3b5 100644 --- a/libdevcore/vector_ref.h +++ b/libdevcore/vector_ref.h @@ -5,16 +5,10 @@ #include #include #include -#include -#include -#include namespace dev { -static unsigned char s_cleanseCounter = 0; -static boost::random_device s_vectorRefEngine; - /** * A modifiable reference to an existing object or vector in memory. */ @@ -71,20 +65,11 @@ public: void copyTo(vector_ref::type> _t) const { if (overlapsWith(_t)) memmove(_t.data(), m_data, std::min(_t.size(), m_count) * sizeof(_T)); else memcpy(_t.data(), m_data, std::min(_t.size(), m_count) * sizeof(_T)); } /// Copies the contents of this vector_ref to the contents of @a _t, and zeros further trailing elements in @a _t. void populate(vector_ref::type> _t) const { copyTo(_t); memset(_t.data() + m_count, 0, std::max(_t.size(), m_count) - m_count); } - /// Populate with random data. - template - void randomize(Engine& _eng) - { - uint8_t* e = (uint8_t*)end(); - for (uint8_t* i = (uint8_t*)begin(); i != e; ++i) - *i = (uint8_t)boost::random::uniform_int_distribution(0, 255)(_eng); - } - /// @returns a random valued object. - void randomize() { randomize(s_vectorRefEngine); } /// Securely overwrite the memory. /// @note adapted from OpenSSL's implementation. void cleanse() { + static unsigned char s_cleanseCounter = 0; uint8_t* p = (uint8_t*)begin(); size_t const len = (uint8_t*)end() - p; size_t loop = len; diff --git a/libethcore/EthashCPUMiner.cpp b/libethcore/EthashCPUMiner.cpp index 0c645c831..6c7097605 100644 --- a/libethcore/EthashCPUMiner.cpp +++ b/libethcore/EthashCPUMiner.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #if ETH_CPUID || !ETH_TRUE #define HAVE_STDINT_H #include @@ -78,7 +79,7 @@ void EthashCPUMiner::workLoop() auto tid = std::this_thread::get_id(); static std::mt19937_64 s_eng((time(0) + std::hash()(tid))); - uint64_t tryNonce = (uint64_t)(u64)Nonce::random(s_eng); + uint64_t tryNonce = s_eng(); ethash_return_value ethashReturn; WorkPackage w = work();