61 lines
1.9 KiB
C++
61 lines
1.9 KiB
C++
--- base/rand_util_posix.cc.orig 2026-04-28 21:06:17 UTC
|
|
+++ base/rand_util_posix.cc
|
|
@@ -24,7 +24,7 @@
|
|
#include "build/build_config.h"
|
|
#include "third_party/boringssl/src/include/openssl/rand.h"
|
|
|
|
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
|
+#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !BUILDFLAG(IS_BSD)
|
|
#include "third_party/lss/linux_syscall_support.h"
|
|
#elif BUILDFLAG(IS_MAC)
|
|
// TODO(crbug.com/40641285): Waiting for this header to appear in the iOS SDK.
|
|
@@ -36,6 +36,7 @@ namespace {
|
|
|
|
namespace {
|
|
|
|
+#if !BUILDFLAG(IS_BSD)
|
|
#if BUILDFLAG(IS_AIX)
|
|
// AIX has no 64-bit support for O_CLOEXEC.
|
|
static constexpr int kOpenFlags = O_RDONLY;
|
|
@@ -60,8 +61,9 @@ class URandomFd {
|
|
private:
|
|
const int fd_;
|
|
};
|
|
+#endif
|
|
|
|
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
|
+#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)) && !BUILDFLAG(IS_BSD)
|
|
|
|
bool KernelSupportsGetRandom() {
|
|
return base::SysInfo::KernelVersionNumber::Current() >=
|
|
@@ -114,6 +116,7 @@ void RandBytesInternal(span<uint8_t> output, bool avoi
|
|
namespace {
|
|
|
|
void RandBytesInternal(span<uint8_t> output, bool avoid_allocation) {
|
|
+#if !BUILDFLAG(IS_BSD)
|
|
// The BoringSSL experiment takes priority over everything else.
|
|
if (!avoid_allocation && internal::UseBoringSSLForRandBytes()) {
|
|
// BoringSSL's RAND_bytes always returns 1. Any error aborts the program.
|
|
@@ -144,6 +147,9 @@ void RandBytesInternal(span<uint8_t> output, bool avoi
|
|
const int urandom_fd = GetUrandomFD();
|
|
const bool success = ReadFromFD(urandom_fd, as_writable_chars(output));
|
|
CHECK(success);
|
|
+#else
|
|
+ arc4random_buf(output.data(), output.size());
|
|
+#endif
|
|
}
|
|
|
|
} // namespace
|
|
@@ -163,9 +169,11 @@ void RandBytes(span<uint8_t> output) {
|
|
RandBytesInternal(output, /*avoid_allocation=*/false);
|
|
}
|
|
|
|
+#if !BUILDFLAG(IS_BSD)
|
|
int GetUrandomFD() {
|
|
static NoDestructor<URandomFd> urandom_fd;
|
|
return urandom_fd->fd();
|
|
}
|
|
+#endif
|
|
|
|
} // namespace base
|