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

Side by Side Diff: net/quic/core/crypto/crypto_utils.cc

Issue 2611613003: Add quic_logging (Closed)
Patch Set: fix failed test? Created 3 years, 11 months 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 (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/crypto_utils.h" 5 #include "net/quic/core/crypto/crypto_utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "crypto/hkdf.h" 9 #include "crypto/hkdf.h"
10 #include "crypto/secure_hash.h" 10 #include "crypto/secure_hash.h"
11 #include "net/base/url_util.h" 11 #include "net/base/url_util.h"
12 #include "net/quic/core/crypto/crypto_handshake.h" 12 #include "net/quic/core/crypto/crypto_handshake.h"
13 #include "net/quic/core/crypto/crypto_protocol.h" 13 #include "net/quic/core/crypto/crypto_protocol.h"
14 #include "net/quic/core/crypto/quic_decrypter.h" 14 #include "net/quic/core/crypto/quic_decrypter.h"
15 #include "net/quic/core/crypto/quic_encrypter.h" 15 #include "net/quic/core/crypto/quic_encrypter.h"
16 #include "net/quic/core/crypto/quic_random.h" 16 #include "net/quic/core/crypto/quic_random.h"
17 #include "net/quic/core/quic_time.h" 17 #include "net/quic/core/quic_time.h"
18 #include "net/quic/core/quic_utils.h" 18 #include "net/quic/core/quic_utils.h"
19 #include "net/quic/platform/api/quic_bug_tracker.h" 19 #include "net/quic/platform/api/quic_bug_tracker.h"
20 #include "net/quic/platform/api/quic_logging.h"
20 #include "url/url_canon.h" 21 #include "url/url_canon.h"
21 22
22 using base::StringPiece; 23 using base::StringPiece;
23 using std::string; 24 using std::string;
24 25
25 namespace net { 26 namespace net {
26 27
27 // static 28 // static
28 void CryptoUtils::GenerateNonce(QuicWallTime now, 29 void CryptoUtils::GenerateNonce(QuicWallTime now,
29 QuicRandom* random_generator, 30 QuicRandom* random_generator,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 179 }
179 180
180 // static 181 // static
181 bool CryptoUtils::ExportKeyingMaterial(StringPiece subkey_secret, 182 bool CryptoUtils::ExportKeyingMaterial(StringPiece subkey_secret,
182 StringPiece label, 183 StringPiece label,
183 StringPiece context, 184 StringPiece context,
184 size_t result_len, 185 size_t result_len,
185 string* result) { 186 string* result) {
186 for (size_t i = 0; i < label.length(); i++) { 187 for (size_t i = 0; i < label.length(); i++) {
187 if (label[i] == '\0') { 188 if (label[i] == '\0') {
188 LOG(ERROR) << "ExportKeyingMaterial label may not contain NULs"; 189 QUIC_LOG(ERROR) << "ExportKeyingMaterial label may not contain NULs";
189 return false; 190 return false;
190 } 191 }
191 } 192 }
192 // Create HKDF info input: null-terminated label + length-prefixed context 193 // Create HKDF info input: null-terminated label + length-prefixed context
193 if (context.length() >= std::numeric_limits<uint32_t>::max()) { 194 if (context.length() >= std::numeric_limits<uint32_t>::max()) {
194 LOG(ERROR) << "Context value longer than 2^32"; 195 QUIC_LOG(ERROR) << "Context value longer than 2^32";
195 return false; 196 return false;
196 } 197 }
197 uint32_t context_length = static_cast<uint32_t>(context.length()); 198 uint32_t context_length = static_cast<uint32_t>(context.length());
198 string info = label.as_string(); 199 string info = label.as_string();
199 info.push_back('\0'); 200 info.push_back('\0');
200 info.append(reinterpret_cast<char*>(&context_length), sizeof(context_length)); 201 info.append(reinterpret_cast<char*>(&context_length), sizeof(context_length));
201 info.append(context.data(), context.length()); 202 info.append(context.data(), context.length());
202 203
203 crypto::HKDF hkdf(subkey_secret, StringPiece() /* no salt */, info, 204 crypto::HKDF hkdf(subkey_secret, StringPiece() /* no salt */, info,
204 result_len, 0 /* no fixed IV */, 0 /* no subkey secret */); 205 result_len, 0 /* no fixed IV */, 0 /* no subkey secret */);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 const QuicData& serialized = message.GetSerialized(); 331 const QuicData& serialized = message.GetSerialized();
331 std::unique_ptr<crypto::SecureHash> hash( 332 std::unique_ptr<crypto::SecureHash> hash(
332 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); 333 crypto::SecureHash::Create(crypto::SecureHash::SHA256));
333 hash->Update(serialized.data(), serialized.length()); 334 hash->Update(serialized.data(), serialized.length());
334 uint8_t digest[32]; 335 uint8_t digest[32];
335 hash->Finish(digest, sizeof(digest)); 336 hash->Finish(digest, sizeof(digest));
336 output->assign(reinterpret_cast<const char*>(&digest), sizeof(digest)); 337 output->assign(reinterpret_cast<const char*>(&digest), sizeof(digest));
337 } 338 }
338 339
339 } // namespace net 340 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/crypto/crypto_framer_test.cc ('k') | net/quic/core/crypto/curve25519_key_exchange.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698