mirror of
https://github.com/D-Modem/gui.git
synced 2026-11-28 14:19:58 -08:00
Remove the getentropy() stand-in for Mac OS 9
mac-sdk's C library now has getentropy(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRVR36R8PgTTMQiuWkQ
This commit is contained in:
4 files changed
+1
-83
No files matched your search
@@ -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
|
||||
|
||||
|
||||
Vendored
+1
-1
Submodule external/D-Modem updated: 01e123692b...351268cd9c.
@@ -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.)
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* getentropy.c - getentropy() for the classic Mac OS.
|
||||
*
|
||||
* The C library of clang-retro/mac-sdk declares getentropy() in
|
||||
* <unistd.h>, 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 <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <Timer.h>
|
||||
|
||||
/* 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;
|
||||
}
|
||||
Reference in new issue
Block a user