OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/webcrypto/webcrypto_impl.h" | 5 #include "content/renderer/webcrypto/webcrypto_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 #include <openssl/aes.h> | 8 #include <openssl/aes.h> |
9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
10 #include <openssl/hmac.h> | 10 #include <openssl/hmac.h> |
11 #include <openssl/sha.h> | 11 #include <openssl/sha.h> |
12 #include <openssl/evp.h> | 12 #include <openssl/evp.h> |
13 #include <openssl/rand.h> | 13 #include <openssl/rand.h> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "content/renderer/webcrypto/webcrypto_util.h" |
16 #include "crypto/openssl_util.h" | 17 #include "crypto/openssl_util.h" |
17 #include "crypto/secure_util.h" | 18 #include "crypto/secure_util.h" |
18 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | 19 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
19 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 20 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
20 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 21 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 int final_output_chunk_len = 0; | 145 int final_output_chunk_len = 0; |
145 if (!EVP_CipherFinal_ex( | 146 if (!EVP_CipherFinal_ex( |
146 context.get(), buffer_data + output_len, &final_output_chunk_len)) | 147 context.get(), buffer_data + output_len, &final_output_chunk_len)) |
147 return false; | 148 return false; |
148 | 149 |
149 const unsigned final_output_len = | 150 const unsigned final_output_len = |
150 static_cast<unsigned>(output_len) + | 151 static_cast<unsigned>(output_len) + |
151 static_cast<unsigned>(final_output_chunk_len); | 152 static_cast<unsigned>(final_output_chunk_len); |
152 DCHECK_LE(final_output_len, output_max_len); | 153 DCHECK_LE(final_output_len, output_max_len); |
153 | 154 |
154 WebCryptoImpl::ShrinkBuffer(buffer, final_output_len); | 155 webcrypto::ShrinkBuffer(buffer, final_output_len); |
155 | 156 |
156 return true; | 157 return true; |
157 } | 158 } |
158 | 159 |
159 } // namespace | 160 } // namespace |
160 | 161 |
161 void WebCryptoImpl::Init() { crypto::EnsureOpenSSLInit(); } | 162 void WebCryptoImpl::Init() { crypto::EnsureOpenSSLInit(); } |
162 | 163 |
163 bool WebCryptoImpl::EncryptInternal(const blink::WebCryptoAlgorithm& algorithm, | 164 bool WebCryptoImpl::EncryptInternal(const blink::WebCryptoAlgorithm& algorithm, |
164 const blink::WebCryptoKey& key, | 165 const blink::WebCryptoKey& key, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 if (algorithm_or_null.isNull()) | 324 if (algorithm_or_null.isNull()) |
324 return false; | 325 return false; |
325 const blink::WebCryptoAlgorithm& algorithm = algorithm_or_null; | 326 const blink::WebCryptoAlgorithm& algorithm = algorithm_or_null; |
326 | 327 |
327 // TODO(padolph): Support all relevant alg types and then remove this gate. | 328 // TODO(padolph): Support all relevant alg types and then remove this gate. |
328 if (algorithm.id() != blink::WebCryptoAlgorithmIdHmac && | 329 if (algorithm.id() != blink::WebCryptoAlgorithmIdHmac && |
329 algorithm.id() != blink::WebCryptoAlgorithmIdAesCbc) { | 330 algorithm.id() != blink::WebCryptoAlgorithmIdAesCbc) { |
330 return false; | 331 return false; |
331 } | 332 } |
332 | 333 |
333 // TODO(padolph): Need to split handling for symmetric | 334 // TODO(padolph): Need to split handling for symmetric (raw format) and |
| 335 // asymmetric (spki or pkcs8 format) keys. |
334 // Currently only supporting symmetric. | 336 // Currently only supporting symmetric. |
335 | 337 |
336 // Symmetric keys are always type secret | 338 // Symmetric keys are always type secret |
337 blink::WebCryptoKeyType type = blink::WebCryptoKeyTypeSecret; | 339 blink::WebCryptoKeyType type = blink::WebCryptoKeyTypeSecret; |
338 | 340 |
339 const unsigned char* raw_key_data; | 341 const unsigned char* raw_key_data; |
340 unsigned raw_key_data_size; | 342 unsigned raw_key_data_size; |
341 switch (format) { | 343 switch (format) { |
342 case blink::WebCryptoKeyFormatRaw: | 344 case blink::WebCryptoKeyFormatRaw: |
343 raw_key_data = key_data; | 345 raw_key_data = key_data; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 490 |
489 break; | 491 break; |
490 } | 492 } |
491 default: | 493 default: |
492 return false; | 494 return false; |
493 } | 495 } |
494 return true; | 496 return true; |
495 } | 497 } |
496 | 498 |
497 } // namespace content | 499 } // namespace content |
OLD | NEW |