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 <openssl/aes.h> | 5 #include <openssl/aes.h> |
6 #include <openssl/evp.h> | 6 #include <openssl/evp.h> |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/child/webcrypto/crypto_data.h" | 9 #include "content/child/webcrypto/crypto_data.h" |
10 #include "content/child/webcrypto/openssl/aes_key_openssl.h" | 10 #include "content/child/webcrypto/openssl/aes_key_openssl.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 // OpenSSL constants for EVP_CipherInit_ex(), do not change | 35 // OpenSSL constants for EVP_CipherInit_ex(), do not change |
36 enum CipherOperation { kDoDecrypt = 0, kDoEncrypt = 1 }; | 36 enum CipherOperation { kDoDecrypt = 0, kDoEncrypt = 1 }; |
37 | 37 |
38 Status AesCbcEncryptDecrypt(CipherOperation cipher_operation, | 38 Status AesCbcEncryptDecrypt(CipherOperation cipher_operation, |
39 const blink::WebCryptoAlgorithm& algorithm, | 39 const blink::WebCryptoAlgorithm& algorithm, |
40 const blink::WebCryptoKey& key, | 40 const blink::WebCryptoKey& key, |
41 const CryptoData& data, | 41 const CryptoData& data, |
42 std::vector<uint8>* buffer) { | 42 std::vector<uint8_t>* buffer) { |
43 const blink::WebCryptoAesCbcParams* params = algorithm.aesCbcParams(); | 43 const blink::WebCryptoAesCbcParams* params = algorithm.aesCbcParams(); |
44 const std::vector<uint8>& raw_key = SymKeyOpenSsl::Cast(key)->raw_key_data(); | 44 const std::vector<uint8_t>& raw_key = |
| 45 SymKeyOpenSsl::Cast(key)->raw_key_data(); |
45 | 46 |
46 if (params->iv().size() != 16) | 47 if (params->iv().size() != 16) |
47 return Status::ErrorIncorrectSizeAesCbcIv(); | 48 return Status::ErrorIncorrectSizeAesCbcIv(); |
48 | 49 |
49 if (data.byte_length() >= INT_MAX - AES_BLOCK_SIZE) { | 50 if (data.byte_length() >= INT_MAX - AES_BLOCK_SIZE) { |
50 // TODO(padolph): Handle this by chunking the input fed into OpenSSL. Right | 51 // TODO(padolph): Handle this by chunking the input fed into OpenSSL. Right |
51 // now it doesn't make much difference since the one-shot API would end up | 52 // now it doesn't make much difference since the one-shot API would end up |
52 // blowing out the memory and crashing anyway. | 53 // blowing out the memory and crashing anyway. |
53 return Status::ErrorDataTooLarge(); | 54 return Status::ErrorDataTooLarge(); |
54 } | 55 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 return Status::Success(); | 109 return Status::Success(); |
109 } | 110 } |
110 | 111 |
111 class AesCbcImplementation : public AesAlgorithm { | 112 class AesCbcImplementation : public AesAlgorithm { |
112 public: | 113 public: |
113 AesCbcImplementation() : AesAlgorithm("CBC") {} | 114 AesCbcImplementation() : AesAlgorithm("CBC") {} |
114 | 115 |
115 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | 116 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, |
116 const blink::WebCryptoKey& key, | 117 const blink::WebCryptoKey& key, |
117 const CryptoData& data, | 118 const CryptoData& data, |
118 std::vector<uint8>* buffer) const OVERRIDE { | 119 std::vector<uint8_t>* buffer) const OVERRIDE { |
119 return AesCbcEncryptDecrypt(kDoEncrypt, algorithm, key, data, buffer); | 120 return AesCbcEncryptDecrypt(kDoEncrypt, algorithm, key, data, buffer); |
120 } | 121 } |
121 | 122 |
122 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, | 123 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, |
123 const blink::WebCryptoKey& key, | 124 const blink::WebCryptoKey& key, |
124 const CryptoData& data, | 125 const CryptoData& data, |
125 std::vector<uint8>* buffer) const OVERRIDE { | 126 std::vector<uint8_t>* buffer) const OVERRIDE { |
126 return AesCbcEncryptDecrypt(kDoDecrypt, algorithm, key, data, buffer); | 127 return AesCbcEncryptDecrypt(kDoDecrypt, algorithm, key, data, buffer); |
127 } | 128 } |
128 }; | 129 }; |
129 | 130 |
130 } // namespace | 131 } // namespace |
131 | 132 |
132 AlgorithmImplementation* CreatePlatformAesCbcImplementation() { | 133 AlgorithmImplementation* CreatePlatformAesCbcImplementation() { |
133 return new AesCbcImplementation; | 134 return new AesCbcImplementation; |
134 } | 135 } |
135 | 136 |
136 } // namespace webcrypto | 137 } // namespace webcrypto |
137 | 138 |
138 } // namespace content | 139 } // namespace content |
OLD | NEW |