summaryrefslogtreecommitdiffstats
path: root/ppapi/shared_impl
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-20 15:25:55 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-20 15:25:55 +0000
commitf682ad7ed47cf3cadf5d4c9f12996bb6bd5890f2 (patch)
tree74e15da4da50e5cbb9be7d6a30f96e83f260def3 /ppapi/shared_impl
parent264fda93befd14308dc1703b53c270cbe63e8dc6 (diff)
downloadchromium_src-f682ad7ed47cf3cadf5d4c9f12996bb6bd5890f2.zip
chromium_src-f682ad7ed47cf3cadf5d4c9f12996bb6bd5890f2.tar.gz
chromium_src-f682ad7ed47cf3cadf5d4c9f12996bb6bd5890f2.tar.bz2
Add an initial crypto interface to fill a given buffer with random data. This
has the same implementation as the WebKit one on ChromeOS. TEST=none BUG=none Review URL: http://codereview.chromium.org/6880053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl')
-rw-r--r--ppapi/shared_impl/crypto_impl.cc25
-rw-r--r--ppapi/shared_impl/crypto_impl.h22
2 files changed, 47 insertions, 0 deletions
diff --git a/ppapi/shared_impl/crypto_impl.cc b/ppapi/shared_impl/crypto_impl.cc
new file mode 100644
index 0000000..6295bb2
--- /dev/null
+++ b/ppapi/shared_impl/crypto_impl.cc
@@ -0,0 +1,25 @@
+// Copyright (c) 2011 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 "ppapi/shared_impl/crypto_impl.h"
+
+#include "base/rand_util.h"
+
+namespace pp {
+namespace shared_impl {
+
+// static
+void CryptoImpl::GetRandomBytes(char* buffer, uint32_t num_bytes) {
+ // Note: this is a copy of WebKitClientImpl::cryptographicallyRandomValues.
+ uint64 bytes = 0;
+ for (uint32_t i = 0; i < num_bytes; ++i) {
+ uint32_t offset = i % sizeof(bytes);
+ if (!offset)
+ bytes = base::RandUint64();
+ buffer[i] = reinterpret_cast<char*>(&bytes)[offset];
+ }
+}
+
+} // namespace shared_impl
+} // namespace pp
diff --git a/ppapi/shared_impl/crypto_impl.h b/ppapi/shared_impl/crypto_impl.h
new file mode 100644
index 0000000..c3b3cd4
--- /dev/null
+++ b/ppapi/shared_impl/crypto_impl.h
@@ -0,0 +1,22 @@
+// Copyright (c) 2011 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.
+
+#ifndef PPAPI_SHARED_IMPL_CRYPTO_IMPL_H_
+#define PPAPI_SHARED_IMPL_CRYPTO_IMPL_H_
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_stdint.h"
+
+namespace pp {
+namespace shared_impl {
+
+class CryptoImpl {
+ public:
+ static void GetRandomBytes(char* buffer, uint32_t num_bytes);
+};
+
+} // namespace shared_impl
+} // namespace pp
+
+#endif // PPAPI_SHARED_IMPL_CRYPTO_IMPL_H_