| 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/core/crypto/chacha20_poly1305_decrypter.h" | 5 #include "net/quic/core/crypto/chacha20_poly1305_decrypter.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "net/quic/core/quic_utils.h" | 9 #include "net/quic/core/quic_utils.h" |
| 10 #include "net/quic/platform/api/quic_test.h" |
| 10 #include "net/quic/platform/api/quic_text_utils.h" | 11 #include "net/quic/platform/api/quic_text_utils.h" |
| 11 #include "net/quic/test_tools/quic_test_utils.h" | 12 #include "net/quic/test_tools/quic_test_utils.h" |
| 12 | 13 |
| 13 using std::string; | 14 using std::string; |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // The test vectors come from RFC 7539 Section 2.8.2. | 18 // The test vectors come from RFC 7539 Section 2.8.2. |
| 18 | 19 |
| 19 // Each test vector consists of six strings of lowercase hexadecimal digits. | 20 // Each test vector consists of six strings of lowercase hexadecimal digits. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 size_t output_length = 0; | 127 size_t output_length = 0; |
| 127 const bool success = decrypter->DecryptPacket( | 128 const bool success = decrypter->DecryptPacket( |
| 128 QuicVersionMax(), packet_number, associated_data, ciphertext, | 129 QuicVersionMax(), packet_number, associated_data, ciphertext, |
| 129 output.get(), &output_length, ciphertext.length()); | 130 output.get(), &output_length, ciphertext.length()); |
| 130 if (!success) { | 131 if (!success) { |
| 131 return nullptr; | 132 return nullptr; |
| 132 } | 133 } |
| 133 return new QuicData(output.release(), output_length, true); | 134 return new QuicData(output.release(), output_length, true); |
| 134 } | 135 } |
| 135 | 136 |
| 136 TEST(ChaCha20Poly1305DecrypterTest, Decrypt) { | 137 class ChaCha20Poly1305DecrypterTest : public QuicTest {}; |
| 138 |
| 139 TEST_F(ChaCha20Poly1305DecrypterTest, Decrypt) { |
| 137 for (size_t i = 0; test_vectors[i].key != nullptr; i++) { | 140 for (size_t i = 0; test_vectors[i].key != nullptr; i++) { |
| 138 // If not present then decryption is expected to fail. | 141 // If not present then decryption is expected to fail. |
| 139 bool has_pt = test_vectors[i].pt; | 142 bool has_pt = test_vectors[i].pt; |
| 140 | 143 |
| 141 // Decode the test vector. | 144 // Decode the test vector. |
| 142 string key = QuicTextUtils::HexDecode(test_vectors[i].key); | 145 string key = QuicTextUtils::HexDecode(test_vectors[i].key); |
| 143 string iv = QuicTextUtils::HexDecode(test_vectors[i].iv); | 146 string iv = QuicTextUtils::HexDecode(test_vectors[i].iv); |
| 144 string fixed = QuicTextUtils::HexDecode(test_vectors[i].fixed); | 147 string fixed = QuicTextUtils::HexDecode(test_vectors[i].fixed); |
| 145 string aad = QuicTextUtils::HexDecode(test_vectors[i].aad); | 148 string aad = QuicTextUtils::HexDecode(test_vectors[i].aad); |
| 146 string ct = QuicTextUtils::HexDecode(test_vectors[i].ct); | 149 string ct = QuicTextUtils::HexDecode(test_vectors[i].ct); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 165 | 168 |
| 166 EXPECT_EQ(12u, ct.size() - decrypted->length()); | 169 EXPECT_EQ(12u, ct.size() - decrypted->length()); |
| 167 ASSERT_EQ(pt.length(), decrypted->length()); | 170 ASSERT_EQ(pt.length(), decrypted->length()); |
| 168 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), | 171 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), |
| 169 pt.length(), pt.data(), pt.length()); | 172 pt.length(), pt.data(), pt.length()); |
| 170 } | 173 } |
| 171 } | 174 } |
| 172 | 175 |
| 173 } // namespace test | 176 } // namespace test |
| 174 } // namespace net | 177 } // namespace net |
| OLD | NEW |