Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: content/renderer/webcrypto/shared_crypto.h

Issue 155623005: Refactor to share more code between OpenSSL and NSS implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change header guard Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #ifndef CONTENT_RENDERER_WEBCRYPTO_SHARED_CRYPTO_H_
6 #define CONTENT_RENDERER_WEBCRYPTO_SHARED_CRYPTO_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "content/common/content_export.h"
11 #include "third_party/WebKit/public/platform/WebArrayBuffer.h"
12 #include "third_party/WebKit/public/platform/WebCrypto.h"
13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
14
15 namespace content {
16
17 namespace webcrypto {
18
19 class CryptoData;
20
21 class Status;
22
23 // Do one-time initialization. It is safe to call this multiple times.
24 CONTENT_EXPORT void Init();
25
26 // The functions exported by shared_crypto.h provide a common entry point for
27 // synchronous crypto operations.
28 //
29 // Here is how the layer cake looks.
30 //
31 // Blink
32 // |
33 // ==============|==========================
34 // |
35 // content
36 // |
37 // |
38 // v
39 // WebCryptoImpl (Implements the blink::WebCrypto interface for
40 // | asynchronous completions)
41 // |
42 // | [shared_crypto_unittests.cc]
43 // | /
44 // | / (The blink::WebCrypto interface is not
45 // | / testable from the chromium side because
46 // | / the result object is not mockable.
47 // | / Tests are done on shared_crypto instead.
48 // V v
49 // [shared_crypto.h] (Exposes synchronous functions in the
50 // | webcrypto:: namespace. This does
51 // | common validations, infers default
52 // | parameters, and casts the algorithm
53 // | parameters to the right types)
54 // |
55 // V
56 // [platform_crypto.h] (Exposes functions in the webcrypto::platform
57 // | namespace)
58 // |
59 // |
60 // V
61 // [platform_crypto_{nss|openssl}.cc] (Implements using the platform crypto
62 // library)
63 //
64 // The shared_crypto.h functions are responsible for:
65 //
66 // * Validating the key usages
67 // * Inferring default parameters when not specified
68 // * Validating key exportability
69 // * Validating algorithm with key.algorithm
70 // * Converting the blink key to a more specific platform::{PublicKey,
71 // PrivateKey, SymKey} and making sure it was the right type.
72 // * Validating alogorithm specific parameters (for instance, was the iv for
73 // AES-CBC 16 bytes).
74 // * Parse a JWK
75
76 CONTENT_EXPORT Status Encrypt(const blink::WebCryptoAlgorithm& algorithm,
77 const blink::WebCryptoKey& key,
78 const CryptoData& data,
79 blink::WebArrayBuffer* buffer);
80
81 CONTENT_EXPORT Status Decrypt(const blink::WebCryptoAlgorithm& algorithm,
82 const blink::WebCryptoKey& key,
83 const CryptoData& data,
84 blink::WebArrayBuffer* buffer);
85
86 CONTENT_EXPORT Status Digest(const blink::WebCryptoAlgorithm& algorithm,
87 const CryptoData& data,
88 blink::WebArrayBuffer* buffer);
89
90 CONTENT_EXPORT Status
91 GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm,
92 bool extractable,
93 blink::WebCryptoKeyUsageMask usage_mask,
94 blink::WebCryptoKey* key);
95
96 CONTENT_EXPORT Status
97 GenerateKeyPair(const blink::WebCryptoAlgorithm& algorithm,
98 bool extractable,
99 blink::WebCryptoKeyUsageMask usage_mask,
100 blink::WebCryptoKey* public_key,
101 blink::WebCryptoKey* private_key);
102
103 CONTENT_EXPORT Status
104 ImportKey(blink::WebCryptoKeyFormat format,
105 const CryptoData& key_data,
106 const blink::WebCryptoAlgorithm& algorithm_or_null,
107 bool extractable,
108 blink::WebCryptoKeyUsageMask usage_mask,
109 blink::WebCryptoKey* key);
110
111 CONTENT_EXPORT Status ExportKey(blink::WebCryptoKeyFormat format,
112 const blink::WebCryptoKey& key,
113 blink::WebArrayBuffer* buffer);
114
115 CONTENT_EXPORT Status Sign(const blink::WebCryptoAlgorithm& algorithm,
116 const blink::WebCryptoKey& key,
117 const CryptoData& data,
118 blink::WebArrayBuffer* buffer);
119
120 CONTENT_EXPORT Status
121 VerifySignature(const blink::WebCryptoAlgorithm& algorithm,
122 const blink::WebCryptoKey& key,
123 const CryptoData& signature,
124 const CryptoData& data,
125 bool* signature_match);
126
127 CONTENT_EXPORT Status
128 ImportKeyJwk(const CryptoData& key_data,
129 const blink::WebCryptoAlgorithm& algorithm_or_null,
130 bool extractable,
131 blink::WebCryptoKeyUsageMask usage_mask,
132 blink::WebCryptoKey* key);
133
134 } // namespace webcrypto
135
136 } // namespace content
137
138 #endif // CONTENT_RENDERER_WEBCRYPTO_SHARED_CRYPTO_H_
OLDNEW
« no previous file with comments | « content/renderer/webcrypto/platform_crypto_openssl.cc ('k') | content/renderer/webcrypto/shared_crypto.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698