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_NSS_AES_NSS_H_
6 #define CONTENT_CHILD_WEBCRYPTO_NSS_AES_NSS_H_
10 #include "content/child/webcrypto/algorithm_implementation.h"
16 // Base class for AES algorithms that provides the implementation for key
17 // creation and export.
18 class AesAlgorithm : public AlgorithmImplementation {
20 // Constructs an AES algorithm whose keys will be imported using the NSS
21 // mechanism |import_mechanism| and NSS flags |import_flags|.
22 // |all_key_usages| is the set of all WebCrypto key usages that are
23 // allowed for imported or generated keys. |jwk_suffix| is the suffix
24 // used when constructing JWK names for the algorithm. For instance A128CBC
25 // is the JWK name for 128-bit AES-CBC. The |jwk_suffix| in this case would
27 AesAlgorithm(CK_MECHANISM_TYPE import_mechanism,
28 CK_FLAGS import_flags,
29 blink::WebCryptoKeyUsageMask all_key_usages,
30 const std::string& jwk_suffix);
32 // This is the same as the other AesAlgorithm constructor, however
33 // |import_flags| and |all_key_usages| are pre-filled to values for
34 // encryption/decryption algorithms (supports usages for: encrypt, decrypt,
36 AesAlgorithm(CK_MECHANISM_TYPE import_mechanism,
37 const std::string& jwk_suffix);
39 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
41 blink::WebCryptoKeyUsageMask usages,
42 GenerateKeyResult* result) const override;
44 Status VerifyKeyUsagesBeforeImportKey(
45 blink::WebCryptoKeyFormat format,
46 blink::WebCryptoKeyUsageMask usages) const override;
48 Status ImportKeyRaw(const CryptoData& key_data,
49 const blink::WebCryptoAlgorithm& algorithm,
51 blink::WebCryptoKeyUsageMask usages,
52 blink::WebCryptoKey* key) const override;
54 Status ImportKeyJwk(const CryptoData& key_data,
55 const blink::WebCryptoAlgorithm& algorithm,
57 blink::WebCryptoKeyUsageMask usages,
58 blink::WebCryptoKey* key) const override;
60 Status ExportKeyRaw(const blink::WebCryptoKey& key,
61 std::vector<uint8_t>* buffer) const override;
63 Status ExportKeyJwk(const blink::WebCryptoKey& key,
64 std::vector<uint8_t>* buffer) const override;
67 const CK_MECHANISM_TYPE import_mechanism_;
68 const CK_FLAGS import_flags_;
69 const blink::WebCryptoKeyUsageMask all_key_usages_;
70 const std::string jwk_suffix_;
73 } // namespace webcrypto
75 } // namespace content
77 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_AES_NSS_H_