| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/quic/crypto/p256_key_exchange.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 using std::string; | |
| 13 | |
| 14 namespace net { | |
| 15 namespace test { | |
| 16 | |
| 17 // SharedKey just tests that the basic key exchange identity holds: that both | |
| 18 // parties end up with the same key. | |
| 19 TEST(P256KeyExchange, SharedKey) { | |
| 20 for (int i = 0; i < 5; i++) { | |
| 21 string alice_private(P256KeyExchange::NewPrivateKey()); | |
| 22 string bob_private(P256KeyExchange::NewPrivateKey()); | |
| 23 | |
| 24 ASSERT_FALSE(alice_private.empty()); | |
| 25 ASSERT_FALSE(bob_private.empty()); | |
| 26 ASSERT_NE(alice_private, bob_private); | |
| 27 | |
| 28 std::unique_ptr<P256KeyExchange> alice(P256KeyExchange::New(alice_private)); | |
| 29 std::unique_ptr<P256KeyExchange> bob(P256KeyExchange::New(bob_private)); | |
| 30 | |
| 31 ASSERT_TRUE(alice.get() != nullptr); | |
| 32 ASSERT_TRUE(bob.get() != nullptr); | |
| 33 | |
| 34 const base::StringPiece alice_public(alice->public_value()); | |
| 35 const base::StringPiece bob_public(bob->public_value()); | |
| 36 | |
| 37 std::string alice_shared, bob_shared; | |
| 38 ASSERT_TRUE(alice->CalculateSharedKey(bob_public, &alice_shared)); | |
| 39 ASSERT_TRUE(bob->CalculateSharedKey(alice_public, &bob_shared)); | |
| 40 ASSERT_EQ(alice_shared, bob_shared); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 } // namespace test | |
| 45 } // namespace net | |
| OLD | NEW |