Commit 78baca9f authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Remove wtf/cryptographically_random_number.h.

Use base/ and/or crypto/ directly, instead.

Change-Id: I7fecadacb4bb3c0cfc0f144ebc284b47349621df
Reviewed-on: https://chromium-review.googlesource.com/1071878Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561627}
parent c3daaae9
...@@ -12,6 +12,7 @@ include_rules = [ ...@@ -12,6 +12,7 @@ include_rules = [
"+base/memory/weak_ptr.h", "+base/memory/weak_ptr.h",
"+base/metrics/histogram_macros.h", "+base/metrics/histogram_macros.h",
"+base/optional.h", "+base/optional.h",
"+base/rand_util.h",
"+base/sequenced_task_runner.h", "+base/sequenced_task_runner.h",
"+base/single_thread_task_runner.h", "+base/single_thread_task_runner.h",
"+base/stl_util.h", "+base/stl_util.h",
......
...@@ -24,4 +24,8 @@ blink_modules_sources("crypto") { ...@@ -24,4 +24,8 @@ blink_modules_sources("crypto") {
"worker_global_scope_crypto.cc", "worker_global_scope_crypto.cc",
"worker_global_scope_crypto.h", "worker_global_scope_crypto.h",
] ]
deps = [
"//crypto",
]
} }
include_rules = [ include_rules = [
"+crypto",
"-third_party/blink/renderer/modules", "-third_party/blink/renderer/modules",
"+third_party/blink/renderer/modules/crypto", "+third_party/blink/renderer/modules/crypto",
"+third_party/blink/renderer/modules/modules_export.h", "+third_party/blink/renderer/modules/modules_export.h",
......
...@@ -28,10 +28,10 @@ ...@@ -28,10 +28,10 @@
#include "third_party/blink/renderer/modules/crypto/crypto.h" #include "third_party/blink/renderer/modules/crypto/crypto.h"
#include "crypto/random.h"
#include "third_party/blink/renderer/bindings/core/v8/exception_state.h" #include "third_party/blink/renderer/bindings/core/v8/exception_state.h"
#include "third_party/blink/renderer/core/dom/exception_code.h" #include "third_party/blink/renderer/core/dom/exception_code.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/platform/wtf/cryptographically_random_number.h"
namespace blink { namespace blink {
...@@ -71,8 +71,7 @@ NotShared<DOMArrayBufferView> Crypto::getRandomValues( ...@@ -71,8 +71,7 @@ NotShared<DOMArrayBufferView> Crypto::getRandomValues(
array.View()->byteLength())); array.View()->byteLength()));
return NotShared<DOMArrayBufferView>(nullptr); return NotShared<DOMArrayBufferView>(nullptr);
} }
CryptographicallyRandomValues(array.View()->BaseAddress(), crypto::RandBytes(array.View()->BaseAddress(), array.View()->byteLength());
array.View()->byteLength());
return array; return array;
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/modules/csspaint/paint_worklet.h" #include "third_party/blink/renderer/modules/csspaint/paint_worklet.h"
#include "base/rand_util.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
...@@ -11,7 +12,6 @@ ...@@ -11,7 +12,6 @@
#include "third_party/blink/renderer/modules/csspaint/css_paint_definition.h" #include "third_party/blink/renderer/modules/csspaint/css_paint_definition.h"
#include "third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope.h" #include "third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope.h"
#include "third_party/blink/renderer/platform/graphics/image.h" #include "third_party/blink/renderer/platform/graphics/image.h"
#include "third_party/blink/renderer/platform/wtf/cryptographically_random_number.h"
namespace blink { namespace blink {
...@@ -79,11 +79,11 @@ int PaintWorklet::GetPaintsBeforeSwitching() { ...@@ -79,11 +79,11 @@ int PaintWorklet::GetPaintsBeforeSwitching() {
// according to the actual paints per frame. For example, if we found that // according to the actual paints per frame. For example, if we found that
// there are typically ~1000 paints in each frame, we'd want to set the number // there are typically ~1000 paints in each frame, we'd want to set the number
// to average at 500. // to average at 500.
return CryptographicallyRandomNumber() % kMaxPaintCountToSwitch; return base::RandInt(0, kMaxPaintCountToSwitch - 1);
} }
size_t PaintWorklet::SelectNewGlobalScope() { size_t PaintWorklet::SelectNewGlobalScope() {
return CryptographicallyRandomNumber() % kNumGlobalScopes; return static_cast<size_t>(base::RandGenerator(kNumGlobalScopes));
} }
scoped_refptr<Image> PaintWorklet::Paint(const String& name, scoped_refptr<Image> PaintWorklet::Paint(const String& name,
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "third_party/blink/renderer/modules/csspaint/css_paint_definition.h" #include "third_party/blink/renderer/modules/csspaint/css_paint_definition.h"
#include "third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope.h" #include "third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope.h"
#include "third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope_proxy.h" #include "third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope_proxy.h"
#include "third_party/blink/renderer/platform/wtf/cryptographically_random_number.h"
namespace blink { namespace blink {
class TestPaintWorklet : public PaintWorklet { class TestPaintWorklet : public PaintWorklet {
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include "third_party/blink/renderer/platform/text/quoted_printable.h" #include "third_party/blink/renderer/platform/text/quoted_printable.h"
#include "third_party/blink/renderer/platform/weborigin/scheme_registry.h" #include "third_party/blink/renderer/platform/weborigin/scheme_registry.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/cryptographically_random_number.h"
#include "third_party/blink/renderer/platform/wtf/date_math.h" #include "third_party/blink/renderer/platform/wtf/date_math.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h" #include "third_party/blink/renderer/platform/wtf/text/base64.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "third_party/blink/renderer/platform/network/form_data_encoder.h" #include "third_party/blink/renderer/platform/network/form_data_encoder.h"
#include <limits> #include <limits>
#include "third_party/blink/renderer/platform/wtf/cryptographically_random_number.h" #include "base/rand_util.h"
#include "third_party/blink/renderer/platform/wtf/hex_number.h" #include "third_party/blink/renderer/platform/wtf/hex_number.h"
#include "third_party/blink/renderer/platform/wtf/text/cstring.h" #include "third_party/blink/renderer/platform/wtf/text/cstring.h"
#include "third_party/blink/renderer/platform/wtf/text/text_encoding.h" #include "third_party/blink/renderer/platform/wtf/text/text_encoding.h"
...@@ -120,17 +120,12 @@ Vector<char> FormDataEncoder::GenerateUniqueBoundaryString() { ...@@ -120,17 +120,12 @@ Vector<char> FormDataEncoder::GenerateUniqueBoundaryString() {
Append(boundary, "----WebKitFormBoundary"); Append(boundary, "----WebKitFormBoundary");
// Append 16 random 7bit ascii AlphaNumeric characters. // Append 16 random 7bit ascii AlphaNumeric characters.
Vector<char> random_bytes; char random_bytes[16];
base::RandBytes(random_bytes, sizeof(random_bytes));
for (unsigned i = 0; i < 4; ++i) { for (char& c : random_bytes)
uint32_t randomness = CryptographicallyRandomNumber(); c = kAlphaNumericEncodingMap[c & 0x3F];
random_bytes.push_back(kAlphaNumericEncodingMap[(randomness >> 24) & 0x3F]); boundary.Append(random_bytes, sizeof(random_bytes));
random_bytes.push_back(kAlphaNumericEncodingMap[(randomness >> 16) & 0x3F]);
random_bytes.push_back(kAlphaNumericEncodingMap[(randomness >> 8) & 0x3F]);
random_bytes.push_back(kAlphaNumericEncodingMap[randomness & 0x3F]);
}
boundary.AppendVector(random_bytes);
boundary.push_back( boundary.push_back(
0); // Add a 0 at the end so we can use this as a C-style string. 0); // Add a 0 at the end so we can use this as a C-style string.
return boundary; return boundary;
......
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
#include "third_party/blink/renderer/platform/scheduler/base/task_queue_manager.h" #include "third_party/blink/renderer/platform/scheduler/base/task_queue_manager.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl.h" #include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl.h"
#include "third_party/blink/renderer/platform/wtf/allocator/partitions.h" #include "third_party/blink/renderer/platform/wtf/allocator/partitions.h"
#include "third_party/blink/renderer/platform/wtf/cryptographically_random_number.h"
#include "third_party/blink/renderer/platform/wtf/wtf.h" #include "third_party/blink/renderer/platform/wtf/wtf.h"
namespace blink { namespace blink {
......
...@@ -5,16 +5,14 @@ ...@@ -5,16 +5,14 @@
#include "third_party/blink/renderer/platform/time_clamper.h" #include "third_party/blink/renderer/platform/time_clamper.h"
#include "base/bit_cast.h" #include "base/bit_cast.h"
#include "base/rand_util.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/cryptographically_random_number.h"
#include <cmath> #include <cmath>
namespace blink { namespace blink {
TimeClamper::TimeClamper() { TimeClamper::TimeClamper() : secret_(base::RandUint64()) {}
CryptographicallyRandomValues(&secret_, sizeof(secret_));
}
double TimeClamper::ClampTimeResolution(double time_seconds) const { double TimeClamper::ClampTimeResolution(double time_seconds) const {
DCHECK_GE(time_seconds, 0); DCHECK_GE(time_seconds, 0);
......
...@@ -66,8 +66,6 @@ jumbo_component("wtf") { ...@@ -66,8 +66,6 @@ jumbo_component("wtf") {
"conditional_destructor.h", "conditional_destructor.h",
"container_annotations.h", "container_annotations.h",
"cpu.h", "cpu.h",
"cryptographically_random_number.cc",
"cryptographically_random_number.h",
"date_math.cc", "date_math.cc",
"date_math.h", "date_math.h",
"deque.h", "deque.h",
......
...@@ -69,8 +69,7 @@ The below is a list of major libraries. For a complete list, look at ...@@ -69,8 +69,7 @@ The below is a list of major libraries. For a complete list, look at
* **Miscellaneous** * **Miscellaneous**
[StdLibExtras.h] (`DEFINE_STATIC_LOCAL` etc.), [StdLibExtras.h] (`DEFINE_STATIC_LOCAL` etc.),
[Time.h], [Time.h]
[CryptographicallyRandomNumber.h]
## History ## History
...@@ -111,7 +110,6 @@ current location][4] Source/platform/wtf. ...@@ -111,7 +110,6 @@ current location][4] Source/platform/wtf.
[Noncopyable.h]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/noncopyable.h [Noncopyable.h]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/noncopyable.h
[StdLibExtras.h]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/std_lib_extras.h [StdLibExtras.h]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/std_lib_extras.h
[Time.h]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/time.h [Time.h]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/time.h
[CryptographicallyRandomNumber.h]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/cryptographically_random_number.h
[1]: https://chromium.googlesource.com/chromium/src/+/e372c152fc6e57743ebc508fe17f6eb131b4ff8d [1]: https://chromium.googlesource.com/chromium/src/+/e372c152fc6e57743ebc508fe17f6eb131b4ff8d
[2]: https://chromium.googlesource.com/chromium/src/+/547a6ca360a56fbee3d5ea4a71ba18f91622455c [2]: https://chromium.googlesource.com/chromium/src/+/547a6ca360a56fbee3d5ea4a71ba18f91622455c
[3]: https://chromium.googlesource.com/chromium/src/+/478890427ee03fd88e6f0f58ee8220512044bed9/third_party/WebKit/WebCore/kwq/KWQAssertions.h [3]: https://chromium.googlesource.com/chromium/src/+/478890427ee03fd88e6f0f58ee8220512044bed9/third_party/WebKit/WebCore/kwq/KWQAssertions.h
......
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
* Copyright (c) 2008, Damien Miller <djm@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "third_party/blink/renderer/platform/wtf/cryptographically_random_number.h"
#include "base/rand_util.h"
namespace WTF {
uint32_t CryptographicallyRandomNumber() {
uint32_t result;
CryptographicallyRandomValues(&result, sizeof(result));
return result;
}
void CryptographicallyRandomValues(void* buffer, size_t length) {
// This should really be crypto::RandBytes(), but WTF can't depend on crypto.
// The implementation of crypto::RandBytes() is just calling
// base::RandBytes(), so both are actually same.
base::RandBytes(buffer, length);
}
} // namespace WTF
/*
* Copyright (C) 2008 Torch Mobile Inc. All rights reserved.
* (http://www.torchmobile.com/)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_CRYPTOGRAPHICALLY_RANDOM_NUMBER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_CRYPTOGRAPHICALLY_RANDOM_NUMBER_H_
#include <stdint.h>
#include <cstddef>
#include "third_party/blink/renderer/platform/wtf/wtf_export.h"
namespace WTF {
// These functions are threadsafe.
WTF_EXPORT uint32_t CryptographicallyRandomNumber();
WTF_EXPORT void CryptographicallyRandomValues(void* buffer, size_t length);
}
using WTF::CryptographicallyRandomNumber;
using WTF::CryptographicallyRandomValues;
#endif
...@@ -80,6 +80,13 @@ _CONFIG = [ ...@@ -80,6 +80,13 @@ _CONFIG = [
# Debugging helpers from //base/debug are allowed everywhere. # Debugging helpers from //base/debug are allowed everywhere.
'base::debug::.+', 'base::debug::.+',
# (Cryptographic) random number generation
'base::RandUint64',
'base::RandInt',
'base::RandGenerator',
'base::RandDouble',
'base::RandBytes',
# Feature list checking. # Feature list checking.
'base::Feature.*', 'base::Feature.*',
'base::FEATURE_.+', 'base::FEATURE_.+',
...@@ -283,6 +290,12 @@ _CONFIG = [ ...@@ -283,6 +290,12 @@ _CONFIG = [
], ],
'allowed': ['ui::NativeTheme.*'], 'allowed': ['ui::NativeTheme.*'],
}, },
{
'paths': [
'third_party/blink/renderer/modules/crypto/',
],
'allowed': ['crypto::.+'],
},
] ]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment