--- ./crypto/rand/rand_unix.c.orig	2021-08-24 06:38:47.000000000 -0700
+++ ./crypto/rand/rand_unix.c	2021-09-04 19:21:00.000000000 -0700
@@ -34,9 +34,6 @@
 #if defined(__OpenBSD__)
 # include <sys/param.h>
 #endif
-#if defined(__APPLE__)
-# include <CommonCrypto/CommonRandom.h>
-#endif
 
 #if defined(OPENSSL_SYS_UNIX) || defined(__DJGPP__)
 # include <sys/types.h>
@@ -381,7 +378,7 @@ static ssize_t syscall_random(void *buf,
         if (errno != ENOSYS)
             return -1;
     }
-#  elif defined(__APPLE__)
+#  elif defined(OPENSSL_APPLE_CRYPTO_RANDOM)
     if (CCRandomGenerateBytes(buf, buflen) == kCCSuccess)
 	    return (ssize_t)buflen;
 
--- ./include/crypto/rand.h.orig	2021-08-24 06:38:47.000000000 -0700
+++ ./include/crypto/rand.h	2021-09-04 19:21:00.000000000 -0700
@@ -20,6 +20,15 @@
 
 # include <openssl/rand.h>
 
+# if defined(__APPLE__) && !defined(OPENSSL_NO_APPLE_CRYPTO_RANDOM)
+#  if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200 || \
+      __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
+#   define OPENSSL_APPLE_CRYPTO_RANDOM 1
+#   include <CommonCrypto/CommonCryptoError.h>
+#   include <CommonCrypto/CommonRandom.h>
+#  endif
+# endif
+
 /* forward declaration */
 typedef struct rand_pool_st RAND_POOL;
 
