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/crypto/aes_128_gcm_12_decrypter.h" | 5 #include "net/quic/crypto/aes_128_gcm_12_decrypter.h" |
6 | 6 |
7 #include "net/quic/test_tools/quic_test_utils.h" | 7 #include "net/quic/test_tools/quic_test_utils.h" |
8 | 8 |
9 using base::StringPiece; | 9 using base::StringPiece; |
10 using std::string; | 10 using std::string; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 250 |
251 namespace net { | 251 namespace net { |
252 namespace test { | 252 namespace test { |
253 | 253 |
254 // DecryptWithNonce wraps the |Decrypt| method of |decrypter| to allow passing | 254 // DecryptWithNonce wraps the |Decrypt| method of |decrypter| to allow passing |
255 // in an nonce and also to allocate the buffer needed for the plaintext. | 255 // in an nonce and also to allocate the buffer needed for the plaintext. |
256 QuicData* DecryptWithNonce(Aes128Gcm12Decrypter* decrypter, | 256 QuicData* DecryptWithNonce(Aes128Gcm12Decrypter* decrypter, |
257 StringPiece nonce, | 257 StringPiece nonce, |
258 StringPiece associated_data, | 258 StringPiece associated_data, |
259 StringPiece ciphertext) { | 259 StringPiece ciphertext) { |
260 size_t plaintext_size = ciphertext.length(); | 260 QuicPacketSequenceNumber sequence_number; |
261 scoped_ptr<char[]> plaintext(new char[plaintext_size]); | 261 StringPiece nonce_prefix(nonce.data(), |
262 | 262 nonce.size() - sizeof(sequence_number)); |
263 if (!decrypter->Decrypt(nonce, associated_data, ciphertext, | 263 decrypter->SetNoncePrefix(nonce_prefix); |
264 reinterpret_cast<unsigned char*>(plaintext.get()), | 264 memcpy(&sequence_number, nonce.data() + nonce_prefix.size(), |
265 &plaintext_size)) { | 265 sizeof(sequence_number)); |
266 return nullptr; | 266 return decrypter->DecryptPacket(sequence_number, associated_data, ciphertext); |
267 } | |
268 return new QuicData(plaintext.release(), plaintext_size, true); | |
269 } | 267 } |
270 | 268 |
271 TEST(Aes128Gcm12DecrypterTest, Decrypt) { | 269 TEST(Aes128Gcm12DecrypterTest, Decrypt) { |
272 for (size_t i = 0; i < arraysize(test_group_array); i++) { | 270 for (size_t i = 0; i < arraysize(test_group_array); i++) { |
273 SCOPED_TRACE(i); | 271 SCOPED_TRACE(i); |
274 const TestVector* test_vectors = test_group_array[i]; | 272 const TestVector* test_vectors = test_group_array[i]; |
275 const TestGroupInfo& test_info = test_group_info[i]; | 273 const TestGroupInfo& test_info = test_group_info[i]; |
276 for (size_t j = 0; test_vectors[j].key != nullptr; j++) { | 274 for (size_t j = 0; test_vectors[j].key != nullptr; j++) { |
277 // If not present then decryption is expected to fail. | 275 // If not present then decryption is expected to fail. |
278 bool has_pt = test_vectors[j].pt; | 276 bool has_pt = test_vectors[j].pt; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 326 |
329 ASSERT_EQ(pt.length(), decrypted->length()); | 327 ASSERT_EQ(pt.length(), decrypted->length()); |
330 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), | 328 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), |
331 pt.length(), pt.data(), pt.length()); | 329 pt.length(), pt.data(), pt.length()); |
332 } | 330 } |
333 } | 331 } |
334 } | 332 } |
335 | 333 |
336 } // namespace test | 334 } // namespace test |
337 } // namespace net | 335 } // namespace net |
OLD | NEW |