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

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

Issue 1542753004: Replace last remaining NULLs in gfe/quic with nullptr. No behavior change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@110554875
Patch Set: Created 4 years, 12 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 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;
11 11
12 namespace { 12 namespace {
13 13
14 // The test vectors come from draft-agl-tls-chacha20poly1305-04 Section 7. 14 // The test vectors come from draft-agl-tls-chacha20poly1305-04 Section 7.
15 15
16 // Each test vector consists of six strings of lowercase hexadecimal digits. 16 // Each test vector consists of six strings of lowercase hexadecimal digits.
17 // The strings may be empty (zero length). A test vector with a NULL |key| 17 // The strings may be empty (zero length). A test vector with a nullptr |key|
18 // marks the end of an array of test vectors. 18 // marks the end of an array of test vectors.
19 struct TestVector { 19 struct TestVector {
20 // Input: 20 // Input:
21 const char* key; 21 const char* key;
22 const char* iv; 22 const char* iv;
23 const char* aad; 23 const char* aad;
24 const char* ct; 24 const char* ct;
25 25
26 // Expected output: 26 // Expected output:
27 const char* pt; // An empty string "" means decryption succeeded and 27 const char* pt; // An empty string "" means decryption succeeded and
28 // the plaintext is zero-length. NULL means decryption 28 // the plaintext is zero-length. NULL means decryption
29 // failed. 29 // failed.
30 }; 30 };
31 31
32 const TestVector test_vectors[] = { 32 const TestVector test_vectors[] = {
33 { "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110" 33 {"4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110"
34 "0a1007",
35 "cd7cf67be39c794a", "87e229d4500845a079c0",
36 "e3e446f7ede9a19b62a4677dabf4e3d24b876bb28475", // "3896e1d6" truncated.
37 "86d09974840bded2a5ca"},
38 // Modify the ciphertext (ChaCha20 encryption output).
39 {
40 "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110"
34 "0a1007", 41 "0a1007",
35 "cd7cf67be39c794a", 42 "cd7cf67be39c794a", "87e229d4500845a079c0",
36 "87e229d4500845a079c0", 43 "f3e446f7ede9a19b62a4677dabf4e3d24b876bb28475", // "3896e1d6"
37 "e3e446f7ede9a19b62a4677dabf4e3d24b876bb28475", // "3896e1d6" truncated. 44 // truncated.
38 "86d09974840bded2a5ca" 45 nullptr // FAIL
39 }, 46 },
40 // Modify the ciphertext (ChaCha20 encryption output). 47 // Modify the ciphertext (Poly1305 authenticator).
41 { "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110" 48 {
49 "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110"
42 "0a1007", 50 "0a1007",
43 "cd7cf67be39c794a", 51 "cd7cf67be39c794a", "87e229d4500845a079c0",
44 "87e229d4500845a079c0", 52 "e3e446f7ede9a19b62a4677dabf4e3d24b876bb28476", // "3896e1d6"
45 "f3e446f7ede9a19b62a4677dabf4e3d24b876bb28475", // "3896e1d6" truncated. 53 // truncated.
46 NULL // FAIL 54 nullptr // FAIL
47 }, 55 },
48 // Modify the ciphertext (Poly1305 authenticator). 56 // Modify the associated data.
49 { "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110" 57 {
58 "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110"
50 "0a1007", 59 "0a1007",
51 "cd7cf67be39c794a", 60 "dd7cf67be39c794a", "87e229d4500845a079c0",
52 "87e229d4500845a079c0", 61 "e3e446f7ede9a19b62a4677dabf4e3d24b876bb28475", // "3896e1d6"
53 "e3e446f7ede9a19b62a4677dabf4e3d24b876bb28476", // "3896e1d6" truncated. 62 // truncated.
54 NULL // FAIL 63 nullptr // FAIL
55 }, 64 },
56 // Modify the associated data. 65 {nullptr}};
57 { "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110"
58 "0a1007",
59 "dd7cf67be39c794a",
60 "87e229d4500845a079c0",
61 "e3e446f7ede9a19b62a4677dabf4e3d24b876bb28475", // "3896e1d6" truncated.
62 NULL // FAIL
63 },
64 { NULL }
65 };
66 66
67 } // namespace 67 } // namespace
68 68
69 namespace net { 69 namespace net {
70 namespace test { 70 namespace test {
71 71
72 // DecryptWithNonce wraps the |Decrypt| method of |decrypter| to allow passing 72 // DecryptWithNonce wraps the |Decrypt| method of |decrypter| to allow passing
73 // in an nonce and also to allocate the buffer needed for the plaintext. 73 // in an nonce and also to allocate the buffer needed for the plaintext.
74 QuicData* DecryptWithNonce(ChaCha20Poly1305Decrypter* decrypter, 74 QuicData* DecryptWithNonce(ChaCha20Poly1305Decrypter* decrypter,
75 StringPiece nonce, 75 StringPiece nonce,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 EXPECT_TRUE(has_pt); 124 EXPECT_TRUE(has_pt);
125 125
126 ASSERT_EQ(pt.length(), decrypted->length()); 126 ASSERT_EQ(pt.length(), decrypted->length());
127 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), 127 test::CompareCharArraysWithHexError("plaintext", decrypted->data(),
128 pt.length(), pt.data(), pt.length()); 128 pt.length(), pt.data(), pt.length());
129 } 129 }
130 } 130 }
131 131
132 } // namespace test 132 } // namespace test
133 } // namespace net 133 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/aes_128_gcm_12_encrypter_test.cc ('k') | net/quic/crypto/chacha20_poly1305_encrypter_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698