Skip to content

Commit 2f8a02e

Browse files
committed
adding code doc
1 parent af551f6 commit 2f8a02e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ext/random/random.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,28 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw)
506506
}
507507
#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001 && __NetBSD_Version__ < 1000000000) || \
508508
defined(__APPLE__) || defined(__GLIBC__))
509+
/*
510+
* OpenBSD until there is a valid equivalent
511+
* or NetBSD before the 10.x release
512+
* falls back to arc4random_buf
513+
* giving a decent output but also
514+
* being implemented in the userland only
515+
* does not necessarily provide the highest
516+
* performance.
517+
* Older macOs releases fall also into this
518+
* category for reasons explained above.
519+
*/
509520
arc4random_buf(bytes, size);
510521
#else
511522
size_t read_bytes = 0;
512523
ssize_t n;
513524
# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || \
514525
defined(__sun) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000)
515-
/* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD getrandom(2) function*/
516-
/* Keep reading until we get enough entropy */
526+
/* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD/NetBSD getrandom(2) function
527+
* Being a syscall, implemented in the kernel, getrandom offers higher performance
528+
* compared to the arc4random api albeit a fallback to /dev/urandom is considered.
529+
* Keep reading until we get enough entropy
530+
*/
517531
while (read_bytes < size) {
518532
errno = 0;
519533

0 commit comments

Comments
 (0)