Skip to content

Commit

Permalink
Fix issue #118
Browse files Browse the repository at this point in the history
Check for _tvOS_ or _watchOS_ to call `getentropy` (instead of using `syscall`)
  • Loading branch information
utelle committed Oct 1, 2023
1 parent d2be01b commit dd508dc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/chacha20poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,20 @@ static size_t read_urandom(void* buf, size_t n)
return 0;
}

#if defined(__APPLE__)
#include "TargetConditionals.h"
#endif

#if defined(__APPLE__) && defined(__MAC_10_12) && !defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#include <sys/random.h>
#endif

static size_t entropy(void* buf, size_t n)
{
#if defined(__APPLE__) && defined(__MAC_10_12) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_12
#if defined(__APPLE__) && ((defined(__MAC_10_12) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_12) || TARGET_OS_TV || TARGET_OS_WATCH)
#if TARGET_OS_TV || TARGET_OS_WATCH
extern int getentropy(void* buffer, size_t buflen);
#endif
if (getentropy(buf, n) == 0)
return n;
#elif defined(__linux__) && defined(SYS_getrandom)
Expand Down

0 comments on commit dd508dc

Please sign in to comment.