diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 22:53:13 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 22:53:13 +0000 |
commit | 1968d9778f74daa4056ddc5a18aeac5061d0314b (patch) | |
tree | 617c16cdb81229734e92aa908bbbd7a4923088be /base/rand_util_nacl.cc | |
parent | a24417742faf535b1a616984b03dcf8258b9f818 (diff) | |
download | chromium_src-1968d9778f74daa4056ddc5a18aeac5061d0314b.zip chromium_src-1968d9778f74daa4056ddc5a18aeac5061d0314b.tar.gz chromium_src-1968d9778f74daa4056ddc5a18aeac5061d0314b.tar.bz2 |
Enable parts of base_untrusted that are used by remoting client
1. base64, rand_util, threading, time and threads were previosly disabled in
base_untrusted. Remoting code depends on these parts of base, so they
need to be enabled.
2. Implemented NaCl version of rand_util.
3. Enabled glibc version of base_untrusted
BUG=134216
Review URL: https://chromiumcodereview.appspot.com/10795083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148641 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/rand_util_nacl.cc')
-rw-r--r-- | base/rand_util_nacl.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/base/rand_util_nacl.cc b/base/rand_util_nacl.cc new file mode 100644 index 0000000..47450aa --- /dev/null +++ b/base/rand_util_nacl.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/rand_util.h" + +#include "base/basictypes.h" +#include "base/lazy_instance.h" +#include "base/logging.h" +#include "native_client/src/untrusted/irt/irt.h" + +namespace { + +class NaclRandom { + public: + NaclRandom() { + size_t result = nacl_interface_query(NACL_IRT_RANDOM_v0_1, + &random_, sizeof(random_)); + CHECK_EQ(result, sizeof(random_)); + } + + ~NaclRandom() { + } + + void GetRandomBytes(char* buffer, uint32_t num_bytes) { + while (num_bytes > 0) { + size_t nread; + int error = random_.get_random_bytes(buffer, num_bytes, &nread); + CHECK_EQ(error, 0); + CHECK_LE(nread, num_bytes); + buffer += nread; + num_bytes -= nread; + } + } + + private: + nacl_irt_random random_; +}; + +base::LazyInstance<NaclRandom>::Leaky g_nacl_random = LAZY_INSTANCE_INITIALIZER; + +} // namespace + +namespace base { + +uint64 RandUint64() { + uint64 result; + g_nacl_random.Pointer()->GetRandomBytes( + reinterpret_cast<char*>(&result), sizeof(result)); + return result; +} + +} // namespace base |