diff --git a/src/randomenv.cpp b/src/randomenv.cpp --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include // for GetTime() @@ -198,6 +199,43 @@ } #endif +#ifdef HAVE_GETCPUID +void inline AddCPUID(CSHA512 &hasher, uint32_t leaf, uint32_t subleaf, + uint32_t &ax, uint32_t &bx, uint32_t &cx, uint32_t &dx) { + GetCPUID(leaf, subleaf, ax, bx, cx, dx); + hasher << leaf << subleaf << ax << bx << cx << dx; +} + +void AddAllCPUID(CSHA512 &hasher) { + uint32_t ax, bx, cx, dx; + // Iterate over all standard leaves + // Returns max leaf in ax + AddCPUID(hasher, 0, 0, ax, bx, cx, dx); + uint32_t max = ax; + for (uint32_t leaf = 1; leaf <= max; ++leaf) { + for (uint32_t subleaf = 0;; ++subleaf) { + AddCPUID(hasher, leaf, subleaf, ax, bx, cx, dx); + // Iterate over subleaves for leaf 4, 11, 13 + if (leaf != 4 && leaf != 11 && leaf != 13) { + break; + } + if ((leaf == 4 || leaf == 13) && ax == 0) { + break; + } + if (leaf == 11 && (cx & 0xFF00) == 0) { + break; + } + } + } + // Iterate over all extended leaves + // Returns max extended leaf in ax + AddCPUID(hasher, 0x80000000, 0, ax, bx, cx, dx); + uint32_t ext_max = ax; + for (uint32_t leaf = 0x80000001; leaf <= ext_max; ++leaf) { + AddCPUID(hasher, leaf, 0, ax, bx, cx, dx); + } +} +#endif } // namespace void RandAddDynamicEnv(CSHA512 &hasher) { @@ -323,6 +361,10 @@ // Bitcoin client version hasher << CLIENT_VERSION; +#ifdef HAVE_GETCPUID + AddAllCPUID(hasher); +#endif + // Memory locations hasher << &hasher << &RandAddStaticEnv << &malloc << &errno << &environ;