Source code
Revision control
Copy as Markdown
Other Tools
Remove third-party dependencies in rand_util.h and friends
We remove dependencies on chromium's third_party/lss and
third_party/boringssl/src/include/openssl.
---
base/rand_util.h | 6 ++++++
base/rand_util_posix.cc | 16 ++++++++++++++++
base/rand_util_win.cc | 6 ++++++
3 files changed, 28 insertions(+)
diff --git a/base/rand_util.h b/base/rand_util.h
index c9dd1249660c..c9ffa1d588fc 100644
--- a/base/rand_util.h
+++ b/base/rand_util.h
@@ -16,9 +16,11 @@
#include "base/gtest_prod_util.h"
#include "build/build_config.h"
+#if !defined(MOZ_ZUCCHINI)
#if !BUILDFLAG(IS_NACL)
#include "third_party/boringssl/src/include/openssl/rand.h"
#endif
+#endif // !defined(MOZ_ZUCCHINI)
namespace memory_simulator {
class MemoryHolder;
@@ -34,9 +36,11 @@ namespace internal {
void ConfigureRandBytesFieldTrial();
#endif
+#if !defined(MOZ_ZUCCHINI)
#if !BUILDFLAG(IS_NACL)
void ConfigureBoringSSLBackedRandBytesFieldTrial();
#endif
+#endif // !defined(MOZ_ZUCCHINI)
// Returns a random double in range [0, 1). For use in allocator shim to avoid
// infinite recursion. Thread-safe.
@@ -97,6 +101,7 @@ class RandomBitGenerator {
~RandomBitGenerator() = default;
};
+#if !defined(MOZ_ZUCCHINI)
#if !BUILDFLAG(IS_NACL)
class NonAllocatingRandomBitGenerator {
public:
@@ -114,6 +119,7 @@ class NonAllocatingRandomBitGenerator {
~NonAllocatingRandomBitGenerator() = default;
};
#endif
+#endif // !defined(MOZ_ZUCCHINI)
// Shuffles [first, last) randomly. Thread-safe.
template <typename Itr>
diff --git a/base/rand_util_posix.cc b/base/rand_util_posix.cc
index 4982a4556f24..3c88dec2abf1 100644
--- a/base/rand_util_posix.cc
+++ b/base/rand_util_posix.cc
@@ -14,26 +14,34 @@
#include "base/check.h"
#include "base/compiler_specific.h"
+#if !defined(MOZ_ZUCCHINI)
#include "base/feature_list.h"
+#endif // !defined(MOZ_ZUCCHINI)
#include "base/files/file_util.h"
+#if !defined(MOZ_ZUCCHINI)
#include "base/metrics/histogram_macros.h"
+#endif // !defined(MOZ_ZUCCHINI)
#include "base/no_destructor.h"
#include "base/posix/eintr_wrapper.h"
#include "base/time/time.h"
#include "build/build_config.h"
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !BUILDFLAG(IS_NACL)
+#if !defined(MOZ_ZUCCHINI)
#include "third_party/lss/linux_syscall_support.h"
+#endif // !defined(MOZ_ZUCCHINI)
#elif BUILDFLAG(IS_MAC)
// TODO(crbug.com/995996): Waiting for this header to appear in the iOS SDK.
// (See below.)
#include <sys/random.h>
#endif
+#if !defined(MOZ_ZUCCHINI)
#if !BUILDFLAG(IS_NACL)
#include "third_party/boringssl/src/include/openssl/crypto.h"
#include "third_party/boringssl/src/include/openssl/rand.h"
#endif
+#endif // !defined(MOZ_ZUCCHINI)
namespace base {
@@ -64,6 +72,7 @@ class URandomFd {
const int fd_;
};
+#if !defined(MOZ_ZUCCHINI)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
BUILDFLAG(IS_ANDROID)) && \
!BUILDFLAG(IS_NACL)
@@ -136,9 +145,11 @@ bool UseGetrandom() {
return true;
}
#endif
+#endif // !defined(MOZ_ZUCCHINI)
} // namespace
+#if !defined(MOZ_ZUCCHINI)
namespace internal {
#if BUILDFLAG(IS_ANDROID)
@@ -172,10 +183,12 @@ bool UseBoringSSLForRandBytes() {
#endif
} // namespace internal
+#endif // !defined(MOZ_ZUCCHINI)
namespace {
void RandBytes(void* output, size_t output_length, bool avoid_allocation) {
+#if !defined(MOZ_ZUCCHINI)
#if !BUILDFLAG(IS_NACL)
// The BoringSSL experiment takes priority over everything else.
if (!avoid_allocation && internal::UseBoringSSLForRandBytes()) {
@@ -186,9 +199,11 @@ void RandBytes(void* output, size_t output_length, bool avoid_allocation) {
return;
}
#endif
+#endif // !defined(MOZ_ZUCCHINI)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
BUILDFLAG(IS_ANDROID)) && \
!BUILDFLAG(IS_NACL)
+#if !defined(MOZ_ZUCCHINI)
if (avoid_allocation || UseGetrandom()) {
// On Android it is mandatory to check that the kernel _version_ has the
// support for a syscall before calling. The same check is made on Linux and
@@ -197,6 +212,7 @@ void RandBytes(void* output, size_t output_length, bool avoid_allocation) {
if (kernel_has_support && GetRandomSyscall(output, output_length))
return;
}
+#endif // !defined(MOZ_ZUCCHINI)
#elif BUILDFLAG(IS_MAC)
// TODO(crbug.com/995996): Enable this on iOS too, when sys/random.h arrives
// in its SDK.
diff --git a/base/rand_util_win.cc b/base/rand_util_win.cc
index 549f4362af8b..c0df55734def 100644
--- a/base/rand_util_win.cc
+++ b/base/rand_util_win.cc
@@ -14,9 +14,11 @@
#include <limits>
#include "base/check.h"
+#if !defined(MOZ_ZUCCHINI)
#include "base/feature_list.h"
#include "third_party/boringssl/src/include/openssl/crypto.h"
#include "third_party/boringssl/src/include/openssl/rand.h"
+#endif // !defined(MOZ_ZUCCHINI)
// Prototype for ProcessPrng.
@@ -26,6 +28,7 @@ BOOL WINAPI ProcessPrng(PBYTE pbData, SIZE_T cbData);
namespace base {
+#if !defined(MOZ_ZUCCHINI)
namespace internal {
namespace {
@@ -50,6 +53,7 @@ bool UseBoringSSLForRandBytes() {
}
} // namespace internal
+#endif // !defined(MOZ_ZUCCHINI)
namespace {
@@ -66,6 +70,7 @@ decltype(&ProcessPrng) GetProcessPrng() {
}
void RandBytes(void* output, size_t output_length, bool avoid_allocation) {
+#if !defined(MOZ_ZUCCHINI)
if (!avoid_allocation && internal::UseBoringSSLForRandBytes()) {
// Ensure BoringSSL is initialized so it can use things like RDRAND.
CRYPTO_library_init();
@@ -73,6 +78,7 @@ void RandBytes(void* output, size_t output_length, bool avoid_allocation) {
(void)RAND_bytes(static_cast<uint8_t*>(output), output_length);
return;
}
+#endif // !defined(MOZ_ZUCCHINI)
static decltype(&ProcessPrng) process_prng_fn = GetProcessPrng();
BOOL success = process_prng_fn(static_cast<BYTE*>(output), output_length);
--
2.42.0.windows.2