jww@chromium.org | cf5d32e5 | 2014-03-07 18:00:08 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
eroman@chromium.org | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 5 | #ifndef COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_ |
| 6 | #define COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_ |
eroman@chromium.org | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 7 | |
eroman@chromium.org | 7e4c36f | 2013-09-12 06:10:19 | [diff] [blame] | 8 | #include "base/basictypes.h" |
eroman@chromium.org | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
eroman@chromium.org | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 10 | #include "third_party/WebKit/public/platform/WebCrypto.h" |
jww@chromium.org | bd48e641 | 2014-02-22 08:32:53 | [diff] [blame] | 11 | #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
eroman@chromium.org | 5daca047 | 2014-03-18 20:27:08 | [diff] [blame] | 12 | #include "third_party/WebKit/public/platform/WebVector.h" |
eroman@chromium.org | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 13 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 14 | namespace webcrypto { |
eroman@chromium.org | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 15 | |
eroman@chromium.org | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 16 | // Wrapper around the Blink WebCrypto asynchronous interface, which forwards to |
eroman@chromium.org | 72af5c5 | 2014-05-13 21:40:19 | [diff] [blame] | 17 | // the synchronous platform (NSS or OpenSSL) implementation. |
eroman@chromium.org | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 18 | // |
eroman@chromium.org | 72af5c5 | 2014-05-13 21:40:19 | [diff] [blame] | 19 | // WebCryptoImpl is threadsafe. |
| 20 | // |
| 21 | // EnsureInit() must be called prior to using methods on WebCryptoImpl(). |
eroman@chromium.org | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 22 | class WebCryptoImpl : public blink::WebCrypto { |
eroman@chromium.org | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 23 | public: |
eroman@chromium.org | 7e4c36f | 2013-09-12 06:10:19 | [diff] [blame] | 24 | WebCryptoImpl(); |
eroman@chromium.org | 72af5c5 | 2014-05-13 21:40:19 | [diff] [blame] | 25 | |
eroman | 429e700 | 2014-10-24 21:45:26 | [diff] [blame] | 26 | // TODO(eroman): Once Blink and Chromium repositories are merged, use |
| 27 | // "override" in place of virtual. |
| 28 | |
eroman@chromium.org | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 29 | virtual ~WebCryptoImpl(); |
eroman@chromium.org | 7e4c36f | 2013-09-12 06:10:19 | [diff] [blame] | 30 | |
eroman@chromium.org | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 31 | virtual void encrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 32 | const blink::WebCryptoKey& key, |
| 33 | const unsigned char* data, |
| 34 | unsigned int data_size, |
| 35 | blink::WebCryptoResult result); |
| 36 | virtual void decrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 37 | const blink::WebCryptoKey& key, |
| 38 | const unsigned char* data, |
| 39 | unsigned int data_size, |
| 40 | blink::WebCryptoResult result); |
| 41 | virtual void digest(const blink::WebCryptoAlgorithm& algorithm, |
| 42 | const unsigned char* data, |
| 43 | unsigned int data_size, |
| 44 | blink::WebCryptoResult result); |
| 45 | virtual void generateKey(const blink::WebCryptoAlgorithm& algorithm, |
| 46 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 47 | blink::WebCryptoKeyUsageMask usages, |
eroman@chromium.org | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 48 | blink::WebCryptoResult result); |
| 49 | virtual void importKey(blink::WebCryptoKeyFormat format, |
| 50 | const unsigned char* key_data, |
| 51 | unsigned int key_data_size, |
eroman@chromium.org | c7a9468 | 2014-03-20 22:58:40 | [diff] [blame] | 52 | const blink::WebCryptoAlgorithm& algorithm, |
eroman@chromium.org | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 53 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 54 | blink::WebCryptoKeyUsageMask usages, |
eroman@chromium.org | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 55 | blink::WebCryptoResult result); |
| 56 | virtual void exportKey(blink::WebCryptoKeyFormat format, |
| 57 | const blink::WebCryptoKey& key, |
| 58 | blink::WebCryptoResult result); |
| 59 | virtual void sign(const blink::WebCryptoAlgorithm& algorithm, |
| 60 | const blink::WebCryptoKey& key, |
| 61 | const unsigned char* data, |
| 62 | unsigned int data_size, |
| 63 | blink::WebCryptoResult result); |
| 64 | virtual void verifySignature(const blink::WebCryptoAlgorithm& algorithm, |
| 65 | const blink::WebCryptoKey& key, |
| 66 | const unsigned char* signature, |
| 67 | unsigned int signature_size, |
| 68 | const unsigned char* data, |
| 69 | unsigned int data_size, |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 70 | blink::WebCryptoResult result); |
eroman@chromium.org | baa9284 | 2014-03-25 01:07:38 | [diff] [blame] | 71 | virtual void wrapKey(blink::WebCryptoKeyFormat format, |
| 72 | const blink::WebCryptoKey& key, |
| 73 | const blink::WebCryptoKey& wrapping_key, |
| 74 | const blink::WebCryptoAlgorithm& wrap_algorithm, |
| 75 | blink::WebCryptoResult result); |
| 76 | virtual void unwrapKey( |
| 77 | blink::WebCryptoKeyFormat format, |
| 78 | const unsigned char* wrapped_key, |
| 79 | unsigned wrapped_key_size, |
| 80 | const blink::WebCryptoKey& wrapping_key, |
| 81 | const blink::WebCryptoAlgorithm& unwrap_algorithm, |
| 82 | const blink::WebCryptoAlgorithm& unwrapped_key_algorithm, |
| 83 | bool extractable, |
| 84 | blink::WebCryptoKeyUsageMask usages, |
| 85 | blink::WebCryptoResult result); |
eroman@chromium.org | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 86 | |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 87 | virtual void deriveBits(const blink::WebCryptoAlgorithm& algorithm, |
| 88 | const blink::WebCryptoKey& base_key, |
| 89 | unsigned int length_bits, |
| 90 | blink::WebCryptoResult result); |
| 91 | |
eroman | 20bf4c3c | 2014-12-12 17:22:37 | [diff] [blame] | 92 | virtual void deriveKey(const blink::WebCryptoAlgorithm& algorithm, |
| 93 | const blink::WebCryptoKey& base_key, |
| 94 | const blink::WebCryptoAlgorithm& import_algorithm, |
| 95 | const blink::WebCryptoAlgorithm& key_length_algorithm, |
| 96 | bool extractable, |
| 97 | blink::WebCryptoKeyUsageMask usages, |
| 98 | blink::WebCryptoResult result); |
| 99 | |
jww@chromium.org | 6f778f0 | 2014-04-01 02:31:33 | [diff] [blame] | 100 | // This method returns a digestor object that can be used to synchronously |
| 101 | // compute a digest one chunk at a time. Thus, the consume does not need to |
| 102 | // hold onto a large buffer with all the data to digest. Chunks can be given |
| 103 | // one at a time and the digest will be computed piecemeal. The allocated |
| 104 | // WebCrytpoDigestor that is returned by createDigestor must be freed by the |
| 105 | // caller. |
| 106 | virtual blink::WebCryptoDigestor* createDigestor( |
| 107 | blink::WebCryptoAlgorithmId algorithm_id); |
bryaneyler@google.com | e5b794b | 2013-08-30 01:32:54 | [diff] [blame] | 108 | |
eroman@chromium.org | 5daca047 | 2014-03-18 20:27:08 | [diff] [blame] | 109 | virtual bool deserializeKeyForClone( |
| 110 | const blink::WebCryptoKeyAlgorithm& algorithm, |
| 111 | blink::WebCryptoKeyType type, |
| 112 | bool extractable, |
| 113 | blink::WebCryptoKeyUsageMask usages, |
| 114 | const unsigned char* key_data, |
| 115 | unsigned key_data_size, |
| 116 | blink::WebCryptoKey& key); |
| 117 | |
| 118 | virtual bool serializeKeyForClone(const blink::WebCryptoKey& key, |
| 119 | blink::WebVector<unsigned char>& key_data); |
| 120 | |
eroman@chromium.org | 7e4c36f | 2013-09-12 06:10:19 | [diff] [blame] | 121 | private: |
| 122 | DISALLOW_COPY_AND_ASSIGN(WebCryptoImpl); |
eroman@chromium.org | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 123 | }; |
| 124 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 125 | } // namespace webcrypto |
eroman@chromium.org | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 126 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 127 | #endif // COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_ |