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