| 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" | |
| 11 #include "net/quic/core/crypto/crypto_handshake.h" | 10 #include "net/quic/core/crypto/crypto_handshake.h" |
| 12 #include "net/quic/core/crypto/crypto_protocol.h" | 11 #include "net/quic/core/crypto/crypto_protocol.h" |
| 13 #include "net/quic/core/crypto/quic_decrypter.h" | 12 #include "net/quic/core/crypto/quic_decrypter.h" |
| 14 #include "net/quic/core/crypto/quic_encrypter.h" | 13 #include "net/quic/core/crypto/quic_encrypter.h" |
| 15 #include "net/quic/core/crypto/quic_random.h" | 14 #include "net/quic/core/crypto/quic_random.h" |
| 16 #include "net/quic/core/quic_time.h" | 15 #include "net/quic/core/quic_time.h" |
| 17 #include "net/quic/core/quic_utils.h" | 16 #include "net/quic/core/quic_utils.h" |
| 18 #include "net/quic/platform/api/quic_bug_tracker.h" | 17 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 19 #include "net/quic/platform/api/quic_logging.h" | 18 #include "net/quic/platform/api/quic_logging.h" |
| 19 #include "third_party/boringssl/src/include/openssl/sha.h" |
| 20 | 20 |
| 21 using base::StringPiece; | 21 using base::StringPiece; |
| 22 using std::string; | 22 using std::string; |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 // static | 26 // static |
| 27 void CryptoUtils::GenerateNonce(QuicWallTime now, | 27 void CryptoUtils::GenerateNonce(QuicWallTime now, |
| 28 QuicRandom* random_generator, | 28 QuicRandom* random_generator, |
| 29 StringPiece orbit, | 29 StringPiece orbit, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 // Return a default value so that we return this when |reason| doesn't match | 288 // Return a default value so that we return this when |reason| doesn't match |
| 289 // any HandshakeFailureReason.. This can happen when the message by the peer | 289 // any HandshakeFailureReason.. This can happen when the message by the peer |
| 290 // (attacker) has invalid reason. | 290 // (attacker) has invalid reason. |
| 291 return "INVALID_HANDSHAKE_FAILURE_REASON"; | 291 return "INVALID_HANDSHAKE_FAILURE_REASON"; |
| 292 } | 292 } |
| 293 | 293 |
| 294 // static | 294 // static |
| 295 void CryptoUtils::HashHandshakeMessage(const CryptoHandshakeMessage& message, | 295 void CryptoUtils::HashHandshakeMessage(const CryptoHandshakeMessage& message, |
| 296 string* output) { | 296 string* output) { |
| 297 const QuicData& serialized = message.GetSerialized(); | 297 const QuicData& serialized = message.GetSerialized(); |
| 298 std::unique_ptr<crypto::SecureHash> hash( | 298 uint8_t digest[SHA256_DIGEST_LENGTH]; |
| 299 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 299 SHA256(reinterpret_cast<const uint8_t*>(serialized.data()), |
| 300 hash->Update(serialized.data(), serialized.length()); | 300 serialized.length(), digest); |
| 301 uint8_t digest[32]; | 301 output->assign(reinterpret_cast<const char*>(digest), sizeof(digest)); |
| 302 hash->Finish(digest, sizeof(digest)); | |
| 303 output->assign(reinterpret_cast<const char*>(&digest), sizeof(digest)); | |
| 304 } | 302 } |
| 305 | 303 |
| 306 } // namespace net | 304 } // namespace net |
| OLD | NEW |