OLD | NEW |
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/core/crypto/curve25519_key_exchange.h" | 5 #include "net/quic/core/crypto/curve25519_key_exchange.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "net/quic/core/crypto/quic_random.h" | 9 #include "net/quic/core/crypto/quic_random.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "net/quic/platform/api/quic_test.h" |
11 | 11 |
12 using std::string; | 12 using std::string; |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 namespace test { | 15 namespace test { |
16 | 16 |
| 17 class Curve25519KeyExchangeTest : public QuicTest {}; |
| 18 |
17 // SharedKey just tests that the basic key exchange identity holds: that both | 19 // SharedKey just tests that the basic key exchange identity holds: that both |
18 // parties end up with the same key. | 20 // parties end up with the same key. |
19 TEST(Curve25519KeyExchange, SharedKey) { | 21 TEST_F(Curve25519KeyExchangeTest, SharedKey) { |
20 QuicRandom* const rand = QuicRandom::GetInstance(); | 22 QuicRandom* const rand = QuicRandom::GetInstance(); |
21 | 23 |
22 for (int i = 0; i < 5; i++) { | 24 for (int i = 0; i < 5; i++) { |
23 const string alice_key(Curve25519KeyExchange::NewPrivateKey(rand)); | 25 const string alice_key(Curve25519KeyExchange::NewPrivateKey(rand)); |
24 const string bob_key(Curve25519KeyExchange::NewPrivateKey(rand)); | 26 const string bob_key(Curve25519KeyExchange::NewPrivateKey(rand)); |
25 | 27 |
26 std::unique_ptr<Curve25519KeyExchange> alice( | 28 std::unique_ptr<Curve25519KeyExchange> alice( |
27 Curve25519KeyExchange::New(alice_key)); | 29 Curve25519KeyExchange::New(alice_key)); |
28 std::unique_ptr<Curve25519KeyExchange> bob( | 30 std::unique_ptr<Curve25519KeyExchange> bob( |
29 Curve25519KeyExchange::New(bob_key)); | 31 Curve25519KeyExchange::New(bob_key)); |
30 | 32 |
31 const QuicStringPiece alice_public(alice->public_value()); | 33 const QuicStringPiece alice_public(alice->public_value()); |
32 const QuicStringPiece bob_public(bob->public_value()); | 34 const QuicStringPiece bob_public(bob->public_value()); |
33 | 35 |
34 string alice_shared, bob_shared; | 36 string alice_shared, bob_shared; |
35 ASSERT_TRUE(alice->CalculateSharedKey(bob_public, &alice_shared)); | 37 ASSERT_TRUE(alice->CalculateSharedKey(bob_public, &alice_shared)); |
36 ASSERT_TRUE(bob->CalculateSharedKey(alice_public, &bob_shared)); | 38 ASSERT_TRUE(bob->CalculateSharedKey(alice_public, &bob_shared)); |
37 ASSERT_EQ(alice_shared, bob_shared); | 39 ASSERT_EQ(alice_shared, bob_shared); |
38 } | 40 } |
39 } | 41 } |
40 | 42 |
41 } // namespace test | 43 } // namespace test |
42 } // namespace net | 44 } // namespace net |
OLD | NEW |