summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-31 09:56:24 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-31 09:56:24 (GMT)
commit68f9d7b444cf7f870f2163c00a491e224a2a77a2 (patch)
tree4ae8ed1c3efc691ff47cc22aae336122c7704d96 /random.c
parent070d731bddd537cb1b0f470bd82cc497fc04520f (diff)
random.c: SecRandomCopyBytes
* random.c (fill_random_bytes_syscall): use SecRandomCopyBytes in Security framework on macOS 10.7 or later. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/random.c b/random.c
index 0b0038c..4add886 100644
--- a/random.c
+++ b/random.c
@@ -470,6 +470,26 @@ fill_random_bytes_urandom(void *seed, size_t size)
#endif
#if 0
+#elif defined __APPLE__ && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
+#include <Security/Security.h>
+
+static int
+fill_random_bytes_syscall(void *seed, size_t size, int unused)
+{
+ int status = SecRandomCopyBytes(kSecRandomDefault, size, seed);
+
+ if (status != errSecSuccess) {
+# if 0
+ CFStringRef s = SecCopyErrorMessageString(status, NULL);
+ const char *m = s ? CFStringGetCStringPtr(s, kCFStringEncodingUTF8) : NULL;
+ fprintf(stderr, "SecRandomCopyBytes failed: %d: %s\n", status,
+ m ? m : "unknown");
+ if (s) CFRelease(s);
+# endif
+ return -1;
+ }
+ return 0;
+}
#elif defined(HAVE_ARC4RANDOM_BUF)
static int
fill_random_bytes_syscall(void *buf, size_t size, int unused)