# HG changeset patch
# User Bob Owen <bobowencode@gmail.com>
Remove boringssl option from rand_util.

diff --git a/base/rand_util.h b/base/rand_util.h
--- a/base/rand_util.h
+++ b/base/rand_util.h
@@ -18,31 +18,35 @@
 #include "base/base_export.h"
 #include "base/compiler_specific.h"
 #include "base/containers/span.h"
 #include "base/gtest_prod_util.h"
 #include "base/numerics/clamped_math.h"
 #include "base/numerics/safe_conversions.h"
 #include "base/time/time.h"
 #include "build/build_config.h"
+#if !defined(MOZ_SANDBOX)
 #include "third_party/boringssl/src/include/openssl/rand.h"
+#endif
 
 namespace memory_simulator {
 class MemoryHolder;
 }
 
 namespace gwp_asan::internal {
 class ExtremeLightweightDetectorQuarantineBranch;
 }
 
 namespace base {
 
 namespace internal {
 
+#if !defined(MOZ_SANDBOX)
 void ConfigureBoringSSLBackedRandBytesFieldTrial();
+#endif
 
 // Returns a random double in range [0, 1). For use in allocator shim to avoid
 // infinite recursion. Thread-safe.
 BASE_EXPORT double RandDoubleAvoidAllocation();
 
 }  // namespace internal
 
 namespace test {
@@ -186,31 +190,33 @@ class RandomBitGenerator {
   static constexpr result_type min() { return 0; }
   static constexpr result_type max() { return UINT64_MAX; }
   result_type operator()() const { return RandUint64(); }
 
   RandomBitGenerator() = default;
   ~RandomBitGenerator() = default;
 };
 
+#if !defined(MOZ_SANDBOX)
 class NonAllocatingRandomBitGenerator {
  public:
   using result_type = uint64_t;
   static constexpr result_type min() { return 0; }
   static constexpr result_type max() { return UINT64_MAX; }
   result_type operator()() const {
     uint64_t result;
     RAND_get_system_entropy_for_custom_prng(reinterpret_cast<uint8_t*>(&result),
                                             sizeof(result));
     return result;
   }
 
   NonAllocatingRandomBitGenerator() = default;
   ~NonAllocatingRandomBitGenerator() = default;
 };
+#endif
 
 // Shuffles [first, last) randomly. Thread-safe.
 template <typename Itr>
 void RandomShuffle(Itr first, Itr last) {
   std::shuffle(first, last, RandomBitGenerator());
 }
 
 #if BUILDFLAG(IS_POSIX)
diff --git a/base/rand_util_win.cc b/base/rand_util_win.cc
--- a/base/rand_util_win.cc
+++ b/base/rand_util_win.cc
@@ -10,26 +10,29 @@
 #include <stdint.h>
 
 #include <algorithm>
 #include <atomic>
 #include <limits>
 
 #include "base/check.h"
 #include "base/feature_list.h"
+#if !defined(MOZ_SANDBOX)
 #include "third_party/boringssl/src/include/openssl/rand.h"
+#endif
 
 // Prototype for ProcessPrng.
 // See: https://learn.microsoft.com/en-us/windows/win32/seccng/processprng
 extern "C" {
 BOOL WINAPI ProcessPrng(PBYTE pbData, SIZE_T cbData);
 }
 
 namespace base {
 
+#if !defined(MOZ_SANDBOX)
 namespace internal {
 
 namespace {
 
 // The BoringSSl helpers are duplicated in rand_util_fuchsia.cc and
 // rand_util_posix.cc.
 std::atomic<bool> g_use_boringssl;
 
@@ -42,37 +45,40 @@ void ConfigureBoringSSLBackedRandBytesFieldTrial() {
                         std::memory_order_relaxed);
 }
 
 bool UseBoringSSLForRandBytes() {
   return g_use_boringssl.load(std::memory_order_relaxed);
 }
 
 }  // namespace internal
+#endif
 
 namespace {
 
 // Import bcryptprimitives!ProcessPrng rather than cryptbase!RtlGenRandom to
 // avoid opening a handle to \\Device\KsecDD in the renderer.
 decltype(&ProcessPrng) GetProcessPrng() {
   HMODULE hmod = LoadLibraryW(L"bcryptprimitives.dll");
   CHECK(hmod);
   decltype(&ProcessPrng) process_prng_fn =
       reinterpret_cast<decltype(&ProcessPrng)>(
           GetProcAddress(hmod, "ProcessPrng"));
   CHECK(process_prng_fn);
   return process_prng_fn;
 }
 
 void RandBytesInternal(span<uint8_t> output, bool avoid_allocation) {
+#if !defined(MOZ_SANDBOX)
   if (!avoid_allocation && internal::UseBoringSSLForRandBytes()) {
     // BoringSSL's RAND_bytes always returns 1. Any error aborts the program.
     (void)RAND_bytes(output.data(), output.size());
     return;
   }
+#endif
 
   static decltype(&ProcessPrng) process_prng_fn = GetProcessPrng();
   BOOL success =
       process_prng_fn(static_cast<BYTE*>(output.data()), output.size());
   // ProcessPrng is documented to always return TRUE.
   CHECK(success);
 }
 
