Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / webcrypto / algorithms / aes.h
blob62cc3b1e406f25a739d40322a5ddab92a8d58432
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 COMPONENTS_WEBCRYPTO_ALGORITHMS_AES_H_
6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_AES_H_
8 #include "components/webcrypto/algorithm_implementation.h"
10 namespace webcrypto {
12 // Base class for AES algorithms that provides the implementation for key
13 // creation and export.
14 class AesAlgorithm : public AlgorithmImplementation {
15 public:
16 // |all_key_usages| is the set of all WebCrypto key usages that are
17 // allowed for imported or generated keys. |jwk_suffix| is the suffix
18 // used when constructing JWK names for the algorithm. For instance A128CBC
19 // is the JWK name for 128-bit AES-CBC. The |jwk_suffix| in this case would
20 // be "CBC".
21 AesAlgorithm(blink::WebCryptoKeyUsageMask all_key_usages,
22 const std::string& jwk_suffix);
24 // This is the same as the other AesAlgorithm constructor where
25 // |all_key_usages| is pre-filled to values for encryption/decryption
26 // algorithms (supports usages for: encrypt, decrypt, wrap, unwrap).
27 explicit AesAlgorithm(const std::string& jwk_suffix);
29 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
30 bool extractable,
31 blink::WebCryptoKeyUsageMask usages,
32 GenerateKeyResult* result) const override;
34 Status VerifyKeyUsagesBeforeImportKey(
35 blink::WebCryptoKeyFormat format,
36 blink::WebCryptoKeyUsageMask usages) const override;
38 Status ImportKeyRaw(const CryptoData& key_data,
39 const blink::WebCryptoAlgorithm& algorithm,
40 bool extractable,
41 blink::WebCryptoKeyUsageMask usages,
42 blink::WebCryptoKey* key) const override;
44 Status ImportKeyJwk(const CryptoData& key_data,
45 const blink::WebCryptoAlgorithm& algorithm,
46 bool extractable,
47 blink::WebCryptoKeyUsageMask usages,
48 blink::WebCryptoKey* key) const override;
50 Status ExportKeyRaw(const blink::WebCryptoKey& key,
51 std::vector<uint8_t>* buffer) const override;
53 Status ExportKeyJwk(const blink::WebCryptoKey& key,
54 std::vector<uint8_t>* buffer) const override;
56 Status DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm,
57 blink::WebCryptoKeyType type,
58 bool extractable,
59 blink::WebCryptoKeyUsageMask usages,
60 const CryptoData& key_data,
61 blink::WebCryptoKey* key) const override;
63 Status GetKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm,
64 bool* has_length_bits,
65 unsigned int* length_bits) const override;
67 private:
68 const blink::WebCryptoKeyUsageMask all_key_usages_;
69 const std::string jwk_suffix_;
72 } // namespace webcrypto
74 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_AES_H_