| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_CHILD_WEBCRYPTO_NSS_AES_ALGORITHM_NSS_H_ | |
| 6 #define CONTENT_CHILD_WEBCRYPTO_NSS_AES_ALGORITHM_NSS_H_ | |
| 7 | |
| 8 #include <pkcs11t.h> | |
| 9 | |
| 10 #include "content/child/webcrypto/algorithm_implementation.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 namespace webcrypto { | |
| 15 | |
| 16 // Base class for AES algorithms that provides the implementation for key | |
| 17 // creation and export. | |
| 18 class AesAlgorithm : public AlgorithmImplementation { | |
| 19 public: | |
| 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 | |
| 26 // be "CBC". | |
| 27 AesAlgorithm(CK_MECHANISM_TYPE import_mechanism, | |
| 28 blink::WebCryptoKeyUsageMask all_key_usages, | |
| 29 const std::string& jwk_suffix); | |
| 30 | |
| 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); | |
| 36 | |
| 37 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, | |
| 38 bool extractable, | |
| 39 blink::WebCryptoKeyUsageMask usages, | |
| 40 GenerateKeyResult* result) const override; | |
| 41 | |
| 42 Status VerifyKeyUsagesBeforeImportKey( | |
| 43 blink::WebCryptoKeyFormat format, | |
| 44 blink::WebCryptoKeyUsageMask usages) const override; | |
| 45 | |
| 46 Status ImportKeyRaw(const CryptoData& key_data, | |
| 47 const blink::WebCryptoAlgorithm& algorithm, | |
| 48 bool extractable, | |
| 49 blink::WebCryptoKeyUsageMask usages, | |
| 50 blink::WebCryptoKey* key) const override; | |
| 51 | |
| 52 Status ImportKeyJwk(const CryptoData& key_data, | |
| 53 const blink::WebCryptoAlgorithm& algorithm, | |
| 54 bool extractable, | |
| 55 blink::WebCryptoKeyUsageMask usages, | |
| 56 blink::WebCryptoKey* key) const override; | |
| 57 | |
| 58 Status ExportKeyRaw(const blink::WebCryptoKey& key, | |
| 59 std::vector<uint8_t>* buffer) const override; | |
| 60 | |
| 61 Status ExportKeyJwk(const blink::WebCryptoKey& key, | |
| 62 std::vector<uint8_t>* buffer) const override; | |
| 63 | |
| 64 Status SerializeKeyForClone( | |
| 65 const blink::WebCryptoKey& key, | |
| 66 blink::WebVector<uint8_t>* key_data) const override; | |
| 67 | |
| 68 Status DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm, | |
| 69 blink::WebCryptoKeyType type, | |
| 70 bool extractable, | |
| 71 blink::WebCryptoKeyUsageMask usages, | |
| 72 const CryptoData& key_data, | |
| 73 blink::WebCryptoKey* key) const override; | |
| 74 | |
| 75 Status GetKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm, | |
| 76 bool* has_length_bits, | |
| 77 unsigned int* length_bits) const override; | |
| 78 | |
| 79 private: | |
| 80 const CK_MECHANISM_TYPE import_mechanism_; | |
| 81 const blink::WebCryptoKeyUsageMask all_key_usages_; | |
| 82 const std::string jwk_suffix_; | |
| 83 }; | |
| 84 | |
| 85 } // namespace webcrypto | |
| 86 | |
| 87 } // namespace content | |
| 88 | |
| 89 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_AES_ALGORITHM_NSS_H_ | |
| OLD | NEW |