| 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_ALGORITHM_DISPATCH_H_ | |
| 6 #define CONTENT_CHILD_WEBCRYPTO_ALGORITHM_DISPATCH_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "content/common/content_export.h" | |
| 13 #include "third_party/WebKit/public/platform/WebCrypto.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 namespace webcrypto { | |
| 18 | |
| 19 class AlgorithmImplementation; | |
| 20 class CryptoData; | |
| 21 class GenerateKeyResult; | |
| 22 class Status; | |
| 23 | |
| 24 // These functions provide an entry point for synchronous webcrypto operations. | |
| 25 // | |
| 26 // The inputs to these methods come from Blink, and hence the validations done | |
| 27 // by Blink can be assumed: | |
| 28 // | |
| 29 // * The algorithm parameters are consistent with the algorithm | |
| 30 // * The key contains the required usage for the operation | |
| 31 | |
| 32 CONTENT_EXPORT Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | |
| 33 const blink::WebCryptoKey& key, | |
| 34 const CryptoData& data, | |
| 35 std::vector<uint8_t>* buffer); | |
| 36 | |
| 37 CONTENT_EXPORT Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, | |
| 38 const blink::WebCryptoKey& key, | |
| 39 const CryptoData& data, | |
| 40 std::vector<uint8_t>* buffer); | |
| 41 | |
| 42 CONTENT_EXPORT Status Digest(const blink::WebCryptoAlgorithm& algorithm, | |
| 43 const CryptoData& data, | |
| 44 std::vector<uint8_t>* buffer); | |
| 45 | |
| 46 CONTENT_EXPORT Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, | |
| 47 bool extractable, | |
| 48 blink::WebCryptoKeyUsageMask usages, | |
| 49 GenerateKeyResult* result); | |
| 50 | |
| 51 CONTENT_EXPORT Status ImportKey(blink::WebCryptoKeyFormat format, | |
| 52 const CryptoData& key_data, | |
| 53 const blink::WebCryptoAlgorithm& algorithm, | |
| 54 bool extractable, | |
| 55 blink::WebCryptoKeyUsageMask usages, | |
| 56 blink::WebCryptoKey* key); | |
| 57 | |
| 58 CONTENT_EXPORT Status ExportKey(blink::WebCryptoKeyFormat format, | |
| 59 const blink::WebCryptoKey& key, | |
| 60 std::vector<uint8_t>* buffer); | |
| 61 | |
| 62 CONTENT_EXPORT Status Sign(const blink::WebCryptoAlgorithm& algorithm, | |
| 63 const blink::WebCryptoKey& key, | |
| 64 const CryptoData& data, | |
| 65 std::vector<uint8_t>* buffer); | |
| 66 | |
| 67 CONTENT_EXPORT Status Verify(const blink::WebCryptoAlgorithm& algorithm, | |
| 68 const blink::WebCryptoKey& key, | |
| 69 const CryptoData& signature, | |
| 70 const CryptoData& data, | |
| 71 bool* signature_match); | |
| 72 | |
| 73 CONTENT_EXPORT Status | |
| 74 WrapKey(blink::WebCryptoKeyFormat format, | |
| 75 const blink::WebCryptoKey& key_to_wrap, | |
| 76 const blink::WebCryptoKey& wrapping_key, | |
| 77 const blink::WebCryptoAlgorithm& wrapping_algorithm, | |
| 78 std::vector<uint8_t>* buffer); | |
| 79 | |
| 80 CONTENT_EXPORT Status | |
| 81 UnwrapKey(blink::WebCryptoKeyFormat format, | |
| 82 const CryptoData& wrapped_key_data, | |
| 83 const blink::WebCryptoKey& wrapping_key, | |
| 84 const blink::WebCryptoAlgorithm& wrapping_algorithm, | |
| 85 const blink::WebCryptoAlgorithm& algorithm, | |
| 86 bool extractable, | |
| 87 blink::WebCryptoKeyUsageMask usages, | |
| 88 blink::WebCryptoKey* key); | |
| 89 | |
| 90 CONTENT_EXPORT Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm, | |
| 91 const blink::WebCryptoKey& base_key, | |
| 92 unsigned int length_bits, | |
| 93 std::vector<uint8_t>* derived_bytes); | |
| 94 | |
| 95 // Derives a key by calling the underlying deriveBits/getKeyLength/importKey | |
| 96 // operations. | |
| 97 // | |
| 98 // Note that whereas the WebCrypto spec uses a single "derivedKeyType" | |
| 99 // AlgorithmIdentifier in its specification of deriveKey(), here two separate | |
| 100 // AlgorithmIdentifiers are used: | |
| 101 // | |
| 102 // * |import_algorithm| -- The parameters required by the derived key's | |
| 103 // "importKey" operation. | |
| 104 // | |
| 105 // * |key_length_algorithm| -- The parameters required by the derived key's | |
| 106 // "get key length" operation. | |
| 107 // | |
| 108 // WebCryptoAlgorithm is not a flexible type like AlgorithmIdentifier (it cannot | |
| 109 // be easily re-interpreted as a different parameter type). | |
| 110 // | |
| 111 // Therefore being provided with separate parameter types for the import | |
| 112 // parameters and the key length parameters simplifies passing the right | |
| 113 // parameters onto ImportKey() and GetKeyLength() respectively. | |
| 114 CONTENT_EXPORT Status | |
| 115 DeriveKey(const blink::WebCryptoAlgorithm& algorithm, | |
| 116 const blink::WebCryptoKey& base_key, | |
| 117 const blink::WebCryptoAlgorithm& import_algorithm, | |
| 118 const blink::WebCryptoAlgorithm& key_length_algorithm, | |
| 119 bool extractable, | |
| 120 blink::WebCryptoKeyUsageMask usages, | |
| 121 blink::WebCryptoKey* derived_key); | |
| 122 | |
| 123 CONTENT_EXPORT scoped_ptr<blink::WebCryptoDigestor> CreateDigestor( | |
| 124 blink::WebCryptoAlgorithmId algorithm); | |
| 125 | |
| 126 CONTENT_EXPORT bool SerializeKeyForClone(const blink::WebCryptoKey& key, | |
| 127 blink::WebVector<uint8_t>* key_data); | |
| 128 | |
| 129 CONTENT_EXPORT bool DeserializeKeyForClone( | |
| 130 const blink::WebCryptoKeyAlgorithm& algorithm, | |
| 131 blink::WebCryptoKeyType type, | |
| 132 bool extractable, | |
| 133 blink::WebCryptoKeyUsageMask usages, | |
| 134 const CryptoData& key_data, | |
| 135 blink::WebCryptoKey* key); | |
| 136 | |
| 137 } // namespace webcrypto | |
| 138 | |
| 139 } // namespace content | |
| 140 | |
| 141 #endif // CONTENT_CHILD_WEBCRYPTO_ALGORITHM_DISPATCH_H_ | |
| OLD | NEW |