diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-20 15:25:55 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-20 15:25:55 +0000 |
commit | f682ad7ed47cf3cadf5d4c9f12996bb6bd5890f2 (patch) | |
tree | 74e15da4da50e5cbb9be7d6a30f96e83f260def3 /ppapi | |
parent | 264fda93befd14308dc1703b53c270cbe63e8dc6 (diff) | |
download | chromium_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')
-rw-r--r-- | ppapi/c/dev/ppb_crypto_dev.h | 21 | ||||
-rw-r--r-- | ppapi/ppapi_shared_proxy.gypi | 4 | ||||
-rw-r--r-- | ppapi/proxy/dispatcher.cc | 3 | ||||
-rw-r--r-- | ppapi/proxy/interface_id.h | 1 | ||||
-rw-r--r-- | ppapi/proxy/ppb_crypto_proxy.cc | 54 | ||||
-rw-r--r-- | ppapi/proxy/ppb_crypto_proxy.h | 33 | ||||
-rw-r--r-- | ppapi/shared_impl/crypto_impl.cc | 25 | ||||
-rw-r--r-- | ppapi/shared_impl/crypto_impl.h | 22 | ||||
-rw-r--r-- | ppapi/tests/all_c_includes.h | 1 |
9 files changed, 164 insertions, 0 deletions
diff --git a/ppapi/c/dev/ppb_crypto_dev.h b/ppapi/c/dev/ppb_crypto_dev.h new file mode 100644 index 0000000..266a782 --- /dev/null +++ b/ppapi/c/dev/ppb_crypto_dev.h @@ -0,0 +1,21 @@ +/* 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_C_DEV_PPB_CRYPTO_DEV_H_ +#define PPAPI_C_DEV_PPB_CRYPTO_DEV_H_ + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_stdint.h" + +#define PPB_CRYPTO_DEV_INTERFACE "PPB_Crypto(Dev);0.1" + +struct PPB_Crypto_Dev { + /** + * Fills the given buffer with random bytes. This is potentially slow so only + * request the amount of data you need. + */ + void (*GetRandomBytes)(char* buffer, uint32_t num_bytes); +}; + +#endif diff --git a/ppapi/ppapi_shared_proxy.gypi b/ppapi/ppapi_shared_proxy.gypi index c6b88f8..341e1f3 100644 --- a/ppapi/ppapi_shared_proxy.gypi +++ b/ppapi/ppapi_shared_proxy.gypi @@ -22,6 +22,8 @@ 'shared_impl/audio_impl.h', 'shared_impl/char_set_impl.cc', 'shared_impl/char_set_impl.h', + 'shared_impl/crypto_impl.cc', + 'shared_impl/crypto_impl.h', 'shared_impl/image_data_impl.cc', 'shared_impl/image_data_impl.h', 'shared_impl/url_util_impl.cc', @@ -97,6 +99,8 @@ 'proxy/ppb_context_3d_proxy.h', 'proxy/ppb_core_proxy.cc', 'proxy/ppb_core_proxy.h', + 'proxy/ppb_crypto_proxy.cc', + 'proxy/ppb_crypto_proxy.h', 'proxy/ppb_cursor_control_proxy.cc', 'proxy/ppb_cursor_control_proxy.h', 'proxy/ppb_file_chooser_proxy.cc', diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc index 2964835..f5d5668 100644 --- a/ppapi/proxy/dispatcher.cc +++ b/ppapi/proxy/dispatcher.cc @@ -14,6 +14,7 @@ #include "ppapi/c/dev/ppb_buffer_dev.h" #include "ppapi/c/dev/ppb_char_set_dev.h" #include "ppapi/c/dev/ppb_context_3d_dev.h" +#include "ppapi/c/dev/ppb_crypto_dev.h" #include "ppapi/c/dev/ppb_cursor_control_dev.h" #include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" #include "ppapi/c/dev/ppb_font_dev.h" @@ -50,6 +51,7 @@ #include "ppapi/proxy/ppb_console_proxy.h" #include "ppapi/proxy/ppb_context_3d_proxy.h" #include "ppapi/proxy/ppb_core_proxy.h" +#include "ppapi/proxy/ppb_crypto_proxy.h" #include "ppapi/proxy/ppb_cursor_control_proxy.h" #include "ppapi/proxy/ppb_file_chooser_proxy.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" @@ -113,6 +115,7 @@ InterfaceList::InterfaceList() { AddPPB(PPB_Console_Proxy::GetInfo()); AddPPB(PPB_Context3D_Proxy::GetInfo()); AddPPB(PPB_Core_Proxy::GetInfo()); + AddPPB(PPB_Crypto_Proxy::GetInfo()); AddPPB(PPB_CursorControl_Proxy::GetInfo()); AddPPB(PPB_FileChooser_Proxy::GetInfo()); AddPPB(PPB_FileRef_Proxy::GetInfo()); diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h index 10ef8c4..c7346b5 100644 --- a/ppapi/proxy/interface_id.h +++ b/ppapi/proxy/interface_id.h @@ -21,6 +21,7 @@ enum InterfaceID { INTERFACE_ID_PPB_CONSOLE, INTERFACE_ID_PPB_CONTEXT_3D, INTERFACE_ID_PPB_CORE, + INTERFACE_ID_PPB_CRYPTO, INTERFACE_ID_PPB_CURSORCONTROL, INTERFACE_ID_PPB_FILE_CHOOSER, INTERFACE_ID_PPB_FILE_REF, diff --git a/ppapi/proxy/ppb_crypto_proxy.cc b/ppapi/proxy/ppb_crypto_proxy.cc new file mode 100644 index 0000000..207b400 --- /dev/null +++ b/ppapi/proxy/ppb_crypto_proxy.cc @@ -0,0 +1,54 @@ +// 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/proxy/ppb_crypto_proxy.h" + +#include "ppapi/c/dev/ppb_crypto_dev.h" +#include "ppapi/proxy/interface_id.h" +#include "ppapi/shared_impl/crypto_impl.h" + +namespace pp { +namespace proxy { + +namespace { + +const PPB_Crypto_Dev crypto_interface = { + &pp::shared_impl::CryptoImpl::GetRandomBytes +}; + +InterfaceProxy* CreateCryptoProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Crypto_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPB_Crypto_Proxy::PPB_Crypto_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { + NOTREACHED(); // See comment in the header file. +} + +PPB_Crypto_Proxy::~PPB_Crypto_Proxy() { +} + +// static +const InterfaceProxy::Info* PPB_Crypto_Proxy::GetInfo() { + static const Info info = { + &crypto_interface, + PPB_CRYPTO_DEV_INTERFACE, + INTERFACE_ID_PPB_CRYPTO, + false, + &CreateCryptoProxy, + }; + return &info; +} + +bool PPB_Crypto_Proxy::OnMessageReceived(const IPC::Message& msg) { + NOTREACHED(); + return false; +} + +} // namespace proxy +} // namespace pp diff --git a/ppapi/proxy/ppb_crypto_proxy.h b/ppapi/proxy/ppb_crypto_proxy.h new file mode 100644 index 0000000..e801892 --- /dev/null +++ b/ppapi/proxy/ppb_crypto_proxy.h @@ -0,0 +1,33 @@ +// 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_PROXY_PPB_CRYPTO_PROXY_H_ +#define PPAPI_PROXY_PPB_CRYPTO_PROXY_H_ + +#include "ppapi/proxy/interface_proxy.h" + +namespace pp { +namespace proxy { + +class PPB_Crypto_Proxy : public InterfaceProxy { + public: + // This class should not normally be instantiated since there's only one + // function that's implemented entirely within the plugin. However, we need + // to support this so the machinery for automatically handling interfaces + // works. As a result, this constructor will assert if it's actually used. + PPB_Crypto_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_Crypto_Proxy(); + + static const Info* GetInfo(); + + private: + virtual bool OnMessageReceived(const IPC::Message& msg); + + DISALLOW_COPY_AND_ASSIGN(PPB_Crypto_Proxy); +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PROXY_PPB_CRYPTO_PROXY_H_ 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_ diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index ab68dd1..176af2a 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -18,6 +18,7 @@ #include "ppapi/c/dev/ppb_console_dev.h" #include "ppapi/c/dev/ppb_context_3d_dev.h" #include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" +#include "ppapi/c/dev/ppb_crypto_dev.h" #include "ppapi/c/dev/ppb_cursor_control_dev.h" #include "ppapi/c/dev/ppb_directory_reader_dev.h" #include "ppapi/c/dev/ppb_file_chooser_dev.h" |