From 20f47c88f44bb4cfc4964bc22342d838239d4c73 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:53:55 +0000 Subject: [PATCH] Remove the getentropy() stand-in for Mac OS 9 mac-sdk's C library now has getentropy(). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRVR36R8PgTTMQiuWkQ --- docs/building.md | 4 -- external/D-Modem | 2 +- winport/CMakeLists.txt | 3 -- winport/macos9/getentropy.c | 75 ------------------------------------- 4 files changed, 1 insertion(+), 83 deletions(-) delete mode 100644 winport/macos9/getentropy.c diff --git a/docs/building.md b/docs/building.md index 46fb385..a91dfd6 100644 --- a/docs/building.md +++ b/docs/building.md @@ -123,10 +123,6 @@ These items are different on Mac OS 9: - `cmake/Platform/MacOS9.cmake` gives the CMake system `MacOS9`. The built-in modem needs D-Modem with the changes for this system (`docs/macos-details.md` in D-Modem). -- `winport/macos9/getentropy.c` gives `getentropy()`. The C library of - mac-sdk calls it, but does not have it. The function uses the jitter - of the microsecond clock. These random numbers are not as strong as - those of a modern system. ## The library only diff --git a/external/D-Modem b/external/D-Modem index 01e1236..351268c 160000 --- a/external/D-Modem +++ b/external/D-Modem @@ -1 +1 @@ -Subproject commit 01e123692b23d114e70f54fcc547d4caa21a48f5 +Subproject commit 351268cd9c90d2597a2db184ebdaaf8100a6dc37 diff --git a/winport/CMakeLists.txt b/winport/CMakeLists.txt index e7e53ad..444da48 100644 --- a/winport/CMakeLists.txt +++ b/winport/CMakeLists.txt @@ -121,9 +121,6 @@ if(DMODEM_GUI_EMBED AND TARGET dmodem_embed) target_compile_definitions(dmodem-win32 PRIVATE DMODEM_GUI_EMBED) endif() if(MACOS9_TARGET) - # (getentropy(): mac-sdk's C library calls it but does not have it. - # See macos9/getentropy.c.) - target_sources(dmodem-win32 PRIVATE macos9/getentropy.c) # (cmake/macos9.cmake links with macapp.py: the C and C++ libraries of # mac-sdk, and the Toolbox. The cooperative threads are in its C # library.) diff --git a/winport/macos9/getentropy.c b/winport/macos9/getentropy.c deleted file mode 100644 index 8ef5452..0000000 --- a/winport/macos9/getentropy.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * getentropy.c - getentropy() for the classic Mac OS. - * - * The C library of clang-retro/mac-sdk declares getentropy() in - * , and its arc4random() and the std::random_device of its - * C++ library call it, but the library does not have it. libre makes - * its random numbers (SIP tags, SRTP keys) with arc4random(). - * - * The classic Mac OS has no source of random numbers. This function - * collects the jitter of the microsecond clock (Microseconds(), System - * 7.0 and later): the time of each sample changes with the interrupts, - * the other threads and the cache. It mixes the samples into a 64-bit - * state with the finalizer of SplitMix64. The result is not as strong - * as the random numbers of a modern system. - * - * Remove this file when mac-sdk's C library has getentropy(). - */ -#include -#include -#include -#include - -/* The number of clock samples for each byte of output */ -#define SAMPLES_PER_BYTE 16 - -/* Mixes v into the state *s, and gives the new state */ -static uint64_t mix(uint64_t *s, uint64_t v) -{ - uint64_t z = (*s += v + UINT64_C(0x9e3779b97f4a7c15)); - z = (z ^ (z >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); - z = (z ^ (z >> 27)) * UINT64_C(0x94d049bb133111eb); - *s = z ^ (z >> 31); - return *s; -} - -/* Gives the microsecond clock as one 64-bit value */ -static uint64_t micros(void) -{ - UnsignedWide w; - Microseconds(&w); - return ((uint64_t)w.hi << 32) | w.lo; -} - -/* Fills buf with len random bytes, at most 256. Gives 0, or -1 with - errno EIO when len is more than 256 (as on the BSDs). */ -int getentropy(void *buf, size_t len) -{ - static uint64_t state; - static uint32_t calls; - unsigned char *out = (unsigned char *)buf; - size_t i; - int j; - - if (len > 256) { - errno = EIO; - return -1; - } - mix(&state, ++calls); - mix(&state, (uint64_t)(uintptr_t)&i); - for (i = 0; i < len; i++) { - uint64_t prev = micros(), now; - for (j = 0; j < SAMPLES_PER_BYTE; j++) { - /* (a short wait, its length from the state, so that - the samples are not at a fixed interval) */ - volatile unsigned spin = (unsigned)(state & 63); - while (spin--) - ; - now = micros(); - mix(&state, now - prev); - prev = now; - } - out[i] = (unsigned char)(mix(&state, now) >> 56); - } - return 0; -}