diff options
Diffstat (limited to 'chromium/net/quic/core/crypto/curve25519_key_exchange_test.cc')
-rw-r--r-- | chromium/net/quic/core/crypto/curve25519_key_exchange_test.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/chromium/net/quic/core/crypto/curve25519_key_exchange_test.cc b/chromium/net/quic/core/crypto/curve25519_key_exchange_test.cc new file mode 100644 index 00000000000..dcd33527c1b --- /dev/null +++ b/chromium/net/quic/core/crypto/curve25519_key_exchange_test.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/quic/core/crypto/curve25519_key_exchange.h" + +#include <memory> + +#include "base/strings/string_piece.h" +#include "net/quic/core/crypto/quic_random.h" +#include "testing/gtest/include/gtest/gtest.h" + +using base::StringPiece; +using std::string; + +namespace net { +namespace test { + +// SharedKey just tests that the basic key exchange identity holds: that both +// parties end up with the same key. +TEST(Curve25519KeyExchange, SharedKey) { + QuicRandom* const rand = QuicRandom::GetInstance(); + + for (int i = 0; i < 5; i++) { + const string alice_key(Curve25519KeyExchange::NewPrivateKey(rand)); + const string bob_key(Curve25519KeyExchange::NewPrivateKey(rand)); + + std::unique_ptr<Curve25519KeyExchange> alice( + Curve25519KeyExchange::New(alice_key)); + std::unique_ptr<Curve25519KeyExchange> bob( + Curve25519KeyExchange::New(bob_key)); + + const StringPiece alice_public(alice->public_value()); + const StringPiece bob_public(bob->public_value()); + + string alice_shared, bob_shared; + ASSERT_TRUE(alice->CalculateSharedKey(bob_public, &alice_shared)); + ASSERT_TRUE(bob->CalculateSharedKey(alice_public, &bob_shared)); + ASSERT_EQ(alice_shared, bob_shared); + } +} + +} // namespace test +} // namespace net |