|
10 | 10 | #include <randomenv.h>
|
11 | 11 |
|
12 | 12 | #include <clientversion.h>
|
| 13 | +#include <compat/cpuid.h> |
13 | 14 | #include <crypto/sha512.h>
|
14 | 15 | #include <support/cleanse.h>
|
15 | 16 | #include <util/time.h> // for GetTime()
|
@@ -179,6 +180,36 @@ void AddSysctl(CSHA512& hasher)
|
179 | 180 | }
|
180 | 181 | #endif
|
181 | 182 |
|
| 183 | +#ifdef HAVE_GETCPUID |
| 184 | +void inline AddCPUID(CSHA512& hasher, uint32_t leaf, uint32_t subleaf, uint32_t& ax, uint32_t& bx, uint32_t& cx, uint32_t& dx) |
| 185 | +{ |
| 186 | + GetCPUID(leaf, subleaf, ax, bx, cx, dx); |
| 187 | + hasher << leaf << subleaf << ax << bx << cx << dx; |
| 188 | +} |
| 189 | + |
| 190 | +void AddAllCPUID(CSHA512& hasher) |
| 191 | +{ |
| 192 | + uint32_t ax, bx, cx, dx; |
| 193 | + // Iterate over all standard leaves |
| 194 | + AddCPUID(hasher, 0, 0, ax, bx, cx, dx); // Returns max leaf in ax |
| 195 | + uint32_t max = ax; |
| 196 | + for (uint32_t leaf = 1; leaf <= max; ++leaf) { |
| 197 | + for (uint32_t subleaf = 0;; ++subleaf) { |
| 198 | + AddCPUID(hasher, leaf, subleaf, ax, bx, cx, dx); |
| 199 | + // Iterate over subleaves for leaf 4, 11, 13 |
| 200 | + if (leaf != 4 && leaf != 11 && leaf != 13) break; |
| 201 | + if ((leaf == 4 || leaf == 13) && ax == 0) break; |
| 202 | + if (leaf == 11 && (cx & 0xFF00) == 0) break; |
| 203 | + } |
| 204 | + } |
| 205 | + // Iterate over all extended leaves |
| 206 | + AddCPUID(hasher, 0x80000000, 0, ax, bx, cx, dx); // Returns max extended leaf in ax |
| 207 | + uint32_t ext_max = ax; |
| 208 | + for (uint32_t leaf = 0x80000001; leaf <= ext_max; ++leaf) { |
| 209 | + AddCPUID(hasher, leaf, 0, ax, bx, cx, dx); |
| 210 | + } |
| 211 | +} |
| 212 | +#endif |
182 | 213 | } // namespace
|
183 | 214 |
|
184 | 215 | void RandAddDynamicEnv(CSHA512& hasher)
|
@@ -298,6 +329,10 @@ void RandAddStaticEnv(CSHA512& hasher)
|
298 | 329 | // Bitcoin client version
|
299 | 330 | hasher << CLIENT_VERSION;
|
300 | 331 |
|
| 332 | +#ifdef HAVE_GETCPUID |
| 333 | + AddAllCPUID(hasher); |
| 334 | +#endif |
| 335 | + |
301 | 336 | // Memory locations
|
302 | 337 | hasher << &hasher << &RandAddStaticEnv << &malloc << &errno << &environ;
|
303 | 338 |
|
|
0 commit comments