Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: net/quic/crypto/aes_128_gcm_12_decrypter_test.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 QuicPacketSequenceNumber sequence_number; 260 QuicPacketSequenceNumber sequence_number;
261 StringPiece nonce_prefix(nonce.data(), 261 StringPiece nonce_prefix(nonce.data(),
262 nonce.size() - sizeof(sequence_number)); 262 nonce.size() - sizeof(sequence_number));
263 decrypter->SetNoncePrefix(nonce_prefix); 263 decrypter->SetNoncePrefix(nonce_prefix);
264 memcpy(&sequence_number, nonce.data() + nonce_prefix.size(), 264 memcpy(&sequence_number, nonce.data() + nonce_prefix.size(),
265 sizeof(sequence_number)); 265 sizeof(sequence_number));
266 return decrypter->DecryptPacket(sequence_number, associated_data, ciphertext); 266 scoped_ptr<char[]> output(new char[ciphertext.length()]);
267 size_t output_length = 0;
268 const bool success = decrypter->DecryptPacket(
269 sequence_number, associated_data, ciphertext, output.get(),
270 &output_length, ciphertext.length());
271 if (!success) {
272 return nullptr;
273 }
274 return new QuicData(output.release(), output_length, true);
267 } 275 }
268 276
269 TEST(Aes128Gcm12DecrypterTest, Decrypt) { 277 TEST(Aes128Gcm12DecrypterTest, Decrypt) {
270 for (size_t i = 0; i < arraysize(test_group_array); i++) { 278 for (size_t i = 0; i < arraysize(test_group_array); i++) {
271 SCOPED_TRACE(i); 279 SCOPED_TRACE(i);
272 const TestVector* test_vectors = test_group_array[i]; 280 const TestVector* test_vectors = test_group_array[i];
273 const TestGroupInfo& test_info = test_group_info[i]; 281 const TestGroupInfo& test_info = test_group_info[i];
274 for (size_t j = 0; test_vectors[j].key != nullptr; j++) { 282 for (size_t j = 0; test_vectors[j].key != nullptr; j++) {
275 // If not present then decryption is expected to fail. 283 // If not present then decryption is expected to fail.
276 bool has_pt = test_vectors[j].pt; 284 bool has_pt = test_vectors[j].pt;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 334
327 ASSERT_EQ(pt.length(), decrypted->length()); 335 ASSERT_EQ(pt.length(), decrypted->length());
328 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), 336 test::CompareCharArraysWithHexError("plaintext", decrypted->data(),
329 pt.length(), pt.data(), pt.length()); 337 pt.length(), pt.data(), pt.length());
330 } 338 }
331 } 339 }
332 } 340 }
333 341
334 } // namespace test 342 } // namespace test
335 } // namespace net 343 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/aes_128_gcm_12_decrypter_nss.cc ('k') | net/quic/crypto/chacha20_poly1305_decrypter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698