@@ -383,42 +383,13 @@ static size_t read_urandom(void* buf, size_t n)
383383}
384384
385385#if defined(__APPLE__ )
386- #include <AvailabilityMacros.h>
387- #include <TargetConditionals.h>
388-
389- /* Define version macros if needed */
390- #ifndef MAC_OS_X_VERSION_MIN_REQUIRED
391- #define MAC_OS_X_VERSION_MIN_REQUIRED 0
392- #endif
393- #ifndef __IPHONE_OS_VERSION_MIN_REQUIRED
394- #define __IPHONE_OS_VERSION_MIN_REQUIRED 0
395- #endif
396- #ifndef __TV_OS_VERSION_MIN_REQUIRED
397- #define __TV_OS_VERSION_MIN_REQUIRED 0
398- #endif
399- #ifndef __WATCH_OS_VERSION_MIN_REQUIRED
400- #define __WATCH_OS_VERSION_MIN_REQUIRED 0
401- #endif
402-
403- #define CAN_USE_SECRANDOM () ( \
404- (TARGET_OS_OSX && MAC_OS_X_VERSION_MIN_REQUIRED >= 1070) || \
405- (TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || \
406- (TARGET_OS_TV && __TV_OS_VERSION_MIN_REQUIRED >= 90000) || \
407- (TARGET_OS_WATCH && __WATCH_OS_VERSION_MIN_REQUIRED >= 20000) \
408- )
409-
410- #if CAN_USE_SECRANDOM ()
411- #include <Security/SecRandom.h>
412- #endif
413-
414- #else /* !__APPLE__ */
415- #define CAN_USE_SECRANDOM () 0
386+ #include <CommonCrypto/CommonRandom.h>
416387#endif
417388
418389static size_t entropy (void * buf , size_t n )
419390{
420- #if defined(__APPLE__ ) && CAN_USE_SECRANDOM ()
421- if (SecRandomCopyBytes ( kSecRandomDefault , n , ( uint8_t * ) buf ) == 0 )
391+ #if defined(__APPLE__ )
392+ if (CCRandomGenerateBytes ( buf , n ) == kCCSuccess )
422393 return n ;
423394#elif defined(__linux__ ) && defined(SYS_getrandom )
424395 if (syscall (SYS_getrandom , buf , n , 0 ) == n )
0 commit comments