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

Side by Side Diff: net/quic/core/crypto/null_encrypter_test.cc

Issue 2679673005: Remove path id from IV in QUIC encrytion algorithms. (Closed)
Patch Set: Created 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/core/crypto/null_encrypter.h" 5 #include "net/quic/core/crypto/null_encrypter.h"
6 #include "net/quic/test_tools/quic_test_utils.h" 6 #include "net/quic/test_tools/quic_test_utils.h"
7 7
8 using base::StringPiece; 8 using base::StringPiece;
9 9
10 namespace net { 10 namespace net {
11 namespace test { 11 namespace test {
12 12
13 class NullEncrypterTest : public ::testing::TestWithParam<bool> {}; 13 class NullEncrypterTest : public ::testing::TestWithParam<bool> {};
14 14
15 TEST_F(NullEncrypterTest, EncryptClient) { 15 TEST_F(NullEncrypterTest, EncryptClient) {
16 unsigned char expected[] = { 16 unsigned char expected[] = {
17 // fnv hash 17 // fnv hash
18 0x97, 0xdc, 0x27, 0x2f, 0x18, 0xa8, 0x56, 0x73, 0xdf, 0x8d, 0x1d, 0xd0, 18 0x97, 0xdc, 0x27, 0x2f, 0x18, 0xa8, 0x56, 0x73, 0xdf, 0x8d, 0x1d, 0xd0,
19 // payload 19 // payload
20 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!', 20 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!',
21 }; 21 };
22 char encrypted[256]; 22 char encrypted[256];
23 size_t encrypted_len = 0; 23 size_t encrypted_len = 0;
24 NullEncrypter encrypter(Perspective::IS_CLIENT); 24 NullEncrypter encrypter(Perspective::IS_CLIENT);
25 ASSERT_TRUE(encrypter.EncryptPacket(QUIC_VERSION_37, kDefaultPathId, 0, 25 ASSERT_TRUE(encrypter.EncryptPacket(QUIC_VERSION_37, 0, "hello world!",
26 "hello world!", "goodbye!", encrypted, 26 "goodbye!", encrypted, &encrypted_len,
27 &encrypted_len, 256)); 27 256));
28 test::CompareCharArraysWithHexError( 28 test::CompareCharArraysWithHexError(
29 "encrypted data", encrypted, encrypted_len, 29 "encrypted data", encrypted, encrypted_len,
30 reinterpret_cast<const char*>(expected), arraysize(expected)); 30 reinterpret_cast<const char*>(expected), arraysize(expected));
31 } 31 }
32 32
33 TEST_F(NullEncrypterTest, EncryptServer) { 33 TEST_F(NullEncrypterTest, EncryptServer) {
34 unsigned char expected[] = { 34 unsigned char expected[] = {
35 // fnv hash 35 // fnv hash
36 0x63, 0x5e, 0x08, 0x03, 0x32, 0x80, 0x8f, 0x73, 0xdf, 0x8d, 0x1d, 0x1a, 36 0x63, 0x5e, 0x08, 0x03, 0x32, 0x80, 0x8f, 0x73, 0xdf, 0x8d, 0x1d, 0x1a,
37 // payload 37 // payload
38 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!', 38 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!',
39 }; 39 };
40 char encrypted[256]; 40 char encrypted[256];
41 size_t encrypted_len = 0; 41 size_t encrypted_len = 0;
42 NullEncrypter encrypter(Perspective::IS_SERVER); 42 NullEncrypter encrypter(Perspective::IS_SERVER);
43 ASSERT_TRUE(encrypter.EncryptPacket(QUIC_VERSION_37, kDefaultPathId, 0, 43 ASSERT_TRUE(encrypter.EncryptPacket(QUIC_VERSION_37, 0, "hello world!",
44 "hello world!", "goodbye!", encrypted, 44 "goodbye!", encrypted, &encrypted_len,
45 &encrypted_len, 256)); 45 256));
46 test::CompareCharArraysWithHexError( 46 test::CompareCharArraysWithHexError(
47 "encrypted data", encrypted, encrypted_len, 47 "encrypted data", encrypted, encrypted_len,
48 reinterpret_cast<const char*>(expected), arraysize(expected)); 48 reinterpret_cast<const char*>(expected), arraysize(expected));
49 } 49 }
50 50
51 TEST_F(NullEncrypterTest, EncryptClientPre37) { 51 TEST_F(NullEncrypterTest, EncryptClientPre37) {
52 unsigned char expected[] = { 52 unsigned char expected[] = {
53 // fnv hash 53 // fnv hash
54 0xa0, 0x6f, 0x44, 0x8a, 0x44, 0xf8, 0x18, 0x3b, 0x47, 0x91, 0xb2, 0x13, 54 0xa0, 0x6f, 0x44, 0x8a, 0x44, 0xf8, 0x18, 0x3b, 0x47, 0x91, 0xb2, 0x13,
55 // payload 55 // payload
56 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!', 56 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!',
57 }; 57 };
58 char encrypted[256]; 58 char encrypted[256];
59 size_t encrypted_len = 0; 59 size_t encrypted_len = 0;
60 NullEncrypter encrypter(Perspective::IS_CLIENT); 60 NullEncrypter encrypter(Perspective::IS_CLIENT);
61 ASSERT_TRUE(encrypter.EncryptPacket(QUIC_VERSION_36, kDefaultPathId, 0, 61 ASSERT_TRUE(encrypter.EncryptPacket(QUIC_VERSION_36, 0, "hello world!",
62 "hello world!", "goodbye!", encrypted, 62 "goodbye!", encrypted, &encrypted_len,
63 &encrypted_len, 256)); 63 256));
64 test::CompareCharArraysWithHexError( 64 test::CompareCharArraysWithHexError(
65 "encrypted data", encrypted, encrypted_len, 65 "encrypted data", encrypted, encrypted_len,
66 reinterpret_cast<const char*>(expected), arraysize(expected)); 66 reinterpret_cast<const char*>(expected), arraysize(expected));
67 } 67 }
68 68
69 TEST_F(NullEncrypterTest, EncryptServerPre37) { 69 TEST_F(NullEncrypterTest, EncryptServerPre37) {
70 unsigned char expected[] = { 70 unsigned char expected[] = {
71 // fnv hash 71 // fnv hash
72 0xa0, 0x6f, 0x44, 0x8a, 0x44, 0xf8, 0x18, 0x3b, 0x47, 0x91, 0xb2, 0x13, 72 0xa0, 0x6f, 0x44, 0x8a, 0x44, 0xf8, 0x18, 0x3b, 0x47, 0x91, 0xb2, 0x13,
73 // payload 73 // payload
74 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!', 74 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!',
75 }; 75 };
76 char encrypted[256]; 76 char encrypted[256];
77 size_t encrypted_len = 0; 77 size_t encrypted_len = 0;
78 NullEncrypter encrypter(Perspective::IS_SERVER); 78 NullEncrypter encrypter(Perspective::IS_SERVER);
79 ASSERT_TRUE(encrypter.EncryptPacket(QUIC_VERSION_36, kDefaultPathId, 0, 79 ASSERT_TRUE(encrypter.EncryptPacket(QUIC_VERSION_36, 0, "hello world!",
80 "hello world!", "goodbye!", encrypted, 80 "goodbye!", encrypted, &encrypted_len,
81 &encrypted_len, 256)); 81 256));
82 test::CompareCharArraysWithHexError( 82 test::CompareCharArraysWithHexError(
83 "encrypted data", encrypted, encrypted_len, 83 "encrypted data", encrypted, encrypted_len,
84 reinterpret_cast<const char*>(expected), arraysize(expected)); 84 reinterpret_cast<const char*>(expected), arraysize(expected));
85 } 85 }
86 86
87 TEST_F(NullEncrypterTest, GetMaxPlaintextSize) { 87 TEST_F(NullEncrypterTest, GetMaxPlaintextSize) {
88 NullEncrypter encrypter(Perspective::IS_CLIENT); 88 NullEncrypter encrypter(Perspective::IS_CLIENT);
89 EXPECT_EQ(1000u, encrypter.GetMaxPlaintextSize(1012)); 89 EXPECT_EQ(1000u, encrypter.GetMaxPlaintextSize(1012));
90 EXPECT_EQ(100u, encrypter.GetMaxPlaintextSize(112)); 90 EXPECT_EQ(100u, encrypter.GetMaxPlaintextSize(112));
91 EXPECT_EQ(10u, encrypter.GetMaxPlaintextSize(22)); 91 EXPECT_EQ(10u, encrypter.GetMaxPlaintextSize(22));
92 } 92 }
93 93
94 TEST_F(NullEncrypterTest, GetCiphertextSize) { 94 TEST_F(NullEncrypterTest, GetCiphertextSize) {
95 NullEncrypter encrypter(Perspective::IS_CLIENT); 95 NullEncrypter encrypter(Perspective::IS_CLIENT);
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
OLDNEW
« no previous file with comments | « net/quic/core/crypto/null_encrypter.cc ('k') | net/quic/core/crypto/quic_crypto_client_config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698