mandoline: Reland "Sandbox mojo:browser and mojo:omnibox."
[chromium-blink-merge.git] / components / webcrypto / nss / aes_algorithm_nss.h
blob1d1df1a3a8400106e72dddcb92c0ec98b32bf792
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_NSS_AES_ALGORITHM_NSS_H_
6 #define COMPONENTS_WEBCRYPTO_NSS_AES_ALGORITHM_NSS_H_
8 #include <pkcs11t.h>
10 #include "components/webcrypto/algorithm_implementation.h"
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 // Constructs an AES algorithm whose keys will be imported using the NSS
19 // mechanism |import_mechanism|.
20 // |all_key_usages| is the set of all WebCrypto key usages that are
21 // allowed for imported or generated keys. |jwk_suffix| is the suffix
22 // used when constructing JWK names for the algorithm. For instance A128CBC
23 // is the JWK name for 128-bit AES-CBC. The |jwk_suffix| in this case would
24 // be "CBC".
25 AesAlgorithm(CK_MECHANISM_TYPE import_mechanism,
26 blink::WebCryptoKeyUsageMask all_key_usages,
27 const std::string& jwk_suffix);
29 // This is the same as the other AesAlgorithm constructor, however
30 // |all_key_usages| is pre-filled with values for encryption/decryption
31 // algorithms (supports usages for: encrypt, decrypt, wrap, unwrap).
32 AesAlgorithm(CK_MECHANISM_TYPE import_mechanism,
33 const std::string& jwk_suffix);
35 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
36 bool extractable,
37 blink::WebCryptoKeyUsageMask usages,
38 GenerateKeyResult* result) const override;
40 Status VerifyKeyUsagesBeforeImportKey(
41 blink::WebCryptoKeyFormat format,
42 blink::WebCryptoKeyUsageMask usages) const override;
44 Status ImportKeyRaw(const CryptoData& key_data,
45 const blink::WebCryptoAlgorithm& algorithm,
46 bool extractable,
47 blink::WebCryptoKeyUsageMask usages,
48 blink::WebCryptoKey* key) const override;
50 Status ImportKeyJwk(const CryptoData& key_data,
51 const blink::WebCryptoAlgorithm& algorithm,
52 bool extractable,
53 blink::WebCryptoKeyUsageMask usages,
54 blink::WebCryptoKey* key) const override;
56 Status ExportKeyRaw(const blink::WebCryptoKey& key,
57 std::vector<uint8_t>* buffer) const override;
59 Status ExportKeyJwk(const blink::WebCryptoKey& key,
60 std::vector<uint8_t>* buffer) const override;
62 Status SerializeKeyForClone(
63 const blink::WebCryptoKey& key,
64 blink::WebVector<uint8_t>* key_data) const override;
66 Status DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm,
67 blink::WebCryptoKeyType type,
68 bool extractable,
69 blink::WebCryptoKeyUsageMask usages,
70 const CryptoData& key_data,
71 blink::WebCryptoKey* key) const override;
73 Status GetKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm,
74 bool* has_length_bits,
75 unsigned int* length_bits) const override;
77 private:
78 const CK_MECHANISM_TYPE import_mechanism_;
79 const blink::WebCryptoKeyUsageMask all_key_usages_;
80 const std::string jwk_suffix_;
83 } // namespace webcrypto
85 #endif // COMPONENTS_WEBCRYPTO_NSS_AES_ALGORITHM_NSS_H_