| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/null_decrypter.h" | 5 #include "net/quic/crypto/null_decrypter.h" |
| 6 #include "net/quic/quic_utils.h" | 6 #include "net/quic/quic_utils.h" |
| 7 #include "net/quic/quic_data_reader.h" | 7 #include "net/quic/quic_data_reader.h" |
| 8 | 8 |
| 9 using base::StringPiece; | 9 using base::StringPiece; |
| 10 using std::string; | 10 using std::string; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 QuicData* NullDecrypter::DecryptPacket(QuicPacketSequenceNumber /*seq_number*/, | 47 QuicData* NullDecrypter::DecryptPacket(QuicPacketSequenceNumber /*seq_number*/, |
| 48 StringPiece associated_data, | 48 StringPiece associated_data, |
| 49 StringPiece ciphertext) { | 49 StringPiece ciphertext) { |
| 50 // It's worth duplicating |Decrypt|, above, in order to save a copy by using | 50 // It's worth duplicating |Decrypt|, above, in order to save a copy by using |
| 51 // the shared-data QuicData constructor directly. | 51 // the shared-data QuicData constructor directly. |
| 52 QuicDataReader reader(ciphertext.data(), ciphertext.length()); | 52 QuicDataReader reader(ciphertext.data(), ciphertext.length()); |
| 53 | 53 |
| 54 uint128 hash; | 54 uint128 hash; |
| 55 if (!ReadHash(&reader, &hash)) { | 55 if (!ReadHash(&reader, &hash)) { |
| 56 return NULL; | 56 return nullptr; |
| 57 } | 57 } |
| 58 | 58 |
| 59 StringPiece plaintext = reader.ReadRemainingPayload(); | 59 StringPiece plaintext = reader.ReadRemainingPayload(); |
| 60 | 60 |
| 61 // TODO(rch): avoid buffer copy here | 61 // TODO(rch): avoid buffer copy here |
| 62 string buffer = associated_data.as_string(); | 62 string buffer = associated_data.as_string(); |
| 63 plaintext.AppendToString(&buffer); | 63 plaintext.AppendToString(&buffer); |
| 64 | 64 |
| 65 if (hash != ComputeHash(buffer)) { | 65 if (hash != ComputeHash(buffer)) { |
| 66 return NULL; | 66 return nullptr; |
| 67 } | 67 } |
| 68 return new QuicData(plaintext.data(), plaintext.length()); | 68 return new QuicData(plaintext.data(), plaintext.length()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 StringPiece NullDecrypter::GetKey() const { return StringPiece(); } | 71 StringPiece NullDecrypter::GetKey() const { return StringPiece(); } |
| 72 | 72 |
| 73 StringPiece NullDecrypter::GetNoncePrefix() const { return StringPiece(); } | 73 StringPiece NullDecrypter::GetNoncePrefix() const { return StringPiece(); } |
| 74 | 74 |
| 75 bool NullDecrypter::ReadHash(QuicDataReader* reader, uint128* hash) { | 75 bool NullDecrypter::ReadHash(QuicDataReader* reader, uint128* hash) { |
| 76 uint64 lo; | 76 uint64 lo; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 87 | 87 |
| 88 uint128 NullDecrypter::ComputeHash(const string& data) const { | 88 uint128 NullDecrypter::ComputeHash(const string& data) const { |
| 89 uint128 correct_hash = QuicUtils::FNV1a_128_Hash(data.data(), data.length()); | 89 uint128 correct_hash = QuicUtils::FNV1a_128_Hash(data.data(), data.length()); |
| 90 uint128 mask(GG_UINT64_C(0x0), GG_UINT64_C(0xffffffff)); | 90 uint128 mask(GG_UINT64_C(0x0), GG_UINT64_C(0xffffffff)); |
| 91 mask <<= 96; | 91 mask <<= 96; |
| 92 correct_hash &= ~mask; | 92 correct_hash &= ~mask; |
| 93 return correct_hash; | 93 return correct_hash; |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace net | 96 } // namespace net |
| OLD | NEW |