| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chacha20_poly1305_decrypter.h" | 5 #include "net/quic/crypto/chacha20_poly1305_decrypter.h" |
| 6 | 6 |
| 7 #include "net/quic/quic_flags.h" | 7 #include "net/quic/quic_flags.h" |
| 8 #include "net/quic/test_tools/quic_test_utils.h" | 8 #include "net/quic/test_tools/quic_test_utils.h" |
| 9 | 9 |
| 10 using base::StringPiece; | 10 using base::StringPiece; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 QuicData* DecryptWithNonce(ChaCha20Poly1305Decrypter* decrypter, | 75 QuicData* DecryptWithNonce(ChaCha20Poly1305Decrypter* decrypter, |
| 76 StringPiece nonce, | 76 StringPiece nonce, |
| 77 StringPiece associated_data, | 77 StringPiece associated_data, |
| 78 StringPiece ciphertext) { | 78 StringPiece ciphertext) { |
| 79 QuicPathId path_id = kDefaultPathId; | 79 QuicPathId path_id = kDefaultPathId; |
| 80 QuicPacketNumber packet_number; | 80 QuicPacketNumber packet_number; |
| 81 StringPiece nonce_prefix(nonce.data(), nonce.size() - sizeof(packet_number)); | 81 StringPiece nonce_prefix(nonce.data(), nonce.size() - sizeof(packet_number)); |
| 82 decrypter->SetNoncePrefix(nonce_prefix); | 82 decrypter->SetNoncePrefix(nonce_prefix); |
| 83 memcpy(&packet_number, nonce.data() + nonce_prefix.size(), | 83 memcpy(&packet_number, nonce.data() + nonce_prefix.size(), |
| 84 sizeof(packet_number)); | 84 sizeof(packet_number)); |
| 85 if (FLAGS_quic_include_path_id_in_iv) { | 85 path_id = static_cast<QuicPathId>( |
| 86 path_id = static_cast<QuicPathId>( | 86 packet_number >> 8 * (sizeof(packet_number) - sizeof(path_id))); |
| 87 packet_number >> 8 * (sizeof(packet_number) - sizeof(path_id))); | 87 packet_number &= UINT64_C(0x00FFFFFFFFFFFFFF); |
| 88 packet_number &= UINT64_C(0x00FFFFFFFFFFFFFF); | |
| 89 } | |
| 90 scoped_ptr<char[]> output(new char[ciphertext.length()]); | 88 scoped_ptr<char[]> output(new char[ciphertext.length()]); |
| 91 size_t output_length = 0; | 89 size_t output_length = 0; |
| 92 const bool success = decrypter->DecryptPacket( | 90 const bool success = decrypter->DecryptPacket( |
| 93 path_id, packet_number, associated_data, ciphertext, output.get(), | 91 path_id, packet_number, associated_data, ciphertext, output.get(), |
| 94 &output_length, ciphertext.length()); | 92 &output_length, ciphertext.length()); |
| 95 if (!success) { | 93 if (!success) { |
| 96 return nullptr; | 94 return nullptr; |
| 97 } | 95 } |
| 98 return new QuicData(output.release(), output_length, true); | 96 return new QuicData(output.release(), output_length, true); |
| 99 } | 97 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 EXPECT_TRUE(has_pt); | 129 EXPECT_TRUE(has_pt); |
| 132 | 130 |
| 133 ASSERT_EQ(pt.length(), decrypted->length()); | 131 ASSERT_EQ(pt.length(), decrypted->length()); |
| 134 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), | 132 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), |
| 135 pt.length(), pt.data(), pt.length()); | 133 pt.length(), pt.data(), pt.length()); |
| 136 } | 134 } |
| 137 } | 135 } |
| 138 | 136 |
| 139 } // namespace test | 137 } // namespace test |
| 140 } // namespace net | 138 } // namespace net |
| OLD | NEW |