mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
random: Do not trust arc4random_buf() on glibc (#10390)
This effectively reverts #8984. As discussed in #10327 which will enable the use of the getrandom(2) syscall on NetBSD instead of relying on the userland arc4random_buf(), the CSPRNG should prioritize security over speed [1] and history has shown that userland implementations unavoidably fall short on the security side. In fact the glibc implementation is a thin wrapper around the syscall due to security concerns and thus does not provide any benefit over just calling getrandom(2) ourselves. Even without any performance optimizations the CSPRNG should be plenty fast for the vast majority of applications, because they often only need a few bytes of randomness to generate a session ID. If speed is desired, the OO API offers faster, but non-cryptographically secure engines.
This commit is contained in:
parent
81732056fe
commit
57b362b7a9
2 changed files with 4 additions and 1 deletions
|
@ -505,7 +505,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw)
|
|||
}
|
||||
return FAILURE;
|
||||
}
|
||||
#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001) || defined(__APPLE__) || defined(__GLIBC__))
|
||||
#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001) || defined(__APPLE__))
|
||||
arc4random_buf(bytes, size);
|
||||
#else
|
||||
size_t read_bytes = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue