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

Side by Side Diff: base/rand_util_nacl.cc

Issue 10795083: Enable some parts of base that were previously disabled in base_untrusted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/os_compat_nacl.cc ('k') | base/threading/platform_thread_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/rand_util.h"
6
7 #include "base/basictypes.h"
8 #include "base/lazy_instance.h"
9 #include "base/logging.h"
10 #include "native_client/src/untrusted/irt/irt.h"
11
12 namespace {
13
14 class NaclRandom {
15 public:
16 NaclRandom() {
17 size_t result = nacl_interface_query(NACL_IRT_RANDOM_v0_1,
18 &random_, sizeof(random_));
19 CHECK_EQ(result, sizeof(random_));
20 }
21
22 ~NaclRandom() {
23 }
24
25 void GetRandomBytes(char* buffer, uint32_t num_bytes) {
26 while (num_bytes > 0) {
27 size_t nread;
28 int error = random_.get_random_bytes(buffer, num_bytes, &nread);
29 CHECK_EQ(error, 0);
30 CHECK_LE(nread, num_bytes);
31 buffer += nread;
32 num_bytes -= nread;
33 }
34 }
35
36 private:
37 nacl_irt_random random_;
38 };
39
40 base::LazyInstance<NaclRandom>::Leaky g_nacl_random = LAZY_INSTANCE_INITIALIZER;
41
42 } // namespace
43
44 namespace base {
45
46 uint64 RandUint64() {
47 uint64 result;
48 g_nacl_random.Pointer()->GetRandomBytes(
49 reinterpret_cast<char*>(&result), sizeof(result));
50 return result;
51 }
52
53 } // namespace base
OLDNEW
« no previous file with comments | « base/os_compat_nacl.cc ('k') | base/threading/platform_thread_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698