Use CommonRandom if available
This commit is contained in:
parent
a85ed626f1
commit
4ea96f1d4f
Notes:
git
2021-03-19 16:41:31 +09:00
@ -3634,7 +3634,8 @@ AS_CASE(["$target_os"],
|
|||||||
RUBY_APPEND_OPTION(CFLAGS, -pipe)
|
RUBY_APPEND_OPTION(CFLAGS, -pipe)
|
||||||
AC_COMPILE_IFELSE([
|
AC_COMPILE_IFELSE([
|
||||||
AC_LANG_BOOL_COMPILE_TRY([@%:@include <AvailabilityMacros.h>],
|
AC_LANG_BOOL_COMPILE_TRY([@%:@include <AvailabilityMacros.h>],
|
||||||
[MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7])],
|
[MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 &&
|
||||||
|
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10])],
|
||||||
[dnl
|
[dnl
|
||||||
RUBY_APPEND_OPTION(XLDFLAGS, [-framework Security])
|
RUBY_APPEND_OPTION(XLDFLAGS, [-framework Security])
|
||||||
RUBY_APPEND_OPTION(LIBRUBYARG_STATIC, [-framework Security])
|
RUBY_APPEND_OPTION(LIBRUBYARG_STATIC, [-framework Security])
|
||||||
|
21
random.c
21
random.c
@ -495,20 +495,35 @@ fill_random_bytes_urandom(void *seed, size_t size)
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#elif defined MAC_OS_X_VERSION_10_7 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
|
#elif defined MAC_OS_X_VERSION_10_7 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
|
||||||
#include <Security/SecRandom.h>
|
|
||||||
|
# if defined MAC_OS_X_VERSION_10_10 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
|
||||||
|
# include <CommonCrypto/CommonRandom.h>
|
||||||
|
# define USE_COMMON_RANDOM 1
|
||||||
|
# else
|
||||||
|
# include <Security/SecRandom.h>
|
||||||
|
# define USE_COMMON_RANDOM 0
|
||||||
|
# endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fill_random_bytes_syscall(void *seed, size_t size, int unused)
|
fill_random_bytes_syscall(void *seed, size_t size, int unused)
|
||||||
{
|
{
|
||||||
int status = SecRandomCopyBytes(kSecRandomDefault, size, seed);
|
#if USE_COMMON_RANDOM
|
||||||
|
int failed = CCRandomGenerateBytes(seed, size) != kCCSuccess;
|
||||||
|
#else
|
||||||
|
int failed = SecRandomCopyBytes(kSecRandomDefault, size, seed) != errSecSuccess;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (status != errSecSuccess) {
|
if (failed) {
|
||||||
# if 0
|
# if 0
|
||||||
|
# if USE_COMMON_RANDOM
|
||||||
|
/* How to get the error message? */
|
||||||
|
# else
|
||||||
CFStringRef s = SecCopyErrorMessageString(status, NULL);
|
CFStringRef s = SecCopyErrorMessageString(status, NULL);
|
||||||
const char *m = s ? CFStringGetCStringPtr(s, kCFStringEncodingUTF8) : NULL;
|
const char *m = s ? CFStringGetCStringPtr(s, kCFStringEncodingUTF8) : NULL;
|
||||||
fprintf(stderr, "SecRandomCopyBytes failed: %d: %s\n", status,
|
fprintf(stderr, "SecRandomCopyBytes failed: %d: %s\n", status,
|
||||||
m ? m : "unknown");
|
m ? m : "unknown");
|
||||||
if (s) CFRelease(s);
|
if (s) CFRelease(s);
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user