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.
5 #include "base/rand_util.h"
6 #include "base/rand_util_c.h"
8 #include "base/lazy_instance.h"
9 #include "base/logging.h"
11 // TODO(bbudge) Replace this with a proper system header file when NaCl
13 #include "native_client/src/untrusted/irt/irt.h"
17 // Create a wrapper class so we can cache the NaCl random number interface.
18 class URandomInterface
{
21 size_t result
= nacl_interface_query(NACL_IRT_RANDOM_v0_1
,
24 DCHECK_EQ(result
, sizeof(interface_
)) << "Can't get random interface.";
27 uint64
get_random_bytes() const {
30 int error
= interface_
.get_random_bytes(&result
,
34 DCHECK_EQ(nbytes
, sizeof(result
));
39 struct nacl_irt_random interface_
;
42 base::LazyInstance
<URandomInterface
> g_urandom_interface
=
43 LAZY_INSTANCE_INITIALIZER
;
50 return g_urandom_interface
.Pointer()->get_random_bytes();