OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "content/child/webcrypto/shared_crypto.h" | 5 #include "content/child/webcrypto/shared_crypto.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/child/webcrypto/crypto_data.h" | 8 #include "content/child/webcrypto/crypto_data.h" |
9 #include "content/child/webcrypto/jwk.h" | 9 #include "content/child/webcrypto/jwk.h" |
10 #include "content/child/webcrypto/platform_crypto.h" | 10 #include "content/child/webcrypto/platform_crypto.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 | 41 |
42 bool IsValidAesKeyLengthBits(unsigned int length_bits) { | 42 bool IsValidAesKeyLengthBits(unsigned int length_bits) { |
43 return length_bits == 128 || length_bits == 192 || length_bits == 256; | 43 return length_bits == 128 || length_bits == 192 || length_bits == 256; |
44 } | 44 } |
45 | 45 |
46 bool IsValidAesKeyLengthBytes(unsigned int length_bytes) { | 46 bool IsValidAesKeyLengthBytes(unsigned int length_bytes) { |
47 return length_bytes == 16 || length_bytes == 24 || length_bytes == 32; | 47 return length_bytes == 16 || length_bytes == 24 || length_bytes == 32; |
48 } | 48 } |
49 | 49 |
50 Status ToPlatformSymKey(const blink::WebCryptoKey& key, | |
51 platform::SymKey** out) { | |
52 *out = static_cast<platform::Key*>(key.handle())->AsSymKey(); | |
53 if (!*out) | |
54 return Status::ErrorUnexpectedKeyType(); | |
55 return Status::Success(); | |
56 } | |
57 | |
58 Status ToPlatformPublicKey(const blink::WebCryptoKey& key, | |
59 platform::PublicKey** out) { | |
60 *out = static_cast<platform::Key*>(key.handle())->AsPublicKey(); | |
61 if (!*out) | |
62 return Status::ErrorUnexpectedKeyType(); | |
63 return Status::Success(); | |
64 } | |
65 | |
66 Status ToPlatformPrivateKey(const blink::WebCryptoKey& key, | |
67 platform::PrivateKey** out) { | |
68 *out = static_cast<platform::Key*>(key.handle())->AsPrivateKey(); | |
69 if (!*out) | |
70 return Status::ErrorUnexpectedKeyType(); | |
71 return Status::Success(); | |
72 } | |
73 | |
74 const size_t kAesBlockSizeBytes = 16; | 50 const size_t kAesBlockSizeBytes = 16; |
75 | 51 |
76 Status EncryptDecryptAesCbc(EncryptOrDecrypt mode, | 52 Status EncryptDecryptAesCbc(EncryptOrDecrypt mode, |
77 const blink::WebCryptoAlgorithm& algorithm, | 53 const blink::WebCryptoAlgorithm& algorithm, |
78 const blink::WebCryptoKey& key, | 54 const blink::WebCryptoKey& key, |
79 const CryptoData& data, | 55 const CryptoData& data, |
80 std::vector<uint8>* buffer) { | 56 std::vector<uint8>* buffer) { |
81 platform::SymKey* sym_key; | 57 platform::SymKey* sym_key; |
82 Status status = ToPlatformSymKey(key, &sym_key); | 58 Status status = ToPlatformSymKey(key, &sym_key); |
83 if (status.IsError()) | 59 if (status.IsError()) |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 key_data, | 817 key_data, |
842 KeyAlgorithmToImportAlgorithm(algorithm), | 818 KeyAlgorithmToImportAlgorithm(algorithm), |
843 extractable, | 819 extractable, |
844 usage_mask, | 820 usage_mask, |
845 key); | 821 key); |
846 if (status.IsError()) | 822 if (status.IsError()) |
847 return false; | 823 return false; |
848 return ValidateDeserializedKey(*key, algorithm, type); | 824 return ValidateDeserializedKey(*key, algorithm, type); |
849 } | 825 } |
850 | 826 |
| 827 Status ToPlatformSymKey(const blink::WebCryptoKey& key, |
| 828 platform::SymKey** out) { |
| 829 *out = static_cast<platform::Key*>(key.handle())->AsSymKey(); |
| 830 if (!*out) |
| 831 return Status::ErrorUnexpectedKeyType(); |
| 832 return Status::Success(); |
| 833 } |
| 834 |
| 835 Status ToPlatformPublicKey(const blink::WebCryptoKey& key, |
| 836 platform::PublicKey** out) { |
| 837 *out = static_cast<platform::Key*>(key.handle())->AsPublicKey(); |
| 838 if (!*out) |
| 839 return Status::ErrorUnexpectedKeyType(); |
| 840 return Status::Success(); |
| 841 } |
| 842 |
| 843 Status ToPlatformPrivateKey(const blink::WebCryptoKey& key, |
| 844 platform::PrivateKey** out) { |
| 845 *out = static_cast<platform::Key*>(key.handle())->AsPrivateKey(); |
| 846 if (!*out) |
| 847 return Status::ErrorUnexpectedKeyType(); |
| 848 return Status::Success(); |
| 849 } |
| 850 |
851 } // namespace webcrypto | 851 } // namespace webcrypto |
852 | 852 |
853 } // namespace content | 853 } // namespace content |
OLD | NEW |