66
66
#endif // OPENSSL_LINUX
67
67
68
68
#if defined(OPENSSL_APPLE )
69
+ #if __has_include (< CommonCrypto /CommonRandom .h > )
70
+ #define AWS_LC_HAVE_COMMON_CRYPTO
69
71
#include <CommonCrypto/CommonRandom.h>
72
+ #else
73
+ #define AWS_LC_USE_ARC4RANDOM
74
+ #endif
70
75
#endif
71
76
72
77
#if defined(OPENSSL_FREEBSD )
80
85
#endif
81
86
82
87
#if defined(OPENSSL_OPENBSD )
88
+ #define AWS_LC_USE_ARC4RANDOM
89
+ #endif
90
+
91
+ #if defined(AWS_LC_USE_ARC4RANDOM )
83
92
#include <stdlib.h>
84
93
#endif
85
94
@@ -250,16 +259,16 @@ static void init_once(void) {
250
259
}
251
260
#endif // USE_NR_getrandom
252
261
253
- #if defined(OPENSSL_APPLE )
262
+ #if defined(AWS_LC_HAVE_COMMON_CRYPTO )
254
263
// To get system randomness on MacOS and iOS we use |CCRandomGenerateBytes|
255
264
// function provided by Apple rather than /dev/urandom or |getentropy|
256
265
// function which is available on MacOS but not on iOS.
257
266
return ;
258
267
#endif
259
268
260
- #if defined(OPENSSL_OPENBSD )
269
+ #if defined(AWS_LC_USE_ARC4RANDOM )
261
270
// To get system randomness on OpenBSD we use |arc4random_buf| function
262
- // which is recommended to use for C APIs rather then /dev/urandom.
271
+ // which is recommended to use for C APIs rather than /dev/urandom.
263
272
// See https://man.openbsd.org/arc4random.3
264
273
return ;
265
274
#endif
@@ -350,7 +359,8 @@ static void wait_for_entropy(void) {
350
359
}
351
360
352
361
#if defined(BORINGSSL_FIPS ) && !defined(URANDOM_BLOCKS_FOR_ENTROPY ) && \
353
- !(defined(OPENSSL_APPLE ) || defined(OPENSSL_OPENBSD )) // On MacOS, iOS, and OpenBSD we don't use /dev/urandom.
362
+ !(defined(AWS_LC_HAVE_COMMON_CRYPTO ) || defined(AWS_LC_USE_ARC4RANDOM ))
363
+ // On MacOS, iOS, and OpenBSD we don't use /dev/urandom.
354
364
355
365
// In FIPS mode on platforms where urandom doesn't block at startup, we ensure
356
366
// that the kernel has sufficient entropy before continuing. This is
@@ -388,7 +398,7 @@ static int fill_with_entropy(uint8_t *out, size_t len, int block, int seed) {
388
398
return 1 ;
389
399
}
390
400
391
- #if defined(OPENSSL_APPLE )
401
+ #if defined(AWS_LC_HAVE_COMMON_CRYPTO )
392
402
// To get system randomness on MacOS and iOS we use |CCRandomGenerateBytes|
393
403
// rather than |getentropy| and /dev/urandom.
394
404
if (CCRandomGenerateBytes (out , len ) == kCCSuccess ) {
@@ -399,7 +409,7 @@ static int fill_with_entropy(uint8_t *out, size_t len, int block, int seed) {
399
409
}
400
410
#endif
401
411
402
- #if defined(OPENSSL_OPENBSD )
412
+ #if defined(AWS_LC_USE_ARC4RANDOM )
403
413
// Return value is void, no error to check
404
414
arc4random_buf (out , len );
405
415
return 1 ;
0 commit comments