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

Side by Side Diff: net/quic/crypto/chacha20_poly1305_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
« no previous file with comments | « net/quic/crypto/chacha20_poly1305_decrypter_nss.cc ('k') | net/quic/crypto/crypto_framer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 QuicData* DecryptWithNonce(ChaCha20Poly1305Decrypter* decrypter, 74 QuicData* DecryptWithNonce(ChaCha20Poly1305Decrypter* decrypter,
75 StringPiece nonce, 75 StringPiece nonce,
76 StringPiece associated_data, 76 StringPiece associated_data,
77 StringPiece ciphertext) { 77 StringPiece ciphertext) {
78 QuicPacketSequenceNumber sequence_number; 78 QuicPacketSequenceNumber sequence_number;
79 StringPiece nonce_prefix(nonce.data(), 79 StringPiece nonce_prefix(nonce.data(),
80 nonce.size() - sizeof(sequence_number)); 80 nonce.size() - sizeof(sequence_number));
81 decrypter->SetNoncePrefix(nonce_prefix); 81 decrypter->SetNoncePrefix(nonce_prefix);
82 memcpy(&sequence_number, nonce.data() + nonce_prefix.size(), 82 memcpy(&sequence_number, nonce.data() + nonce_prefix.size(),
83 sizeof(sequence_number)); 83 sizeof(sequence_number));
84 return decrypter->DecryptPacket(sequence_number, associated_data, ciphertext); 84 scoped_ptr<char[]> output(new char[ciphertext.length()]);
85 size_t output_length = 0;
86 const bool success = decrypter->DecryptPacket(
87 sequence_number, associated_data, ciphertext, output.get(),
88 &output_length, ciphertext.length());
89 if (!success) {
90 return nullptr;
91 }
92 return new QuicData(output.release(), output_length, true);
85 } 93 }
86 94
87 TEST(ChaCha20Poly1305DecrypterTest, Decrypt) { 95 TEST(ChaCha20Poly1305DecrypterTest, Decrypt) {
88 if (!ChaCha20Poly1305Decrypter::IsSupported()) { 96 if (!ChaCha20Poly1305Decrypter::IsSupported()) {
89 LOG(INFO) << "ChaCha20+Poly1305 not supported. Test skipped."; 97 LOG(INFO) << "ChaCha20+Poly1305 not supported. Test skipped.";
90 return; 98 return;
91 } 99 }
92 100
93 for (size_t i = 0; test_vectors[i].key != nullptr; i++) { 101 for (size_t i = 0; test_vectors[i].key != nullptr; i++) {
94 // If not present then decryption is expected to fail. 102 // If not present then decryption is expected to fail.
(...skipping 27 matching lines...) Expand all
122 EXPECT_TRUE(has_pt); 130 EXPECT_TRUE(has_pt);
123 131
124 ASSERT_EQ(pt.length(), decrypted->length()); 132 ASSERT_EQ(pt.length(), decrypted->length());
125 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), 133 test::CompareCharArraysWithHexError("plaintext", decrypted->data(),
126 pt.length(), pt.data(), pt.length()); 134 pt.length(), pt.data(), pt.length());
127 } 135 }
128 } 136 }
129 137
130 } // namespace test 138 } // namespace test
131 } // namespace net 139 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/chacha20_poly1305_decrypter_nss.cc ('k') | net/quic/crypto/crypto_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698