6#if defined(HAVE_CONFIG_H)
7#include <config/bitcoin-config.h>
33#include <netinet/in.h>
34#include <sys/resource.h>
35#include <sys/socket.h>
38#include <sys/utsname.h>
41#if HAVE_DECL_GETIFADDRS
45#include <sys/sysctl.h>
47#include <vm/vm_param.h>
49#if HAVE_SYS_RESOURCES_H
50#include <sys/resources.h>
53#include <sys/vmmeter.h>
70 static std::atomic<std::chrono::seconds>
last_perfmon{0s};
78 std::vector<uint8_t> vData(250000, 0);
80 unsigned long nSize = 0;
86 nullptr, vData.data(), &nSize);
91 vData.resize(std::min((vData.size() * 3) / 2,
nMaxSize));
95 hasher.
Write(vData.data(), nSize);
115 !std::is_same<typename std::decay<T>::type,
char *>::value,
116 "Calling operator<<(CSHA512, char*) is probably not what you want");
118 !std::is_same<typename std::decay<T>::type,
uint8_t *>::value,
119 "Calling operator<<(CSHA512, uint8_t*) is probably not what you "
122 !std::is_same<typename std::decay<T>::type,
const char *>::value,
123 "Calling operator<<(CSHA512, const char*) is probably not what you "
126 !std::is_same<typename std::decay<T>::type,
const uint8_t *>::value,
127 "Calling operator<<(CSHA512, const uint8_t*) is "
128 "probably not what you want");
135 if (addr ==
nullptr) {
138 switch (addr->sa_family) {
147 sizeof(addr->sa_family));
169 }
while (n ==
sizeof(
fbuf) &&
177 if (
stat(path, &
sb) == 0) {
186 int CTL[
sizeof...(S)] = {
S...};
191 hasher <<
sizeof(
CTL);
215 for (
uint32_t leaf = 1; leaf <= max && leaf <= 0xFF; ++leaf) {
221 if ((
ax & 0x1f) == 0) {
224 }
else if (leaf == 7) {
231 }
else if (leaf == 11) {
232 if ((
cx & 0xff00) == 0) {
235 }
else if (leaf == 13) {
236 if (
ax == 0 &&
bx == 0 &&
cx == 0 &&
dx == 0) {
249 for (
uint32_t leaf = 0x80000001; leaf <=
ext_max && leaf <= 0x800000FF;
267#ifdef CLOCK_MONOTONIC
277 hasher <<
ts.tv_sec <<
ts.tv_nsec;
286 hasher << std::chrono::system_clock::now().time_since_epoch().count();
287 hasher << std::chrono::steady_clock::now().time_since_epoch().count();
289 << std::chrono::high_resolution_clock::now().time_since_epoch().count();
300 AddFile(hasher,
"/proc/diskstats");
301 AddFile(hasher,
"/proc/vmstat");
302 AddFile(hasher,
"/proc/schedstat");
303 AddFile(hasher,
"/proc/zoneinfo");
304 AddFile(hasher,
"/proc/meminfo");
305 AddFile(hasher,
"/proc/softirqs");
307 AddFile(hasher,
"/proc/self/schedstat");
308 AddFile(hasher,
"/proc/self/status");
313#if defined(KERN_PROC) && defined(KERN_PROC_ALL)
336 void *addr =
malloc(4097);
337 hasher << &addr << addr;
343 hasher << (
CHAR_MIN < 0) <<
sizeof(
void *) <<
sizeof(
long) <<
sizeof(
int);
344#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
404#if HAVE_DECL_GETIFADDRS
414 sizeof(
ifit->ifa_flags));
442 AddFile(hasher,
"/proc/cmdline");
443 AddFile(hasher,
"/proc/cpuinfo");
444 AddFile(hasher,
"/proc/version");
446 AddFile(hasher,
"/etc/passwd");
449 AddFile(hasher,
"/etc/resolv.conf");
450 AddFile(hasher,
"/etc/timezone");
451 AddFile(hasher,
"/etc/localtime");
473#ifdef HW_MACHINE_ARCH
531 for (
size_t i = 0;
environ[i]; ++i) {
543 hasher << std::this_thread::get_id();
A hasher class for SHA-512.
CSHA512 & Write(const uint8_t *data, size_t len)
void memory_cleanse(void *ptr, size_t len)
Secure overwrite a buffer (possibly containing secret data) with zero-bytes.
static constexpr int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
size_t strnlen(const char *start, size_t max_len)
std::ostream & operator<<(std::ostream &os, const PeerMessagingState &state)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
void RandAddStaticEnv(CSHA512 &hasher)
Gather non-cryptographic environment data that does not change over time.
char ** environ
Necessary on some platforms.
void RandAddDynamicEnv(CSHA512 &hasher)
Gather non-cryptographic environment data that changes over time.