Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: src/v8.cc

Issue 7395012: Introduce a random entropy source which can optionally be provided at initialization. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/v8.h ('K') | « src/v8.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8.cc
===================================================================
--- src/v8.cc (revision 8657)
+++ src/v8.cc (working copy)
@@ -50,7 +50,10 @@
bool V8::has_fatal_error_ = false;
bool V8::use_crankshaft_ = true;
+static Mutex* entropy_mutex = OS::CreateMutex();
+static EntropySource entropy_source;
+
bool V8::Initialize(Deserializer* des) {
InitializeOncePerProcess();
@@ -102,8 +105,14 @@
static void seed_random(uint32_t* state) {
for (int i = 0; i < 2; ++i) {
- state[i] = FLAG_random_seed;
- while (state[i] == 0) {
+ if (FLAG_random_seed != NULL)
Mads Ager (chromium) 2011/07/17 09:11:39 Please consistently use braces around the body. Al
+ state[i] = FLAG_random_seed;
+ else if (entropy_source != NULL) {
+ uint32_t val;
+ ScopedLock lock(entropy_mutex);
+ entropy_source(reinterpret_cast<unsigned char*>(&val), sizeof(uint32_t));
+ state[i] = val;
+ } else {
state[i] = random();
}
}
@@ -124,6 +133,11 @@
}
+void V8::SetEntropySource(EntropySource source) {
+ entropy_source = source;
+}
+
+
// Used by JavaScript APIs
uint32_t V8::Random(Isolate* isolate) {
ASSERT(isolate == Isolate::Current());
« src/v8.h ('K') | « src/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698