Changeset View
Changeset View
Standalone View
Standalone View
src/randomenv.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2019 The Bitcoin Core developers | // Copyright (c) 2009-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#if defined(HAVE_CONFIG_H) | #if defined(HAVE_CONFIG_H) | ||||
#include <config/bitcoin-config.h> | #include <config/bitcoin-config.h> | ||||
#endif | #endif | ||||
#include <randomenv.h> | #include <randomenv.h> | ||||
#include <clientversion.h> | #include <clientversion.h> | ||||
#include <compat/cpuid.h> | |||||
#include <crypto/sha512.h> | #include <crypto/sha512.h> | ||||
#include <support/cleanse.h> | #include <support/cleanse.h> | ||||
#include <util/time.h> // for GetTime() | #include <util/time.h> // for GetTime() | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
#include <compat.h> // for Windows API | #include <compat.h> // for Windows API | ||||
#endif | #endif | ||||
#include <algorithm> | #include <algorithm> | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if (ret == 0 || (ret == -1 && errno == ENOMEM)) { | ||||
siz = sizeof(buffer); | siz = sizeof(buffer); | ||||
} | } | ||||
hasher << siz; | hasher << siz; | ||||
hasher.Write(buffer, siz); | hasher.Write(buffer, siz); | ||||
} | } | ||||
} | } | ||||
#endif | #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 | } // namespace | ||||
void RandAddDynamicEnv(CSHA512 &hasher) { | void RandAddDynamicEnv(CSHA512 &hasher) { | ||||
RandAddSeedPerfmon(hasher); | RandAddSeedPerfmon(hasher); | ||||
// Various clocks | // Various clocks | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
FILETIME ftime; | FILETIME ftime; | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | #ifdef __VERSION__ | ||||
const char *COMPILER_VERSION = __VERSION__; | const char *COMPILER_VERSION = __VERSION__; | ||||
hasher.Write((const uint8_t *)COMPILER_VERSION, | hasher.Write((const uint8_t *)COMPILER_VERSION, | ||||
strlen(COMPILER_VERSION) + 1); | strlen(COMPILER_VERSION) + 1); | ||||
#endif | #endif | ||||
// Bitcoin client version | // Bitcoin client version | ||||
hasher << CLIENT_VERSION; | hasher << CLIENT_VERSION; | ||||
#ifdef HAVE_GETCPUID | |||||
AddAllCPUID(hasher); | |||||
#endif | |||||
// Memory locations | // Memory locations | ||||
hasher << &hasher << &RandAddStaticEnv << &malloc << &errno << &environ; | hasher << &hasher << &RandAddStaticEnv << &malloc << &errno << &environ; | ||||
// Hostname | // Hostname | ||||
char hname[256]; | char hname[256]; | ||||
if (gethostname(hname, 256) == 0) { | if (gethostname(hname, 256) == 0) { | ||||
hasher.Write((const uint8_t *)hname, strnlen(hname, 256)); | hasher.Write((const uint8_t *)hname, strnlen(hname, 256)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |