Add native Windows build of meshtasticd (#11031)

This commit is contained in:
Thomas Göttgens
2026-07-19 23:31:19 +02:00
committed by GitHub
co-authored by GitHub
parent 4726375282
commit a808e992a1
16 changed files with 910 additions and 21 deletions
+12
View File
@@ -22,6 +22,12 @@ extern Adafruit_nRFCrypto nRFCrypto;
#include <unistd.h>
#ifdef __linux__
#include <sys/random.h> // getrandom()
#elif defined(_WIN32)
// Order is load-bearing, hence the blank line: bcrypt.h uses LONG/ULONG from
// windows.h and does not include it itself.
#include <windows.h>
#include <bcrypt.h> // BCryptGenRandom()
#else
#include <stdlib.h> // arc4random_buf() on Darwin/BSD
#endif
@@ -128,6 +134,12 @@ bool fill(uint8_t *buffer, size_t length, bool useRadioEntropy)
if (generated == static_cast<ssize_t>(length)) {
filled = true;
}
#elif defined(_WIN32)
// No getrandom/arc4random on Windows; BCryptGenRandom is the documented CSPRNG.
// Preferred over std::random_device, whose libstdc++ Windows backend reports entropy() == 0.
if (BCryptGenRandom(NULL, buffer, static_cast<ULONG>(length), BCRYPT_USE_SYSTEM_PREFERRED_RNG) == 0) { // STATUS_SUCCESS
filled = true;
}
#elif defined(__EMSCRIPTEN__)
// Browser/wasm: no getrandom/arc4random - fall through to std::random_device,
// which emscripten backs with crypto.getRandomValues().