Skip to content

Commit dd508dc

Browse files
committed
Fix issue #118
Check for _tvOS_ or _watchOS_ to call `getentropy` (instead of using `syscall`)
1 parent d2be01b commit dd508dc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/chacha20poly1305.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,20 @@ static size_t read_urandom(void* buf, size_t n)
370370
return 0;
371371
}
372372

373+
#if defined(__APPLE__)
374+
#include "TargetConditionals.h"
375+
#endif
376+
373377
#if defined(__APPLE__) && defined(__MAC_10_12) && !defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
374378
#include <sys/random.h>
375379
#endif
376380

377381
static size_t entropy(void* buf, size_t n)
378382
{
379-
#if defined(__APPLE__) && defined(__MAC_10_12) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_12
383+
#if defined(__APPLE__) && ((defined(__MAC_10_12) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_12) || TARGET_OS_TV || TARGET_OS_WATCH)
384+
#if TARGET_OS_TV || TARGET_OS_WATCH
385+
extern int getentropy(void* buffer, size_t buflen);
386+
#endif
380387
if (getentropy(buf, n) == 0)
381388
return n;
382389
#elif defined(__linux__) && defined(SYS_getrandom)

0 commit comments

Comments
 (0)