| // 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" |
| size_t result = nacl_interface_query(NACL_IRT_RANDOM_v0_1, |
| &random_, sizeof(random_)); |
| CHECK_EQ(result, sizeof(random_)); |
| void GetRandomBytes(char* buffer, uint32_t num_bytes) { |
| int error = random_.get_random_bytes(buffer, num_bytes, &nread); |
| CHECK_LE(nread, num_bytes); |
| base::LazyInstance<NaclRandom>::Leaky g_nacl_random = LAZY_INSTANCE_INITIALIZER; |
| g_nacl_random.Pointer()->GetRandomBytes( |
| reinterpret_cast<char*>(&result), sizeof(result)); |