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

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

Issue 14411004: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use CONFIG_VERSION insteaf of VERSION Created 7 years, 8 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 | Annotate | Revision Log
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/crypto/crypto_utils.h" 5 #include "net/quic/crypto/crypto_utils.h"
6 6
7 #include "crypto/hkdf.h" 7 #include "crypto/hkdf.h"
8 #include "net/quic/crypto/crypto_handshake.h" 8 #include "net/quic/crypto/crypto_handshake.h"
9 #include "net/quic/crypto/crypto_protocol.h" 9 #include "net/quic/crypto/crypto_protocol.h"
10 #include "net/quic/crypto/quic_decrypter.h" 10 #include "net/quic/crypto/quic_decrypter.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 void CryptoUtils::GenerateNonce(QuicTime::Delta now, 67 void CryptoUtils::GenerateNonce(QuicTime::Delta now,
68 QuicRandom* random_generator, 68 QuicRandom* random_generator,
69 StringPiece orbit, 69 StringPiece orbit,
70 string* nonce) { 70 string* nonce) {
71 // a 4-byte timestamp + 28 random bytes. 71 // a 4-byte timestamp + 28 random bytes.
72 nonce->reserve(kNonceSize); 72 nonce->reserve(kNonceSize);
73 nonce->resize(kNonceSize); 73 nonce->resize(kNonceSize);
74 uint32 gmt_unix_time = now.ToSeconds(); 74 uint32 gmt_unix_time = now.ToSeconds();
75 memcpy(&(*nonce)[0], &gmt_unix_time, sizeof(gmt_unix_time)); 75 // The time in the nonce must be encoded in big-endian because the
76 // strike-register depends on the nonces being ordered by time.
77 (*nonce)[0] = static_cast<char>(gmt_unix_time >> 24);
78 (*nonce)[1] = static_cast<char>(gmt_unix_time >> 16);
79 (*nonce)[2] = static_cast<char>(gmt_unix_time >> 8);
80 (*nonce)[3] = static_cast<char>(gmt_unix_time);
76 81
77 size_t bytes_written = sizeof(gmt_unix_time); 82 size_t bytes_written = sizeof(gmt_unix_time);
78 if (orbit.size() == 8) { 83 if (orbit.size() == 8) {
79 memcpy(&(*nonce)[bytes_written], orbit.data(), orbit.size()); 84 memcpy(&(*nonce)[bytes_written], orbit.data(), orbit.size());
80 bytes_written += orbit.size(); 85 bytes_written += orbit.size();
81 } 86 }
82 random_generator->RandBytes(&(*nonce)[bytes_written], 87 random_generator->RandBytes(&(*nonce)[bytes_written],
83 kNonceSize - bytes_written); 88 kNonceSize - bytes_written);
84 } 89 }
85 90
(...skipping 22 matching lines...) Expand all
108 params->decrypter->SetNoncePrefix(hkdf.client_write_iv()); 113 params->decrypter->SetNoncePrefix(hkdf.client_write_iv());
109 } else { 114 } else {
110 params->encrypter->SetKey(hkdf.client_write_key()); 115 params->encrypter->SetKey(hkdf.client_write_key());
111 params->encrypter->SetNoncePrefix(hkdf.client_write_iv()); 116 params->encrypter->SetNoncePrefix(hkdf.client_write_iv());
112 params->decrypter->SetKey(hkdf.server_write_key()); 117 params->decrypter->SetKey(hkdf.server_write_key());
113 params->decrypter->SetNoncePrefix(hkdf.server_write_iv()); 118 params->decrypter->SetNoncePrefix(hkdf.server_write_iv());
114 } 119 }
115 } 120 }
116 121
117 } // namespace net 122 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698