Chromium Code Reviews| Index: base/rand_util_nacl.cc |
| diff --git a/base/rand_util_nacl.cc b/base/rand_util_nacl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c2e92455ea1bb0944e56f2627a26e87dbec695af |
| --- /dev/null |
| +++ b/base/rand_util_nacl.cc |
| @@ -0,0 +1,48 @@ |
| +// 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 <stdlib.h> |
| + |
| +#include "base/lazy_instance.h" |
| +#include "base/logging.h" |
| +#include "ppapi/c/dev/ppb_crypto_dev.h" |
| +#include "ppapi/cpp/module.h" |
| + |
| +namespace { |
| + |
| +class PepperCrypto { |
| + public: |
| + PepperCrypto() { |
| + ppb_crypto_ = reinterpret_cast<const PPB_Crypto_Dev*>( |
| + pp::Module::Get()->GetPluginInterface(PPB_CRYPTO_DEV_INTERFACE)); |
|
bradn
2012/07/24 23:02:29
Two questions:
1. I had the impression this interf
|
| + DCHECK(ppb_crypto_); |
| + } |
| + |
| + ~PepperCrypto() { |
| + } |
| + |
| + void GetRandomBytes(char* buffer, uint32_t num_bytes) { |
| + ppb_crypto_->GetRandomBytes(buffer, num_bytes); |
| + } |
| + |
| + private: |
| + const PPB_Crypto_Dev* ppb_crypto_; |
| +}; |
| + |
| +base::LazyInstance<PepperCrypto> g_pepper_crypto = LAZY_INSTANCE_INITIALIZER; |
| + |
| +} // namespace |
| + |
| +namespace base { |
| + |
| +uint64 RandUint64() { |
| + uint64 result; |
| + g_pepper_crypto.Pointer()->GetRandomBytes( |
| + reinterpret_cast<char*>(&result), sizeof(result)); |
| + return result; |
| +} |
| + |
| +} // namespace base |