| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <openssl/err.h> | 5 #include <openssl/err.h> |
| 6 #include <openssl/hkdf.h> | 6 #include <openssl/hkdf.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const blink::WebCryptoKeyUsageMask kValidUsages = | 25 const blink::WebCryptoKeyUsageMask kValidUsages = |
| 26 blink::WebCryptoKeyUsageDeriveKey | blink::WebCryptoKeyUsageDeriveBits; | 26 blink::WebCryptoKeyUsageDeriveKey | blink::WebCryptoKeyUsageDeriveBits; |
| 27 | 27 |
| 28 class HkdfImplementation : public AlgorithmImplementation { | 28 class HkdfImplementation : public AlgorithmImplementation { |
| 29 public: | 29 public: |
| 30 HkdfImplementation() {} | 30 HkdfImplementation() {} |
| 31 | 31 |
| 32 Status VerifyKeyUsagesBeforeImportKey( | 32 Status ImportKey(blink::WebCryptoKeyFormat format, |
| 33 blink::WebCryptoKeyFormat format, | 33 const CryptoData& key_data, |
| 34 blink::WebCryptoKeyUsageMask usages) const override { | 34 const blink::WebCryptoAlgorithm& algorithm, |
| 35 if (format != blink::WebCryptoKeyFormatRaw) | 35 bool extractable, |
| 36 return Status::ErrorUnsupportedImportKeyFormat(); | 36 blink::WebCryptoKeyUsageMask usages, |
| 37 return CheckSecretKeyCreationUsages(kValidUsages, usages); | 37 blink::WebCryptoKey* key) const override { |
| 38 switch (format) { |
| 39 case blink::WebCryptoKeyFormatRaw: |
| 40 return ImportKeyRaw(key_data, algorithm, extractable, usages, key); |
| 41 default: |
| 42 return Status::ErrorUnsupportedImportKeyFormat(); |
| 43 } |
| 38 } | 44 } |
| 39 | 45 |
| 40 Status ImportKeyRaw(const CryptoData& key_data, | 46 Status ImportKeyRaw(const CryptoData& key_data, |
| 41 const blink::WebCryptoAlgorithm& algorithm, | 47 const blink::WebCryptoAlgorithm& algorithm, |
| 42 bool extractable, | 48 bool extractable, |
| 43 blink::WebCryptoKeyUsageMask usages, | 49 blink::WebCryptoKeyUsageMask usages, |
| 44 blink::WebCryptoKey* key) const override { | 50 blink::WebCryptoKey* key) const { |
| 51 Status status = CheckKeyCreationUsages(kValidUsages, usages); |
| 52 if (status.IsError()) |
| 53 return status; |
| 54 |
| 45 return CreateWebCryptoSecretKey( | 55 return CreateWebCryptoSecretKey( |
| 46 key_data, blink::WebCryptoKeyAlgorithm::createWithoutParams( | 56 key_data, blink::WebCryptoKeyAlgorithm::createWithoutParams( |
| 47 blink::WebCryptoAlgorithmIdHkdf), | 57 blink::WebCryptoAlgorithmIdHkdf), |
| 48 extractable, usages, key); | 58 extractable, usages, key); |
| 49 } | 59 } |
| 50 | 60 |
| 51 Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm, | 61 Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm, |
| 52 const blink::WebCryptoKey& base_key, | 62 const blink::WebCryptoKey& base_key, |
| 53 bool has_optional_length_bits, | 63 bool has_optional_length_bits, |
| 54 unsigned int optional_length_bits, | 64 unsigned int optional_length_bits, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 114 } |
| 105 }; | 115 }; |
| 106 | 116 |
| 107 } // namespace | 117 } // namespace |
| 108 | 118 |
| 109 std::unique_ptr<AlgorithmImplementation> CreateHkdfImplementation() { | 119 std::unique_ptr<AlgorithmImplementation> CreateHkdfImplementation() { |
| 110 return base::WrapUnique(new HkdfImplementation); | 120 return base::WrapUnique(new HkdfImplementation); |
| 111 } | 121 } |
| 112 | 122 |
| 113 } // namespace webcrypto | 123 } // namespace webcrypto |
| OLD | NEW |