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

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

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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/crypto/crypto_framer.cc ('k') | net/quic/crypto/p256_key_exchange_nss.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) 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/base/net_util.h" 8 #include "net/base/net_util.h"
9 #include "net/quic/crypto/crypto_handshake.h" 9 #include "net/quic/crypto/crypto_handshake.h"
10 #include "net/quic/crypto/crypto_protocol.h" 10 #include "net/quic/crypto/crypto_protocol.h"
(...skipping 10 matching lines...) Expand all
21 namespace net { 21 namespace net {
22 22
23 // static 23 // static
24 void CryptoUtils::GenerateNonce(QuicWallTime now, 24 void CryptoUtils::GenerateNonce(QuicWallTime now,
25 QuicRandom* random_generator, 25 QuicRandom* random_generator,
26 StringPiece orbit, 26 StringPiece orbit,
27 string* nonce) { 27 string* nonce) {
28 // a 4-byte timestamp + 28 random bytes. 28 // a 4-byte timestamp + 28 random bytes.
29 nonce->reserve(kNonceSize); 29 nonce->reserve(kNonceSize);
30 nonce->resize(kNonceSize); 30 nonce->resize(kNonceSize);
31 uint32 gmt_unix_time = now.ToUNIXSeconds(); 31
32 uint32 gmt_unix_time = static_cast<uint32>(now.ToUNIXSeconds());
32 // The time in the nonce must be encoded in big-endian because the 33 // The time in the nonce must be encoded in big-endian because the
33 // strike-register depends on the nonces being ordered by time. 34 // strike-register depends on the nonces being ordered by time.
34 (*nonce)[0] = static_cast<char>(gmt_unix_time >> 24); 35 (*nonce)[0] = static_cast<char>(gmt_unix_time >> 24);
35 (*nonce)[1] = static_cast<char>(gmt_unix_time >> 16); 36 (*nonce)[1] = static_cast<char>(gmt_unix_time >> 16);
36 (*nonce)[2] = static_cast<char>(gmt_unix_time >> 8); 37 (*nonce)[2] = static_cast<char>(gmt_unix_time >> 8);
37 (*nonce)[3] = static_cast<char>(gmt_unix_time); 38 (*nonce)[3] = static_cast<char>(gmt_unix_time);
39 size_t bytes_written = 4;
38 40
39 size_t bytes_written = sizeof(gmt_unix_time);
40 if (orbit.size() == 8) { 41 if (orbit.size() == 8) {
41 memcpy(&(*nonce)[bytes_written], orbit.data(), orbit.size()); 42 memcpy(&(*nonce)[bytes_written], orbit.data(), orbit.size());
42 bytes_written += orbit.size(); 43 bytes_written += orbit.size();
43 } 44 }
45
44 random_generator->RandBytes(&(*nonce)[bytes_written], 46 random_generator->RandBytes(&(*nonce)[bytes_written],
45 kNonceSize - bytes_written); 47 kNonceSize - bytes_written);
46 } 48 }
47 49
48 // static 50 // static
49 bool CryptoUtils::IsValidSNI(StringPiece sni) { 51 bool CryptoUtils::IsValidSNI(StringPiece sni) {
50 // TODO(rtenneti): Support RFC2396 hostname. 52 // TODO(rtenneti): Support RFC2396 hostname.
51 // NOTE: Microsoft does NOT enforce this spec, so if we throw away hostnames 53 // NOTE: Microsoft does NOT enforce this spec, so if we throw away hostnames
52 // based on the above spec, we may be losing some hostnames that windows 54 // based on the above spec, we may be losing some hostnames that windows
53 // would consider valid. By far the most common hostname character NOT 55 // would consider valid. By far the most common hostname character NOT
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 StringPiece() /* no salt */, 153 StringPiece() /* no salt */,
152 info, 154 info,
153 result_len, 155 result_len,
154 0 /* no fixed IV */, 156 0 /* no fixed IV */,
155 0 /* no subkey secret */); 157 0 /* no subkey secret */);
156 hkdf.client_write_key().CopyToString(result); 158 hkdf.client_write_key().CopyToString(result);
157 return true; 159 return true;
158 } 160 }
159 161
160 } // namespace net 162 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_framer.cc ('k') | net/quic/crypto/p256_key_exchange_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698