blob: 068a65cfc18fe48a5b6fd78cc917e6c309bf01ad [file] [log] [blame]
[email protected]cf5d32e52014-03-07 18:00:081// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]408699c2013-07-17 21:23:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
erg56f12322015-04-17 00:51:485#ifndef COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_
6#define COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_
[email protected]408699c2013-07-17 21:23:167
[email protected]7e4c36f2013-09-12 06:10:198#include "base/basictypes.h"
[email protected]408699c2013-07-17 21:23:169#include "base/compiler_specific.h"
[email protected]408699c2013-07-17 21:23:1610#include "third_party/WebKit/public/platform/WebCrypto.h"
[email protected]bd48e6412014-02-22 08:32:5311#include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
[email protected]5daca0472014-03-18 20:27:0812#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]408699c2013-07-17 21:23:1613
erg56f12322015-04-17 00:51:4814namespace webcrypto {
[email protected]408699c2013-07-17 21:23:1615
[email protected]88be98562014-04-30 11:18:5916// Wrapper around the Blink WebCrypto asynchronous interface, which forwards to
eroman039e410f2015-09-15 23:17:3817// the synchronous OpenSSL implementation.
[email protected]04166f82014-02-19 06:11:0418//
[email protected]72af5c52014-05-13 21:40:1919// WebCryptoImpl is threadsafe.
20//
21// EnsureInit() must be called prior to using methods on WebCryptoImpl().
[email protected]04166f82014-02-19 06:11:0422class WebCryptoImpl : public blink::WebCrypto {
[email protected]408699c2013-07-17 21:23:1623 public:
[email protected]7e4c36f2013-09-12 06:10:1924 WebCryptoImpl();
[email protected]72af5c52014-05-13 21:40:1925
avia27ae4b92015-09-24 20:12:2426 ~WebCryptoImpl() override;
eroman429e7002014-10-24 21:45:2627
avia27ae4b92015-09-24 20:12:2428 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]a60326552014-02-19 22:58:2462 const blink::WebCryptoKey& key,
avia27ae4b92015-09-24 20:12:2463 const unsigned char* signature,
64 unsigned int signature_size,
[email protected]a60326552014-02-19 22:58:2465 const unsigned char* data,
66 unsigned int data_size,
avia27ae4b92015-09-24 20:12:2467 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]88be98562014-04-30 11:18:5982
avia27ae4b92015-09-24 20:12:2483 void deriveBits(const blink::WebCryptoAlgorithm& algorithm,
84 const blink::WebCryptoKey& base_key,
85 unsigned int length_bits,
86 blink::WebCryptoResult result) override;
eroman1499b4942014-11-26 19:59:5387
avia27ae4b92015-09-24 20:12:2488 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;
eroman20bf4c3c2014-12-12 17:22:3795
[email protected]6f778f02014-04-01 02:31:3396 // 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.
avia27ae4b92015-09-24 20:12:24102 blink::WebCryptoDigestor* createDigestor(
103 blink::WebCryptoAlgorithmId algorithm_id) override;
[email protected]e5b794b2013-08-30 01:32:54104
avia27ae4b92015-09-24 20:12:24105 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]5daca0472014-03-18 20:27:08112
avia27ae4b92015-09-24 20:12:24113 bool serializeKeyForClone(const blink::WebCryptoKey& key,
114 blink::WebVector<unsigned char>& key_data) override;
[email protected]5daca0472014-03-18 20:27:08115
[email protected]7e4c36f2013-09-12 06:10:19116 private:
117 DISALLOW_COPY_AND_ASSIGN(WebCryptoImpl);
[email protected]408699c2013-07-17 21:23:16118};
119
erg56f12322015-04-17 00:51:48120} // namespace webcrypto
[email protected]408699c2013-07-17 21:23:16121
erg56f12322015-04-17 00:51:48122#endif // COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_