Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(739)

Side by Side Diff: components/webcrypto/algorithms/aes_ctr.cc

Issue 2528243002: Fix silent truncations when extracting values from CheckedNumeric (Closed)
Patch Set: compile fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // expects buffer sizes as an "int". 159 // expects buffer sizes as an "int".
160 base::CheckedNumeric<int> output_max_len = data.byte_length(); 160 base::CheckedNumeric<int> output_max_len = data.byte_length();
161 if (!output_max_len.IsValid()) 161 if (!output_max_len.IsValid())
162 return Status::ErrorDataTooLarge(); 162 return Status::ErrorDataTooLarge();
163 163
164 const EVP_CIPHER* const cipher = GetAESCipherByKeyLength(raw_key.size()); 164 const EVP_CIPHER* const cipher = GetAESCipherByKeyLength(raw_key.size());
165 if (!cipher) 165 if (!cipher)
166 return Status::ErrorUnexpected(); 166 return Status::ErrorUnexpected();
167 167
168 const CryptoData counter_block(params->counter()); 168 const CryptoData counter_block(params->counter());
169 buffer->resize(output_max_len.ValueOrDie()); 169 buffer->resize(base::ValueOrDieForType<size_t>(output_max_len));
170 170
171 // The total number of possible counter values is pow(2, counter_length_bits) 171 // The total number of possible counter values is pow(2, counter_length_bits)
172 bssl::UniquePtr<BIGNUM> num_counter_values(BN_new()); 172 bssl::UniquePtr<BIGNUM> num_counter_values(BN_new());
173 if (!BN_lshift(num_counter_values.get(), BN_value_one(), counter_length_bits)) 173 if (!BN_lshift(num_counter_values.get(), BN_value_one(), counter_length_bits))
174 return Status::ErrorUnexpected(); 174 return Status::ErrorUnexpected();
175 175
176 bssl::UniquePtr<BIGNUM> current_counter = 176 bssl::UniquePtr<BIGNUM> current_counter =
177 GetCounter(counter_block, counter_length_bits); 177 GetCounter(counter_block, counter_length_bits);
178 178
179 // The number of AES blocks needed for encryption/decryption. The counter is 179 // The number of AES blocks needed for encryption/decryption. The counter is
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 254 }
255 }; 255 };
256 256
257 } // namespace 257 } // namespace
258 258
259 std::unique_ptr<AlgorithmImplementation> CreateAesCtrImplementation() { 259 std::unique_ptr<AlgorithmImplementation> CreateAesCtrImplementation() {
260 return base::WrapUnique(new AesCtrImplementation); 260 return base::WrapUnique(new AesCtrImplementation);
261 } 261 }
262 262
263 } // namespace webcrypto 263 } // namespace webcrypto
OLDNEW
« no previous file with comments | « components/webcrypto/algorithms/aes_cbc.cc ('k') | content/renderer/pepper/pepper_audio_encoder_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698