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

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

Issue 612323013: QUIC - (no behavior change) s/NULL/nullptr/g in .../quic/... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « net/quic/crypto/crypto_server_test.cc ('k') | net/quic/crypto/crypto_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) 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 StringPiece server_nonce, 84 StringPiece server_nonce,
85 const string& hkdf_input, 85 const string& hkdf_input,
86 Perspective perspective, 86 Perspective perspective,
87 CrypterPair* crypters, 87 CrypterPair* crypters,
88 string* subkey_secret) { 88 string* subkey_secret) {
89 crypters->encrypter.reset(QuicEncrypter::Create(aead)); 89 crypters->encrypter.reset(QuicEncrypter::Create(aead));
90 crypters->decrypter.reset(QuicDecrypter::Create(aead)); 90 crypters->decrypter.reset(QuicDecrypter::Create(aead));
91 size_t key_bytes = crypters->encrypter->GetKeySize(); 91 size_t key_bytes = crypters->encrypter->GetKeySize();
92 size_t nonce_prefix_bytes = crypters->encrypter->GetNoncePrefixSize(); 92 size_t nonce_prefix_bytes = crypters->encrypter->GetNoncePrefixSize();
93 size_t subkey_secret_bytes = 93 size_t subkey_secret_bytes =
94 subkey_secret == NULL ? 0 : premaster_secret.length(); 94 subkey_secret == nullptr ? 0 : premaster_secret.length();
95 95
96 StringPiece nonce = client_nonce; 96 StringPiece nonce = client_nonce;
97 string nonce_storage; 97 string nonce_storage;
98 if (!server_nonce.empty()) { 98 if (!server_nonce.empty()) {
99 nonce_storage = client_nonce.as_string() + server_nonce.as_string(); 99 nonce_storage = client_nonce.as_string() + server_nonce.as_string();
100 nonce = nonce_storage; 100 nonce = nonce_storage;
101 } 101 }
102 102
103 crypto::HKDF hkdf(premaster_secret, nonce, hkdf_input, key_bytes, 103 crypto::HKDF hkdf(premaster_secret, nonce, hkdf_input, key_bytes,
104 nonce_prefix_bytes, subkey_secret_bytes); 104 nonce_prefix_bytes, subkey_secret_bytes);
105 if (perspective == SERVER) { 105 if (perspective == SERVER) {
106 if (!crypters->encrypter->SetKey(hkdf.server_write_key()) || 106 if (!crypters->encrypter->SetKey(hkdf.server_write_key()) ||
107 !crypters->encrypter->SetNoncePrefix(hkdf.server_write_iv()) || 107 !crypters->encrypter->SetNoncePrefix(hkdf.server_write_iv()) ||
108 !crypters->decrypter->SetKey(hkdf.client_write_key()) || 108 !crypters->decrypter->SetKey(hkdf.client_write_key()) ||
109 !crypters->decrypter->SetNoncePrefix(hkdf.client_write_iv())) { 109 !crypters->decrypter->SetNoncePrefix(hkdf.client_write_iv())) {
110 return false; 110 return false;
111 } 111 }
112 } else { 112 } else {
113 if (!crypters->encrypter->SetKey(hkdf.client_write_key()) || 113 if (!crypters->encrypter->SetKey(hkdf.client_write_key()) ||
114 !crypters->encrypter->SetNoncePrefix(hkdf.client_write_iv()) || 114 !crypters->encrypter->SetNoncePrefix(hkdf.client_write_iv()) ||
115 !crypters->decrypter->SetKey(hkdf.server_write_key()) || 115 !crypters->decrypter->SetKey(hkdf.server_write_key()) ||
116 !crypters->decrypter->SetNoncePrefix(hkdf.server_write_iv())) { 116 !crypters->decrypter->SetNoncePrefix(hkdf.server_write_iv())) {
117 return false; 117 return false;
118 } 118 }
119 } 119 }
120 if (subkey_secret != NULL) { 120 if (subkey_secret != nullptr) {
121 hkdf.subkey_secret().CopyToString(subkey_secret); 121 hkdf.subkey_secret().CopyToString(subkey_secret);
122 } 122 }
123 123
124 return true; 124 return true;
125 } 125 }
126 126
127 // static 127 // static
128 bool CryptoUtils::ExportKeyingMaterial(StringPiece subkey_secret, 128 bool CryptoUtils::ExportKeyingMaterial(StringPiece subkey_secret,
129 StringPiece label, 129 StringPiece label,
130 StringPiece context, 130 StringPiece context,
(...skipping 20 matching lines...) Expand all
151 StringPiece() /* no salt */, 151 StringPiece() /* no salt */,
152 info, 152 info,
153 result_len, 153 result_len,
154 0 /* no fixed IV */, 154 0 /* no fixed IV */,
155 0 /* no subkey secret */); 155 0 /* no subkey secret */);
156 hkdf.client_write_key().CopyToString(result); 156 hkdf.client_write_key().CopyToString(result);
157 return true; 157 return true;
158 } 158 }
159 159
160 } // namespace net 160 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_server_test.cc ('k') | net/quic/crypto/crypto_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698