OLD | NEW |
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" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 StringPiece context, | 184 StringPiece context, |
185 size_t result_len, | 185 size_t result_len, |
186 string* result) { | 186 string* result) { |
187 for (size_t i = 0; i < label.length(); i++) { | 187 for (size_t i = 0; i < label.length(); i++) { |
188 if (label[i] == '\0') { | 188 if (label[i] == '\0') { |
189 LOG(ERROR) << "ExportKeyingMaterial label may not contain NULs"; | 189 LOG(ERROR) << "ExportKeyingMaterial label may not contain NULs"; |
190 return false; | 190 return false; |
191 } | 191 } |
192 } | 192 } |
193 // Create HKDF info input: null-terminated label + length-prefixed context | 193 // Create HKDF info input: null-terminated label + length-prefixed context |
194 if (context.length() >= numeric_limits<uint32_t>::max()) { | 194 if (context.length() >= std::numeric_limits<uint32_t>::max()) { |
195 LOG(ERROR) << "Context value longer than 2^32"; | 195 LOG(ERROR) << "Context value longer than 2^32"; |
196 return false; | 196 return false; |
197 } | 197 } |
198 uint32_t context_length = static_cast<uint32_t>(context.length()); | 198 uint32_t context_length = static_cast<uint32_t>(context.length()); |
199 string info = label.as_string(); | 199 string info = label.as_string(); |
200 info.push_back('\0'); | 200 info.push_back('\0'); |
201 info.append(reinterpret_cast<char*>(&context_length), sizeof(context_length)); | 201 info.append(reinterpret_cast<char*>(&context_length), sizeof(context_length)); |
202 info.append(context.data(), context.length()); | 202 info.append(context.data(), context.length()); |
203 | 203 |
204 crypto::HKDF hkdf(subkey_secret, StringPiece() /* no salt */, info, | 204 crypto::HKDF hkdf(subkey_secret, StringPiece() /* no salt */, info, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 const QuicData& serialized = message.GetSerialized(); | 331 const QuicData& serialized = message.GetSerialized(); |
332 std::unique_ptr<crypto::SecureHash> hash( | 332 std::unique_ptr<crypto::SecureHash> hash( |
333 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 333 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
334 hash->Update(serialized.data(), serialized.length()); | 334 hash->Update(serialized.data(), serialized.length()); |
335 uint8_t digest[32]; | 335 uint8_t digest[32]; |
336 hash->Finish(digest, sizeof(digest)); | 336 hash->Finish(digest, sizeof(digest)); |
337 output->assign(reinterpret_cast<const char*>(&digest), sizeof(digest)); | 337 output->assign(reinterpret_cast<const char*>(&digest), sizeof(digest)); |
338 } | 338 } |
339 | 339 |
340 } // namespace net | 340 } // namespace net |
OLD | NEW |