Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / content / child / webcrypto / openssl / aes_algorithm_openssl.h
blobffdc60c32058edf176e8a1165b90da7e10f53e8b
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_OPENSSL_AES_ALGORITHM_OPENSSL_H_
6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_AES_ALGORITHM_OPENSSL_H_
8 #include "content/child/webcrypto/algorithm_implementation.h"
10 namespace content {
12 namespace webcrypto {
14 // Base class for AES algorithms that provides the implementation for key
15 // creation and export.
16 class AesAlgorithm : public AlgorithmImplementation {
17 public:
18 // |all_key_usages| is the set of all WebCrypto key usages that are
19 // allowed for imported or generated keys. |jwk_suffix| is the suffix
20 // used when constructing JWK names for the algorithm. For instance A128CBC
21 // is the JWK name for 128-bit AES-CBC. The |jwk_suffix| in this case would
22 // be "CBC".
23 AesAlgorithm(blink::WebCryptoKeyUsageMask all_key_usages,
24 const std::string& jwk_suffix);
26 // This is the same as the other AesAlgorithm constructor where
27 // |all_key_usages| is pre-filled to values for encryption/decryption
28 // algorithms (supports usages for: encrypt, decrypt, wrap, unwrap).
29 explicit AesAlgorithm(const std::string& jwk_suffix);
31 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
32 bool extractable,
33 blink::WebCryptoKeyUsageMask usages,
34 GenerateKeyResult* result) const override;
36 Status VerifyKeyUsagesBeforeImportKey(
37 blink::WebCryptoKeyFormat format,
38 blink::WebCryptoKeyUsageMask usages) const override;
40 Status ImportKeyRaw(const CryptoData& key_data,
41 const blink::WebCryptoAlgorithm& algorithm,
42 bool extractable,
43 blink::WebCryptoKeyUsageMask usages,
44 blink::WebCryptoKey* key) const override;
46 Status ImportKeyJwk(const CryptoData& key_data,
47 const blink::WebCryptoAlgorithm& algorithm,
48 bool extractable,
49 blink::WebCryptoKeyUsageMask usages,
50 blink::WebCryptoKey* key) const override;
52 Status ExportKeyRaw(const blink::WebCryptoKey& key,
53 std::vector<uint8_t>* buffer) const override;
55 Status ExportKeyJwk(const blink::WebCryptoKey& key,
56 std::vector<uint8_t>* buffer) const override;
58 Status SerializeKeyForClone(
59 const blink::WebCryptoKey& key,
60 blink::WebVector<uint8_t>* key_data) const override;
62 Status DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm,
63 blink::WebCryptoKeyType type,
64 bool extractable,
65 blink::WebCryptoKeyUsageMask usages,
66 const CryptoData& key_data,
67 blink::WebCryptoKey* key) const override;
69 Status GetKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm,
70 bool* has_length_bits,
71 unsigned int* length_bits) const override;
73 private:
74 const blink::WebCryptoKeyUsageMask all_key_usages_;
75 const std::string jwk_suffix_;
78 } // namespace webcrypto
80 } // namespace content
82 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_AES_ALGORITHM_OPENSSL_H_