OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "net/quic/core/crypto/strike_register.h" | 5 #include "net/quic/core/crypto/strike_register.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 return NONCE_INVALID_TIME_FAILURE; | 224 return NONCE_INVALID_TIME_FAILURE; |
225 } | 225 } |
226 | 226 |
227 // Check that the timestamp is in the current window. | 227 // Check that the timestamp is in the current window. |
228 if ((current_time > window_secs_ && | 228 if ((current_time > window_secs_ && |
229 nonce_time < (current_time - window_secs_)) || | 229 nonce_time < (current_time - window_secs_)) || |
230 nonce_time > (current_time + window_secs_)) { | 230 nonce_time > (current_time + window_secs_)) { |
231 return NONCE_INVALID_TIME_FAILURE; | 231 return NONCE_INVALID_TIME_FAILURE; |
232 } | 232 } |
233 | 233 |
234 pair<uint32_t, string> nonce = std::make_pair( | 234 std::pair<uint32_t, string> nonce = std::make_pair( |
235 nonce_time, string(reinterpret_cast<const char*>(nonce_bytes), 32)); | 235 nonce_time, string(reinterpret_cast<const char*>(nonce_bytes), 32)); |
236 | 236 |
237 set<pair<uint32_t, string>>::const_iterator it = nonces_.find(nonce); | 237 std::set<std::pair<uint32_t, string>>::const_iterator it = |
| 238 nonces_.find(nonce); |
238 if (it != nonces_.end()) { | 239 if (it != nonces_.end()) { |
239 return NONCE_NOT_UNIQUE_FAILURE; | 240 return NONCE_NOT_UNIQUE_FAILURE; |
240 } | 241 } |
241 | 242 |
242 nonces_.insert(nonce); | 243 nonces_.insert(nonce); |
243 return NONCE_OK; | 244 return NONCE_OK; |
244 } | 245 } |
245 | 246 |
246 uint32_t GetCurrentValidWindowSecs( | 247 uint32_t GetCurrentValidWindowSecs( |
247 const uint32_t current_time_external) const { | 248 const uint32_t current_time_external) const { |
(...skipping 16 matching lines...) Expand all Loading... |
264 static const uint32_t kCreationTimeFromInternalEpoch = 63115200.0; | 265 static const uint32_t kCreationTimeFromInternalEpoch = 63115200.0; |
265 uint32_t internal_epoch = 0; | 266 uint32_t internal_epoch = 0; |
266 if (creation_time_ > kCreationTimeFromInternalEpoch) { | 267 if (creation_time_ > kCreationTimeFromInternalEpoch) { |
267 internal_epoch = creation_time_ - kCreationTimeFromInternalEpoch; | 268 internal_epoch = creation_time_ - kCreationTimeFromInternalEpoch; |
268 } | 269 } |
269 | 270 |
270 return external_time - internal_epoch; | 271 return external_time - internal_epoch; |
271 } | 272 } |
272 | 273 |
273 void DropOldestEntry() { | 274 void DropOldestEntry() { |
274 set<pair<uint32_t, string>>::iterator oldest = nonces_.begin(); | 275 std::set<std::pair<uint32_t, string>>::iterator oldest = nonces_.begin(); |
275 horizon_ = oldest->first + 1; | 276 horizon_ = oldest->first + 1; |
276 nonces_.erase(oldest); | 277 nonces_.erase(oldest); |
277 } | 278 } |
278 | 279 |
279 const unsigned max_entries_; | 280 const unsigned max_entries_; |
280 const unsigned window_secs_; | 281 const unsigned window_secs_; |
281 const uint32_t creation_time_; | 282 const uint32_t creation_time_; |
282 uint8_t orbit_[8]; | 283 uint8_t orbit_[8]; |
283 uint32_t horizon_; | 284 uint32_t horizon_; |
284 | 285 |
285 set<pair<uint32_t, string>> nonces_; | 286 std::set<std::pair<uint32_t, string>> nonces_; |
286 }; | 287 }; |
287 | 288 |
288 class StrikeRegisterStressTest : public ::testing::Test {}; | 289 class StrikeRegisterStressTest : public ::testing::Test {}; |
289 | 290 |
290 TEST_F(StrikeRegisterStressTest, InOrderInsertion) { | 291 TEST_F(StrikeRegisterStressTest, InOrderInsertion) { |
291 // Fixed seed gives reproducibility for this test. | 292 // Fixed seed gives reproducibility for this test. |
292 srand(42); | 293 srand(42); |
293 | 294 |
294 unsigned max_entries = 64; | 295 unsigned max_entries = 64; |
295 uint32_t current_time = 10000, window = 200; | 296 uint32_t current_time = 10000, window = 200; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 399 } |
399 | 400 |
400 if (i != kMaxIterations) { | 401 if (i != kMaxIterations) { |
401 FAIL() << "Failed after " << i << " iterations"; | 402 FAIL() << "Failed after " << i << " iterations"; |
402 } | 403 } |
403 } | 404 } |
404 | 405 |
405 } // namespace | 406 } // namespace |
406 | 407 |
407 } // namespace net | 408 } // namespace net |
OLD | NEW |