blob: 8b24b53b677092cb3c338116d0f92f5f31b1bc36 [file] [log] [blame]
jww@chromium.orgcf5d32e52014-03-07 18:00:081// Copyright 2014 The Chromium Authors. All rights reserved.
eroman@chromium.org408699c2013-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_
eroman@chromium.org408699c2013-07-17 21:23:167
eroman@chromium.org7e4c36f2013-09-12 06:10:198#include "base/basictypes.h"
eroman@chromium.org408699c2013-07-17 21:23:169#include "base/compiler_specific.h"
eroman@chromium.org408699c2013-07-17 21:23:1610#include "third_party/WebKit/public/platform/WebCrypto.h"
jww@chromium.orgbd48e6412014-02-22 08:32:5311#include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
eroman@chromium.org5daca0472014-03-18 20:27:0812#include "third_party/WebKit/public/platform/WebVector.h"
eroman@chromium.org408699c2013-07-17 21:23:1613
erg56f12322015-04-17 00:51:4814namespace webcrypto {
eroman@chromium.org408699c2013-07-17 21:23:1615
eroman@chromium.org88be98562014-04-30 11:18:5916// Wrapper around the Blink WebCrypto asynchronous interface, which forwards to
eroman@chromium.org72af5c52014-05-13 21:40:1917// the synchronous platform (NSS or OpenSSL) implementation.
eroman@chromium.org04166f82014-02-19 06:11:0418//
eroman@chromium.org72af5c52014-05-13 21:40:1919// WebCryptoImpl is threadsafe.
20//
21// EnsureInit() must be called prior to using methods on WebCryptoImpl().
eroman@chromium.org04166f82014-02-19 06:11:0422class WebCryptoImpl : public blink::WebCrypto {
eroman@chromium.org408699c2013-07-17 21:23:1623 public:
eroman@chromium.org7e4c36f2013-09-12 06:10:1924 WebCryptoImpl();
eroman@chromium.org72af5c52014-05-13 21:40:1925
eroman429e7002014-10-24 21:45:2626 // TODO(eroman): Once Blink and Chromium repositories are merged, use
27 // "override" in place of virtual.
28
eroman@chromium.org04166f82014-02-19 06:11:0429 virtual ~WebCryptoImpl();
eroman@chromium.org7e4c36f2013-09-12 06:10:1930
eroman@chromium.orga60326552014-02-19 22:58:2431 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,
eroman0e1d34e2014-10-21 19:13:3147 blink::WebCryptoKeyUsageMask usages,
eroman@chromium.orga60326552014-02-19 22:58:2448 blink::WebCryptoResult result);
49 virtual void importKey(blink::WebCryptoKeyFormat format,
50 const unsigned char* key_data,
51 unsigned int key_data_size,
eroman@chromium.orgc7a94682014-03-20 22:58:4052 const blink::WebCryptoAlgorithm& algorithm,
eroman@chromium.orga60326552014-02-19 22:58:2453 bool extractable,
eroman0e1d34e2014-10-21 19:13:3154 blink::WebCryptoKeyUsageMask usages,
eroman@chromium.orga60326552014-02-19 22:58:2455 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,
eroman38bb4bd2014-11-24 23:47:0670 blink::WebCryptoResult result);
eroman@chromium.orgbaa92842014-03-25 01:07:3871 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.org88be98562014-04-30 11:18:5986
eroman1499b4942014-11-26 19:59:5387 virtual void deriveBits(const blink::WebCryptoAlgorithm& algorithm,
88 const blink::WebCryptoKey& base_key,
89 unsigned int length_bits,
90 blink::WebCryptoResult result);
91
eroman20bf4c3c2014-12-12 17:22:3792 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.org6f778f02014-04-01 02:31:33100 // 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.come5b794b2013-08-30 01:32:54108
eroman@chromium.org5daca0472014-03-18 20:27:08109 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.org7e4c36f2013-09-12 06:10:19121 private:
122 DISALLOW_COPY_AND_ASSIGN(WebCryptoImpl);
eroman@chromium.org408699c2013-07-17 21:23:16123};
124
erg56f12322015-04-17 00:51:48125} // namespace webcrypto
eroman@chromium.org408699c2013-07-17 21:23:16126
erg56f12322015-04-17 00:51:48127#endif // COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_