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_ALGORITHM_NSS_H_
6 #define CONTENT_CHILD_WEBCRYPTO_NSS_AES_ALGORITHM_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|.
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 blink::WebCryptoKeyUsageMask all_key_usages
,
29 const std::string
& jwk_suffix
);
31 // This is the same as the other AesAlgorithm constructor, however
32 // |all_key_usages| is pre-filled with values for encryption/decryption
33 // algorithms (supports usages for: encrypt, decrypt, wrap, unwrap).
34 AesAlgorithm(CK_MECHANISM_TYPE import_mechanism
,
35 const std::string
& jwk_suffix
);
37 Status
GenerateKey(const blink::WebCryptoAlgorithm
& algorithm
,
39 blink::WebCryptoKeyUsageMask usages
,
40 GenerateKeyResult
* result
) const override
;
42 Status
VerifyKeyUsagesBeforeImportKey(
43 blink::WebCryptoKeyFormat format
,
44 blink::WebCryptoKeyUsageMask usages
) const override
;
46 Status
ImportKeyRaw(const CryptoData
& key_data
,
47 const blink::WebCryptoAlgorithm
& algorithm
,
49 blink::WebCryptoKeyUsageMask usages
,
50 blink::WebCryptoKey
* key
) const override
;
52 Status
ImportKeyJwk(const CryptoData
& key_data
,
53 const blink::WebCryptoAlgorithm
& algorithm
,
55 blink::WebCryptoKeyUsageMask usages
,
56 blink::WebCryptoKey
* key
) const override
;
58 Status
ExportKeyRaw(const blink::WebCryptoKey
& key
,
59 std::vector
<uint8_t>* buffer
) const override
;
61 Status
ExportKeyJwk(const blink::WebCryptoKey
& key
,
62 std::vector
<uint8_t>* buffer
) const override
;
64 Status
SerializeKeyForClone(
65 const blink::WebCryptoKey
& key
,
66 blink::WebVector
<uint8_t>* key_data
) const override
;
68 Status
DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm
& algorithm
,
69 blink::WebCryptoKeyType type
,
71 blink::WebCryptoKeyUsageMask usages
,
72 const CryptoData
& key_data
,
73 blink::WebCryptoKey
* key
) const override
;
75 Status
GetKeyLength(const blink::WebCryptoAlgorithm
& key_length_algorithm
,
76 bool* has_length_bits
,
77 unsigned int* length_bits
) const override
;
80 const CK_MECHANISM_TYPE import_mechanism_
;
81 const blink::WebCryptoKeyUsageMask all_key_usages_
;
82 const std::string jwk_suffix_
;
85 } // namespace webcrypto
87 } // namespace content
89 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_AES_ALGORITHM_NSS_H_