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

Side by Side Diff: base/rand_util_nacl.cc

Issue 10546140: Add untrusted NaCl build for PPAPI proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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/base_untrusted.gyp ('k') | build/all.gyp » ('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/lazy_instance.h"
8 #include "base/logging.h"
9
10 // TODO(bbudge) Replace this with a proper system header file when NaCl
11 // provides one.
12 #include "native_client/src/untrusted/irt/irt.h"
13
14 namespace {
15
16 // Create a wrapper class so we can cache the NaCl random number interface.
17 class URandomInterface {
18 public:
19 URandomInterface() {
20 size_t result = nacl_interface_query(NACL_IRT_RANDOM_v0_1,
21 &interface_,
22 sizeof(interface_));
23 DCHECK_EQ(result, sizeof(interface_)) << "Can't get random interface.";
24 }
25
26 uint64 get_random_bytes() const {
27 size_t nbytes;
28 uint64 result;
29 int error = interface_.get_random_bytes(&result,
30 sizeof(result),
31 &nbytes);
32 DCHECK_EQ(error, 0);
33 DCHECK_EQ(nbytes, sizeof(result));
34 return result;
35 }
36
37 private:
38 struct nacl_irt_random interface_;
39 };
40
41 base::LazyInstance<URandomInterface> g_urandom_interface =
42 LAZY_INSTANCE_INITIALIZER;
43
44 } // namespace
45
46 namespace base {
47
48 uint64 RandUint64() {
49 return g_urandom_interface.Pointer()->get_random_bytes();
50 }
51
52 } // namespace base
53
OLDNEW
« no previous file with comments | « base/base_untrusted.gyp ('k') | build/all.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698