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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 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_utils.h ('k') | net/quic/crypto/curve25519_key_exchange.h » ('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 12 matching lines...) Expand all
23 23
24 // static 24 // static
25 void CryptoUtils::GenerateNonce(QuicWallTime now, 25 void CryptoUtils::GenerateNonce(QuicWallTime now,
26 QuicRandom* random_generator, 26 QuicRandom* random_generator,
27 StringPiece orbit, 27 StringPiece orbit,
28 string* nonce) { 28 string* nonce) {
29 // a 4-byte timestamp + 28 random bytes. 29 // a 4-byte timestamp + 28 random bytes.
30 nonce->reserve(kNonceSize); 30 nonce->reserve(kNonceSize);
31 nonce->resize(kNonceSize); 31 nonce->resize(kNonceSize);
32 32
33 uint32 gmt_unix_time = static_cast<uint32>(now.ToUNIXSeconds()); 33 uint32_t gmt_unix_time = static_cast<uint32_t>(now.ToUNIXSeconds());
34 // The time in the nonce must be encoded in big-endian because the 34 // The time in the nonce must be encoded in big-endian because the
35 // strike-register depends on the nonces being ordered by time. 35 // strike-register depends on the nonces being ordered by time.
36 (*nonce)[0] = static_cast<char>(gmt_unix_time >> 24); 36 (*nonce)[0] = static_cast<char>(gmt_unix_time >> 24);
37 (*nonce)[1] = static_cast<char>(gmt_unix_time >> 16); 37 (*nonce)[1] = static_cast<char>(gmt_unix_time >> 16);
38 (*nonce)[2] = static_cast<char>(gmt_unix_time >> 8); 38 (*nonce)[2] = static_cast<char>(gmt_unix_time >> 8);
39 (*nonce)[3] = static_cast<char>(gmt_unix_time); 39 (*nonce)[3] = static_cast<char>(gmt_unix_time);
40 size_t bytes_written = 4; 40 size_t bytes_written = 4;
41 41
42 if (orbit.size() == 8) { 42 if (orbit.size() == 8) {
43 memcpy(&(*nonce)[bytes_written], orbit.data(), orbit.size()); 43 memcpy(&(*nonce)[bytes_written], orbit.data(), orbit.size());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 StringPiece context, 133 StringPiece context,
134 size_t result_len, 134 size_t result_len,
135 string* result) { 135 string* result) {
136 for (size_t i = 0; i < label.length(); i++) { 136 for (size_t i = 0; i < label.length(); i++) {
137 if (label[i] == '\0') { 137 if (label[i] == '\0') {
138 LOG(ERROR) << "ExportKeyingMaterial label may not contain NULs"; 138 LOG(ERROR) << "ExportKeyingMaterial label may not contain NULs";
139 return false; 139 return false;
140 } 140 }
141 } 141 }
142 // Create HKDF info input: null-terminated label + length-prefixed context 142 // Create HKDF info input: null-terminated label + length-prefixed context
143 if (context.length() >= numeric_limits<uint32>::max()) { 143 if (context.length() >= numeric_limits<uint32_t>::max()) {
144 LOG(ERROR) << "Context value longer than 2^32"; 144 LOG(ERROR) << "Context value longer than 2^32";
145 return false; 145 return false;
146 } 146 }
147 uint32 context_length = static_cast<uint32>(context.length()); 147 uint32_t context_length = static_cast<uint32_t>(context.length());
148 string info = label.as_string(); 148 string info = label.as_string();
149 info.push_back('\0'); 149 info.push_back('\0');
150 info.append(reinterpret_cast<char*>(&context_length), sizeof(context_length)); 150 info.append(reinterpret_cast<char*>(&context_length), sizeof(context_length));
151 info.append(context.data(), context.length()); 151 info.append(context.data(), context.length());
152 152
153 crypto::HKDF hkdf(subkey_secret, StringPiece() /* no salt */, info, 153 crypto::HKDF hkdf(subkey_secret, StringPiece() /* no salt */, info,
154 result_len, 0 /* no fixed IV */, 0 /* no subkey secret */); 154 result_len, 0 /* no fixed IV */, 0 /* no subkey secret */);
155 hkdf.client_write_key().CopyToString(result); 155 hkdf.client_write_key().CopyToString(result);
156 return true; 156 return true;
157 } 157 }
158 158
159 // static 159 // static
160 uint64 CryptoUtils::ComputeLeafCertHash(const std::string& cert) { 160 uint64_t CryptoUtils::ComputeLeafCertHash(const std::string& cert) {
161 return QuicUtils::FNV1a_64_Hash(cert.data(), cert.size()); 161 return QuicUtils::FNV1a_64_Hash(cert.data(), cert.size());
162 } 162 }
163 163
164 QuicErrorCode CryptoUtils::ValidateServerHello( 164 QuicErrorCode CryptoUtils::ValidateServerHello(
165 const CryptoHandshakeMessage& server_hello, 165 const CryptoHandshakeMessage& server_hello,
166 const QuicVersionVector& negotiated_versions, 166 const QuicVersionVector& negotiated_versions,
167 string* error_details) { 167 string* error_details) {
168 DCHECK(error_details != nullptr); 168 DCHECK(error_details != nullptr);
169 169
170 if (server_hello.tag() != kSHLO) { 170 if (server_hello.tag() != kSHLO) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 RETURN_STRING_LITERAL(INVALID_EXPECTED_LEAF_CERTIFICATE); 268 RETURN_STRING_LITERAL(INVALID_EXPECTED_LEAF_CERTIFICATE);
269 RETURN_STRING_LITERAL(MAX_FAILURE_REASON); 269 RETURN_STRING_LITERAL(MAX_FAILURE_REASON);
270 } 270 }
271 // Return a default value so that we return this when |reason| doesn't match 271 // Return a default value so that we return this when |reason| doesn't match
272 // any HandshakeFailureReason.. This can happen when the message by the peer 272 // any HandshakeFailureReason.. This can happen when the message by the peer
273 // (attacker) has invalid reason. 273 // (attacker) has invalid reason.
274 return "INVALID_HANDSHAKE_FAILURE_REASON"; 274 return "INVALID_HANDSHAKE_FAILURE_REASON";
275 } 275 }
276 276
277 } // namespace net 277 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_utils.h ('k') | net/quic/crypto/curve25519_key_exchange.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698