mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
AK: Use arc4random_buf() for Random on all BSDs
This commit is contained in:
parent
c223b65a69
commit
d93e916d0c
1 changed files with 2 additions and 6 deletions
|
@ -16,15 +16,11 @@
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(AK_OS_MACOS)
|
|
||||||
# include <sys/random.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
inline void fill_with_random([[maybe_unused]] Bytes bytes)
|
inline void fill_with_random([[maybe_unused]] Bytes bytes)
|
||||||
{
|
{
|
||||||
#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID)
|
#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID) || defined(AK_OS_BSD_GENERIC)
|
||||||
arc4random_buf(bytes.data(), bytes.size());
|
arc4random_buf(bytes.data(), bytes.size());
|
||||||
#elif defined(OSS_FUZZ)
|
#elif defined(OSS_FUZZ)
|
||||||
#else
|
#else
|
||||||
|
@ -33,7 +29,7 @@ inline void fill_with_random([[maybe_unused]] Bytes bytes)
|
||||||
byte = rand();
|
byte = rand();
|
||||||
};
|
};
|
||||||
|
|
||||||
# if defined(__unix__) or defined(AK_OS_MACOS)
|
# if defined(__unix__)
|
||||||
// The maximum permitted value for the getentropy length argument.
|
// The maximum permitted value for the getentropy length argument.
|
||||||
static constexpr size_t getentropy_length_limit = 256;
|
static constexpr size_t getentropy_length_limit = 256;
|
||||||
auto iterations = bytes.size() / getentropy_length_limit;
|
auto iterations = bytes.size() / getentropy_length_limit;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue