Commit 482d4237

482d4237e7acMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 11 files · ~11 modified

Description

Remove the _WIN32 / MinGW code paths

Follow-up to dropping native Windows support: strip the platform-specific Windows branches now that the target is POSIX-only. Removes the Win32 fiber backend (keeping ucontext), the mmap/VirtualAlloc shims, _pipe / _fullpath / GetModuleFileNameA / GetFileAttributesW / BCryptGenRandom paths, the sp_net/sp_system Windows stubs, and the per-platform \\/.exe handling (now plain / and ""). Keeps the genuinely-portable fallbacks (Darwin/BSD arc4random, malloc_trim no-op, etc.). Windows users run under WSL as Linux.

Net -409 lines; POSIX behaviour unchanged (test/bench/optcarrot green, clang and gcc clean).

Details

Commit
482d4237e7ac
Parent
f95f87329f95

lib/sp_crypto.cmodifiedView file

@@ -33,9 +33,6 @@
3333 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
3434 # include <stdlib.h> /* arc4random_buf */
3535 #endif
36-#if defined(_WIN32) || defined(_WIN64)
37-# include <windows.h> /* LoadLibraryA / GetProcAddress for BCryptGenRandom */
38-#endif
3936
4037 /* ---------- SHA-256 ----------
4138 * FIPS-180-4. Compact reference implementation -- public domain.
@@ -509,39 +506,6 @@
509506 uint8_t r[64];
510507 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
511508 arc4random_buf(r, nbytes);
512-#elif defined(_WIN32) || defined(_WIN64)
513- /* Windows: BCryptGenRandom via runtime LoadLibrary so no
514- * link-time -lbcrypt is needed. Cached function pointer.
515- * Fall through to the time-mixed path if loading fails
516- * (rare; only on pre-Vista where bcrypt.dll isn't present). */
517- {
518- typedef long (__stdcall *sp_BCryptGenRandom_fn)(void *, unsigned char *, unsigned long, unsigned long);
519- static sp_BCryptGenRandom_fn sp_bcrypt_gen_random = NULL;
520- static int sp_bcrypt_resolved = 0;
521- if (!sp_bcrypt_resolved) {
522- sp_bcrypt_resolved = 1;
523- void *h = (void *)LoadLibraryA("bcrypt.dll");
524- if (h) sp_bcrypt_gen_random = (sp_BCryptGenRandom_fn)GetProcAddress((HMODULE)h, "BCryptGenRandom");
525- }
526- int ok = 0;
527- if (sp_bcrypt_gen_random) {
528- if (sp_bcrypt_gen_random(NULL, r, (unsigned long)nbytes, 0x00000002UL /* BCRYPT_USE_SYSTEM_PREFERRED_RNG */) == 0) {
529- ok = 1;
530- }
531- }
532- if (!ok) {
533- /* Counter-mixed time fallback so the test's "two calls
534- * must differ" invariant holds even when BCrypt is
535- * unavailable. NOT cryptographically secure. */
536- static uint64_t sp_crypto_fallback_ctr = 0;
537- sp_crypto_fallback_ctr++;
538- uint64_t mix = (uint64_t)time(NULL) ^ (sp_crypto_fallback_ctr * 0x9e3779b97f4a7c15ULL);
539- for (int k = 0; k < nbytes; k++) {
540- mix ^= mix << 13; mix ^= mix >> 7; mix ^= mix << 17;
541- r[k] = (uint8_t)mix;
542- }
543- }
544- }
545509 #else
546510 FILE *f = fopen("/dev/urandom", "rb");
547511 if (f) {