OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef CONTENT_CHILD_WEBCRYPTO_CRYPTO_ALGORITHM_H_ | |
6 #define CONTENT_CHILD_WEBCRYPTO_CRYPTO_ALGORITHM_H_ | |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "third_party/WebKit/public/platform/WebCrypto.h" | |
10 | |
11 namespace content { | |
12 | |
13 namespace webcrypto { | |
14 | |
15 class CryptoData; | |
16 class Status; | |
17 | |
18 // AlgorithmImplementation is a base class for *executing* the operations of an | |
19 // algorithm (generating keys, encrypting, signing, etc.). | |
20 // | |
21 // This is in contrast to blink::WebCryptoAlgorithm which instead *describes* | |
22 // the operation and its parameters. | |
23 // | |
24 // AlgorithmImplementation has reasonable default implementations for all | |
25 // methods which behave as if the operation is it is unsupported, so | |
26 // implementations need only override the applicable methods. | |
27 // | |
28 // Unless stated otherwise methods of AlgorithmImplementation are responsible | |
29 // for sanitizing their inputs. The following can be assumed: | |
30 // | |
31 // * |algorithm.id()| and |key.algorithm.id()| matches the algorithm under | |
32 // which the implementation was registerd. | |
33 // * |algorithm| has the correct parameters type for the operation. | |
34 // * The key usages have already been verified. In fact in the case of calls | |
35 // to Encrypt()/Decrypt() the corresponding key usages may not be present | |
36 // (when wrapping/unwrapping). | |
37 class AlgorithmImplementation { | |
Ryan Sleevi
2014/07/12 00:55:27
All of these methods should be documented.
It may
eroman
2014/07/12 01:59:30
Done.
| |
38 public: | |
39 virtual ~AlgorithmImplementation(); | |
40 | |
41 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | |
42 const blink::WebCryptoKey& key, | |
43 const CryptoData& data, | |
44 std::vector<uint8>* buffer) const; | |
45 | |
46 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, | |
47 const blink::WebCryptoKey& key, | |
48 const CryptoData& data, | |
49 std::vector<uint8>* buffer) const; | |
50 | |
51 virtual Status Sign(const blink::WebCryptoAlgorithm& algorithm, | |
52 const blink::WebCryptoKey& key, | |
53 const CryptoData& data, | |
54 std::vector<uint8>* buffer) const; | |
55 | |
56 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm, | |
57 const blink::WebCryptoKey& key, | |
58 const CryptoData& signature, | |
59 const CryptoData& data, | |
60 bool* signature_match) const; | |
61 | |
62 virtual Status Digest(const blink::WebCryptoAlgorithm& algorithm, | |
63 const CryptoData& data, | |
64 std::vector<uint8>* buffer) const; | |
65 | |
66 // When generating a key, VerifyKeyUsagesVeforeGenerateKey() will always be | |
67 // called before GenerateSecretKey(). Similarly when generating a keypair | |
68 // VerifyKeyUsagesBeforeGenerateKey() will always be called before | |
69 // GenerateKeyPair(). | |
Ryan Sleevi
2014/07/12 00:55:27
This is documenting how some other class uses this
eroman
2014/07/12 01:59:30
Done.
| |
70 | |
71 virtual Status VerifyKeyUsagesBeforeGenerateKey( | |
72 blink::WebCryptoKeyUsageMask usage_mask) const; | |
73 | |
74 virtual Status GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm, | |
75 bool extractable, | |
76 blink::WebCryptoKeyUsageMask usage_mask, | |
77 blink::WebCryptoKey* key) const; | |
78 | |
79 virtual Status VerifyKeyUsagesBeforeGenerateKeyPair( | |
80 blink::WebCryptoKeyUsageMask combined_usage_mask, | |
81 blink::WebCryptoKeyUsageMask* public_usage_mask, | |
82 blink::WebCryptoKeyUsageMask* private_usage_mask) const; | |
83 | |
84 virtual Status GenerateKeyPair( | |
85 const blink::WebCryptoAlgorithm& algorithm, | |
86 bool extractable, | |
87 blink::WebCryptoKeyUsageMask public_usage_mask, | |
88 blink::WebCryptoKeyUsageMask private_usage_mask, | |
89 blink::WebCryptoKey* public_key, | |
90 blink::WebCryptoKey* private_key) const; | |
91 | |
92 // ----------------------------------------------- | |
93 // Key import | |
94 // ----------------------------------------------- | |
95 // VerifyKeyUsagesBeforeImportKey() will always be called before either | |
96 // importing a key, or unwrapping a key. | |
Ryan Sleevi
2014/07/12 00:55:27
Again, layering.
eroman
2014/07/12 01:59:30
Done.
| |
97 // | |
98 // Note that when the format is JWK and importing an asymmetric key, | |
99 // VerifyKeyUsagesBeforeImportKey() will not know what the key type is yet. In | |
100 // this case the import function will be responsible for checking the usage. | |
Ryan Sleevi
2014/07/12 00:55:27
This belongs in ImportKeyJwk. It's unclear from yo
eroman
2014/07/12 01:59:30
Modified the comment. In the case of JWK, VerifyKe
| |
101 | |
102 virtual Status VerifyKeyUsagesBeforeImportKey( | |
103 blink::WebCryptoKeyFormat format, | |
104 blink::WebCryptoKeyUsageMask usage_mask) const; | |
105 | |
106 virtual Status ImportKeyRaw(const CryptoData& key_data, | |
107 const blink::WebCryptoAlgorithm& algorithm, | |
108 bool extractable, | |
109 blink::WebCryptoKeyUsageMask usage_mask, | |
110 blink::WebCryptoKey* key) const; | |
111 | |
112 virtual Status ImportKeyPkcs8(const CryptoData& key_data, | |
113 const blink::WebCryptoAlgorithm& algorithm, | |
114 bool extractable, | |
115 blink::WebCryptoKeyUsageMask usage_mask, | |
116 blink::WebCryptoKey* key) const; | |
117 | |
118 virtual Status ImportKeySpki(const CryptoData& key_data, | |
119 const blink::WebCryptoAlgorithm& algorithm, | |
120 bool extractable, | |
121 blink::WebCryptoKeyUsageMask usage_mask, | |
122 blink::WebCryptoKey* key) const; | |
123 | |
124 virtual Status ImportKeyJwk(const CryptoData& key_data, | |
125 const blink::WebCryptoAlgorithm& algorithm, | |
126 bool extractable, | |
127 blink::WebCryptoKeyUsageMask usage_mask, | |
128 blink::WebCryptoKey* key) const; | |
129 | |
130 // ----------------------------------------------- | |
131 // Key export | |
132 // ----------------------------------------------- | |
133 | |
134 virtual Status ExportKeyRaw(const blink::WebCryptoKey& key, | |
135 std::vector<uint8>* buffer) const; | |
136 | |
137 virtual Status ExportKeyPkcs8(const blink::WebCryptoKey& key, | |
138 std::vector<uint8>* buffer) const; | |
139 | |
140 virtual Status ExportKeySpki(const blink::WebCryptoKey& key, | |
141 std::vector<uint8>* buffer) const; | |
142 | |
143 virtual Status ExportKeyJwk(const blink::WebCryptoKey& key, | |
144 std::vector<uint8>* buffer) const; | |
145 }; | |
146 | |
147 } // namespace webcrypto | |
148 | |
149 } // namespace content | |
150 | |
151 #endif // CONTENT_CHILD_WEBCRYPTO_CRYPTO_ALGORITHM_H_ | |
OLD | NEW |