diff options
author | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-06 01:33:46 +0000 |
---|---|---|
committer | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-06 01:33:46 +0000 |
commit | 4a2dc73b301fa3bea2791952ba820db79730f0b0 (patch) | |
tree | 8bec325f5cd380ffd30d56d1bc27197c0af05818 /net/quic | |
parent | 8c426dc062e0c48c4060774bd1307ac343db380d (diff) | |
download | chromium_src-4a2dc73b301fa3bea2791952ba820db79730f0b0.zip chromium_src-4a2dc73b301fa3bea2791952ba820db79730f0b0.tar.gz chromium_src-4a2dc73b301fa3bea2791952ba820db79730f0b0.tar.bz2 |
QUIC - curve25519_key_exchange changes
Merge internal CL: 42787086
R=wtc@chromiu.org,agl@chromium.org
Review URL: https://chromiumcodereview.appspot.com/12393031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186319 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/quic')
-rw-r--r-- | net/quic/crypto/curve25519_key_exchange.cc | 6 | ||||
-rw-r--r-- | net/quic/crypto/curve25519_key_exchange.h | 2 | ||||
-rw-r--r-- | net/quic/crypto/curve25519_key_exchange_test.cc | 41 |
3 files changed, 45 insertions, 4 deletions
diff --git a/net/quic/crypto/curve25519_key_exchange.cc b/net/quic/crypto/curve25519_key_exchange.cc index 548c758..7bf503e 100644 --- a/net/quic/crypto/curve25519_key_exchange.cc +++ b/net/quic/crypto/curve25519_key_exchange.cc @@ -69,18 +69,18 @@ string Curve25519KeyExchange::NewPrivateKey(QuicRandom* rand) { } bool Curve25519KeyExchange::CalculateSharedKey( - const StringPiece& public_value, + const StringPiece& peer_public_value, string* out_result) const { // TODO(rtenneti): Add support for curve25519. #if 0 - if (public_value.size() != crypto_scalarmult_curve25519_BYTES) { + if (peer_public_value.size() != crypto_scalarmult_curve25519_BYTES) { return false; } uint8 result[crypto_scalarmult_curve25519_BYTES]; crypto_scalarmult_curve25519( result, private_key_, - reinterpret_cast<const uint8*>(public_value.data())); + reinterpret_cast<const uint8*>(peer_public_value.data())); out_result->assign(reinterpret_cast<char*>(result), sizeof(result)); return true; diff --git a/net/quic/crypto/curve25519_key_exchange.h b/net/quic/crypto/curve25519_key_exchange.h index 7a05a36..f2285b4 100644 --- a/net/quic/crypto/curve25519_key_exchange.h +++ b/net/quic/crypto/curve25519_key_exchange.h @@ -31,7 +31,7 @@ class NET_EXPORT_PRIVATE Curve25519KeyExchange : public KeyExchange { static std::string NewPrivateKey(QuicRandom* rand); // KeyExchange interface. - virtual bool CalculateSharedKey(const base::StringPiece& their_public_value, + virtual bool CalculateSharedKey(const base::StringPiece& peer_public_value, std::string* shared_key) const OVERRIDE; virtual base::StringPiece public_value() const OVERRIDE; virtual CryptoTag tag() const OVERRIDE; diff --git a/net/quic/crypto/curve25519_key_exchange_test.cc b/net/quic/crypto/curve25519_key_exchange_test.cc new file mode 100644 index 0000000..f731a5da --- /dev/null +++ b/net/quic/crypto/curve25519_key_exchange_test.cc @@ -0,0 +1,41 @@ +// 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/crypto/curve25519_key_exchange.h" + +#include "net/quic/crypto/quic_random.h" +#include "testing/gtest/include/gtest/gtest.h" + +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) { +// TODO(rtenneti): Add support for curve25519. +#if 0 + 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)); + + scoped_ptr<Curve25519KeyExchange> alice(Curve25519KeyExchange::New( + alice_key)); + scoped_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); + } +#endif +} + +} // namespace test +} // namespace net |