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