| 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/crypto/chacha20_poly1305_encrypter.h" | 5 #include "net/quic/crypto/chacha20_poly1305_encrypter.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 five strings of lowercase hexadecimal digits. | 16 // Each test vector consists of five 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 const char* key; | 20 const char* key; |
| 21 const char* pt; | 21 const char* pt; |
| 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 | 26 |
| 27 const TestVector test_vectors[] = { | 27 const TestVector test_vectors[] = { |
| 28 { | 28 { |
| 29 "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110" | 29 "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110" |
| 30 "0a1007", | 30 "0a1007", |
| 31 "86d09974840bded2a5ca", "cd7cf67be39c794a", "87e229d4500845a079c0", | 31 "86d09974840bded2a5ca", "cd7cf67be39c794a", "87e229d4500845a079c0", |
| 32 "e3e446f7ede9a19b62a4677dabf4e3d24b876bb28475" // "3896e1d6" truncated. | 32 "e3e446f7ede9a19b62a4677dabf4e3d24b876bb28475" // "3896e1d6" truncated. |
| 33 }, | 33 }, |
| 34 {NULL}}; | 34 {nullptr}}; |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 namespace net { | 38 namespace net { |
| 39 namespace test { | 39 namespace test { |
| 40 | 40 |
| 41 // EncryptWithNonce wraps the |Encrypt| method of |encrypter| to allow passing | 41 // EncryptWithNonce wraps the |Encrypt| method of |encrypter| to allow passing |
| 42 // in an nonce and also to allocate the buffer needed for the ciphertext. | 42 // in an nonce and also to allocate the buffer needed for the ciphertext. |
| 43 QuicData* EncryptWithNonce(ChaCha20Poly1305Encrypter* encrypter, | 43 QuicData* EncryptWithNonce(ChaCha20Poly1305Encrypter* encrypter, |
| 44 StringPiece nonce, | 44 StringPiece nonce, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 TEST(ChaCha20Poly1305EncrypterTest, GetCiphertextSize) { | 94 TEST(ChaCha20Poly1305EncrypterTest, GetCiphertextSize) { |
| 95 ChaCha20Poly1305Encrypter encrypter; | 95 ChaCha20Poly1305Encrypter encrypter; |
| 96 EXPECT_EQ(1012u, encrypter.GetCiphertextSize(1000)); | 96 EXPECT_EQ(1012u, encrypter.GetCiphertextSize(1000)); |
| 97 EXPECT_EQ(112u, encrypter.GetCiphertextSize(100)); | 97 EXPECT_EQ(112u, encrypter.GetCiphertextSize(100)); |
| 98 EXPECT_EQ(22u, encrypter.GetCiphertextSize(10)); | 98 EXPECT_EQ(22u, encrypter.GetCiphertextSize(10)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace test | 101 } // namespace test |
| 102 } // namespace net | 102 } // namespace net |
| OLD | NEW |