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

Side by Side Diff: net/quic/test_tools/quic_test_utils.cc

Issue 2590313003: Use SHA-1 functions from BoringSSL directly. (Closed)
Patch Set: 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
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/quic/test_tools/quic_test_utils_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/test_tools/quic_test_utils.h" 5 #include "net/quic/test_tools/quic_test_utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/sha1.h"
11 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
12 #include "net/quic/core/crypto/crypto_framer.h" 11 #include "net/quic/core/crypto/crypto_framer.h"
13 #include "net/quic/core/crypto/crypto_handshake.h" 12 #include "net/quic/core/crypto/crypto_handshake.h"
14 #include "net/quic/core/crypto/crypto_utils.h" 13 #include "net/quic/core/crypto/crypto_utils.h"
15 #include "net/quic/core/crypto/null_encrypter.h" 14 #include "net/quic/core/crypto/null_encrypter.h"
16 #include "net/quic/core/crypto/quic_decrypter.h" 15 #include "net/quic/core/crypto/quic_decrypter.h"
17 #include "net/quic/core/crypto/quic_encrypter.h" 16 #include "net/quic/core/crypto/quic_encrypter.h"
18 #include "net/quic/core/quic_data_writer.h" 17 #include "net/quic/core/quic_data_writer.h"
19 #include "net/quic/core/quic_framer.h" 18 #include "net/quic/core/quic_framer.h"
20 #include "net/quic/core/quic_packet_creator.h" 19 #include "net/quic/core/quic_packet_creator.h"
21 #include "net/quic/core/quic_utils.h" 20 #include "net/quic/core/quic_utils.h"
22 #include "net/quic/test_tools/crypto_test_utils.h" 21 #include "net/quic/test_tools/crypto_test_utils.h"
23 #include "net/quic/test_tools/quic_connection_peer.h" 22 #include "net/quic/test_tools/quic_connection_peer.h"
24 #include "net/spdy/spdy_frame_builder.h" 23 #include "net/spdy/spdy_frame_builder.h"
25 #include "net/tools/quic/quic_per_connection_packet_writer.h" 24 #include "net/tools/quic/quic_per_connection_packet_writer.h"
25 #include "third_party/boringssl/src/include/openssl/sha.h"
26 26
27 using base::StringPiece; 27 using base::StringPiece;
28 using std::string; 28 using std::string;
29 using testing::Invoke; 29 using testing::Invoke;
30 using testing::_; 30 using testing::_;
31 31
32 namespace net { 32 namespace net {
33 33
34 namespace test { 34 namespace test {
35 35
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 #include "net/quic/core/quic_flags_list.h" 91 #include "net/quic/core/quic_flags_list.h"
92 #undef QUIC_FLAG 92 #undef QUIC_FLAG
93 } 93 }
94 94
95 QuicFlagSaver::~QuicFlagSaver() { 95 QuicFlagSaver::~QuicFlagSaver() {
96 #define QUIC_FLAG(type, flag, value) flag = value; 96 #define QUIC_FLAG(type, flag, value) flag = value;
97 #include "net/quic/core/quic_flags_list.h" 97 #include "net/quic/core/quic_flags_list.h"
98 #undef QUIC_FLAG 98 #undef QUIC_FLAG
99 } 99 }
100 100
101 string Sha1Hash(StringPiece data) {
102 char buffer[SHA_DIGEST_LENGTH];
103 SHA1(reinterpret_cast<const uint8_t*>(data.data()), data.size(),
104 reinterpret_cast<uint8_t*>(buffer));
105 return string(buffer, arraysize(buffer));
106 }
107
101 uint64_t SimpleRandom::RandUint64() { 108 uint64_t SimpleRandom::RandUint64() {
102 unsigned char hash[base::kSHA1Length]; 109 string hash =
103 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), 110 Sha1Hash(StringPiece(reinterpret_cast<char*>(&seed_), sizeof(seed_)));
104 hash); 111 DCHECK_EQ(static_cast<size_t>(SHA_DIGEST_LENGTH), hash.length());
105 memcpy(&seed_, hash, sizeof(seed_)); 112 memcpy(&seed_, hash.data(), sizeof(seed_));
106 return seed_; 113 return seed_;
107 } 114 }
108 115
109 void SimpleRandom::RandBytes(void* data, size_t len) { 116 void SimpleRandom::RandBytes(void* data, size_t len) {
110 uint8_t* real_data = static_cast<uint8_t*>(data); 117 uint8_t* real_data = static_cast<uint8_t*>(data);
111 for (size_t offset = 0; offset < len; offset++) { 118 for (size_t offset = 0; offset < len; offset++) {
112 real_data[offset] = RandUint64() & 0xff; 119 real_data[offset] = RandUint64() & 0xff;
113 } 120 }
114 } 121 }
115 122
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 // strike register worries that we've just overflowed a uint32_t time. 890 // strike register worries that we've just overflowed a uint32_t time.
884 (*server_connection)->AdvanceTime(connection_start_time); 891 (*server_connection)->AdvanceTime(connection_start_time);
885 } 892 }
886 893
887 QuicStreamId QuicClientDataStreamId(int i) { 894 QuicStreamId QuicClientDataStreamId(int i) {
888 return kClientDataStreamId1 + 2 * i; 895 return kClientDataStreamId1 + 2 * i;
889 } 896 }
890 897
891 } // namespace test 898 } // namespace test
892 } // namespace net 899 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/quic/test_tools/quic_test_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698