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 "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
10 #include "base/stl_util.h" | |
11 #include "components/webcrypto/algorithms/aes.h" | 10 #include "components/webcrypto/algorithms/aes.h" |
12 #include "components/webcrypto/algorithms/util.h" | 11 #include "components/webcrypto/algorithms/util.h" |
13 #include "components/webcrypto/blink_key_handle.h" | 12 #include "components/webcrypto/blink_key_handle.h" |
14 #include "components/webcrypto/crypto_data.h" | 13 #include "components/webcrypto/crypto_data.h" |
15 #include "components/webcrypto/status.h" | 14 #include "components/webcrypto/status.h" |
16 #include "crypto/openssl_util.h" | 15 #include "crypto/openssl_util.h" |
17 #include "crypto/scoped_openssl_types.h" | 16 #include "crypto/scoped_openssl_types.h" |
18 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 17 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
19 | 18 |
20 namespace webcrypto { | 19 namespace webcrypto { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 const EVP_CIPHER* const cipher = GetAESCipherByKeyLength(raw_key.size()); | 69 const EVP_CIPHER* const cipher = GetAESCipherByKeyLength(raw_key.size()); |
71 DCHECK(cipher); | 70 DCHECK(cipher); |
72 | 71 |
73 if (!EVP_CipherInit_ex(context.get(), cipher, NULL, &raw_key[0], | 72 if (!EVP_CipherInit_ex(context.get(), cipher, NULL, &raw_key[0], |
74 params->iv().data(), cipher_operation)) { | 73 params->iv().data(), cipher_operation)) { |
75 return Status::OperationError(); | 74 return Status::OperationError(); |
76 } | 75 } |
77 | 76 |
78 buffer->resize(output_max_len.ValueOrDie()); | 77 buffer->resize(output_max_len.ValueOrDie()); |
79 | 78 |
80 unsigned char* const buffer_data = vector_as_array(buffer); | |
81 | |
82 int output_len = 0; | 79 int output_len = 0; |
83 if (!EVP_CipherUpdate(context.get(), buffer_data, &output_len, data.bytes(), | 80 if (!EVP_CipherUpdate(context.get(), buffer->data(), &output_len, |
84 data.byte_length())) { | 81 data.bytes(), data.byte_length())) { |
85 return Status::OperationError(); | 82 return Status::OperationError(); |
86 } | 83 } |
87 int final_output_chunk_len = 0; | 84 int final_output_chunk_len = 0; |
88 if (!EVP_CipherFinal_ex(context.get(), buffer_data + output_len, | 85 if (!EVP_CipherFinal_ex(context.get(), buffer->data() + output_len, |
89 &final_output_chunk_len)) { | 86 &final_output_chunk_len)) { |
90 return Status::OperationError(); | 87 return Status::OperationError(); |
91 } | 88 } |
92 | 89 |
93 const unsigned int final_output_len = | 90 const unsigned int final_output_len = |
94 static_cast<unsigned int>(output_len) + | 91 static_cast<unsigned int>(output_len) + |
95 static_cast<unsigned int>(final_output_chunk_len); | 92 static_cast<unsigned int>(final_output_chunk_len); |
96 | 93 |
97 buffer->resize(final_output_len); | 94 buffer->resize(final_output_len); |
98 | 95 |
(...skipping 19 matching lines...) Expand all Loading... |
118 } | 115 } |
119 }; | 116 }; |
120 | 117 |
121 } // namespace | 118 } // namespace |
122 | 119 |
123 scoped_ptr<AlgorithmImplementation> CreateAesCbcImplementation() { | 120 scoped_ptr<AlgorithmImplementation> CreateAesCbcImplementation() { |
124 return make_scoped_ptr(new AesCbcImplementation); | 121 return make_scoped_ptr(new AesCbcImplementation); |
125 } | 122 } |
126 | 123 |
127 } // namespace webcrypto | 124 } // namespace webcrypto |
OLD | NEW |