Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / content / child / webcrypto / algorithm_dispatch.h
blob5249d4f7620bf2571b888519a6434a7fbe5eae43
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_WEBCRYPTO_ALGORITHM_DISPATCH_H_
6 #define CONTENT_CHILD_WEBCRYPTO_ALGORITHM_DISPATCH_H_
8 #include <stdint.h>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
13 #include "third_party/WebKit/public/platform/WebCrypto.h"
15 namespace content {
17 namespace webcrypto {
19 class AlgorithmImplementation;
20 class CryptoData;
21 class GenerateKeyResult;
22 class Status;
24 // These functions provide an entry point for synchronous webcrypto operations.
26 // The inputs to these methods come from Blink, and hence the validations done
27 // by Blink can be assumed:
29 // * The algorithm parameters are consistent with the algorithm
30 // * The key contains the required usage for the operation
32 CONTENT_EXPORT Status Encrypt(const blink::WebCryptoAlgorithm& algorithm,
33 const blink::WebCryptoKey& key,
34 const CryptoData& data,
35 std::vector<uint8_t>* buffer);
37 CONTENT_EXPORT Status Decrypt(const blink::WebCryptoAlgorithm& algorithm,
38 const blink::WebCryptoKey& key,
39 const CryptoData& data,
40 std::vector<uint8_t>* buffer);
42 CONTENT_EXPORT Status Digest(const blink::WebCryptoAlgorithm& algorithm,
43 const CryptoData& data,
44 std::vector<uint8_t>* buffer);
46 CONTENT_EXPORT Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
47 bool extractable,
48 blink::WebCryptoKeyUsageMask usages,
49 GenerateKeyResult* result);
51 CONTENT_EXPORT Status ImportKey(blink::WebCryptoKeyFormat format,
52 const CryptoData& key_data,
53 const blink::WebCryptoAlgorithm& algorithm,
54 bool extractable,
55 blink::WebCryptoKeyUsageMask usages,
56 blink::WebCryptoKey* key);
58 CONTENT_EXPORT Status ExportKey(blink::WebCryptoKeyFormat format,
59 const blink::WebCryptoKey& key,
60 std::vector<uint8_t>* buffer);
62 CONTENT_EXPORT Status Sign(const blink::WebCryptoAlgorithm& algorithm,
63 const blink::WebCryptoKey& key,
64 const CryptoData& data,
65 std::vector<uint8_t>* buffer);
67 CONTENT_EXPORT Status Verify(const blink::WebCryptoAlgorithm& algorithm,
68 const blink::WebCryptoKey& key,
69 const CryptoData& signature,
70 const CryptoData& data,
71 bool* signature_match);
73 CONTENT_EXPORT Status
74 WrapKey(blink::WebCryptoKeyFormat format,
75 const blink::WebCryptoKey& key_to_wrap,
76 const blink::WebCryptoKey& wrapping_key,
77 const blink::WebCryptoAlgorithm& wrapping_algorithm,
78 std::vector<uint8_t>* buffer);
80 CONTENT_EXPORT Status
81 UnwrapKey(blink::WebCryptoKeyFormat format,
82 const CryptoData& wrapped_key_data,
83 const blink::WebCryptoKey& wrapping_key,
84 const blink::WebCryptoAlgorithm& wrapping_algorithm,
85 const blink::WebCryptoAlgorithm& algorithm,
86 bool extractable,
87 blink::WebCryptoKeyUsageMask usages,
88 blink::WebCryptoKey* key);
90 CONTENT_EXPORT Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm,
91 const blink::WebCryptoKey& base_key,
92 unsigned int length_bits,
93 std::vector<uint8_t>* derived_bytes);
95 // Derives a key by calling the underlying deriveBits/getKeyLength/importKey
96 // operations.
98 // Note that whereas the WebCrypto spec uses a single "derivedKeyType"
99 // AlgorithmIdentifier in its specification of deriveKey(), here two separate
100 // AlgorithmIdentifiers are used:
102 // * |import_algorithm| -- The parameters required by the derived key's
103 // "importKey" operation.
105 // * |key_length_algorithm| -- The parameters required by the derived key's
106 // "get key length" operation.
108 // WebCryptoAlgorithm is not a flexible type like AlgorithmIdentifier (it cannot
109 // be easily re-interpreted as a different parameter type).
111 // Therefore being provided with separate parameter types for the import
112 // parameters and the key length parameters simplifies passing the right
113 // parameters onto ImportKey() and GetKeyLength() respectively.
114 CONTENT_EXPORT Status
115 DeriveKey(const blink::WebCryptoAlgorithm& algorithm,
116 const blink::WebCryptoKey& base_key,
117 const blink::WebCryptoAlgorithm& import_algorithm,
118 const blink::WebCryptoAlgorithm& key_length_algorithm,
119 bool extractable,
120 blink::WebCryptoKeyUsageMask usages,
121 blink::WebCryptoKey* derived_key);
123 CONTENT_EXPORT scoped_ptr<blink::WebCryptoDigestor> CreateDigestor(
124 blink::WebCryptoAlgorithmId algorithm);
126 CONTENT_EXPORT bool SerializeKeyForClone(const blink::WebCryptoKey& key,
127 blink::WebVector<uint8_t>* key_data);
129 CONTENT_EXPORT bool DeserializeKeyForClone(
130 const blink::WebCryptoKeyAlgorithm& algorithm,
131 blink::WebCryptoKeyType type,
132 bool extractable,
133 blink::WebCryptoKeyUsageMask usages,
134 const CryptoData& key_data,
135 blink::WebCryptoKey* key);
137 } // namespace webcrypto
139 } // namespace content
141 #endif // CONTENT_CHILD_WEBCRYPTO_ALGORITHM_DISPATCH_H_