summaryrefslogtreecommitdiffstats
path: root/net/quic
diff options
context:
space:
mode:
authorrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-09 14:58:55 +0000
committerrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-09 14:58:55 +0000
commit04f8e29bbb39c932be953372fe50ee3ba180fdeb (patch)
tree765f47f22d083d62c0e66bfe6944426e0c21ac7c /net/quic
parent5af517b94a5c8f73cb036b5bffee2e1d3b219904 (diff)
downloadchromium_src-04f8e29bbb39c932be953372fe50ee3ba180fdeb.zip
chromium_src-04f8e29bbb39c932be953372fe50ee3ba180fdeb.tar.gz
chromium_src-04f8e29bbb39c932be953372fe50ee3ba180fdeb.tar.bz2
QUIC/Crypto - Enabled curve25519 key exchange code.
R=wtc@chromium.org BUG= Review URL: https://chromiumcodereview.appspot.com/12740002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187161 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/quic')
-rw-r--r--net/quic/crypto/curve25519_key_exchange.cc44
-rw-r--r--net/quic/crypto/curve25519_key_exchange.h3
-rw-r--r--net/quic/crypto/curve25519_key_exchange_test.cc8
3 files changed, 18 insertions, 37 deletions
diff --git a/net/quic/crypto/curve25519_key_exchange.cc b/net/quic/crypto/curve25519_key_exchange.cc
index 9258dc1..a4c20fa 100644
--- a/net/quic/crypto/curve25519_key_exchange.cc
+++ b/net/quic/crypto/curve25519_key_exchange.cc
@@ -4,15 +4,10 @@
#include "net/quic/crypto/curve25519_key_exchange.h"
-#include <string.h>
-
#include "base/logging.h"
+#include "crypto/curve25519.h"
#include "net/quic/crypto/quic_random.h"
-// TODO(rtenneti): Remove the following line after support for curve25519 is
-// added.
-#define crypto_scalarmult_curve25519_SCALARBYTES 32
-
using base::StringPiece;
using std::string;
@@ -27,39 +22,31 @@ Curve25519KeyExchange::~Curve25519KeyExchange() {
// static
Curve25519KeyExchange* Curve25519KeyExchange::New(
const StringPiece& private_key) {
-// TODO(rtenneti): Add support for curve25519.
-#if 0
- crypto_scalarmult_curve25519_base(ka->public_key_, ka->private_key_);
Curve25519KeyExchange* ka;
-
// We don't want to #include the NaCl headers in the public header file, so
// we use literals for the sizes of private_key_ and public_key_. Here we
// assert that those values are equal to the values from the NaCl header.
COMPILE_ASSERT(
- sizeof(ka->private_key_) == crypto_scalarmult_curve25519_SCALARBYTES,
+ sizeof(ka->private_key_) == crypto::curve25519::kScalarBytes,
header_out_of_sync);
COMPILE_ASSERT(
- sizeof(ka->public_key_) == crypto_scalarmult_curve25519_BYTES,
+ sizeof(ka->public_key_) == crypto::curve25519::kBytes,
header_out_of_sync);
- if (private_key.size() != crypto_scalarmult_curve25519_SCALARBYTES) {
+ if (private_key.size() != crypto::curve25519::kScalarBytes) {
return NULL;
}
ka = new Curve25519KeyExchange();
memcpy(ka->private_key_, private_key.data(),
- crypto_scalarmult_curve25519_SCALARBYTES);
+ crypto::curve25519::kScalarBytes);
+ crypto::curve25519::ScalarBaseMult(ka->private_key_, ka->public_key_);
return ka;
-#else
- Curve25519KeyExchange* ka = new Curve25519KeyExchange();
- memset(ka->public_key_, 0, arraysize(ka->public_key_));
- return ka;
-#endif
}
// static
string Curve25519KeyExchange::NewPrivateKey(QuicRandom* rand) {
- uint8 private_key[crypto_scalarmult_curve25519_SCALARBYTES];
+ uint8 private_key[crypto::curve25519::kScalarBytes];
rand->RandBytes(private_key, sizeof(private_key));
// This makes |private_key| a valid scalar, as specified on
@@ -73,23 +60,18 @@ string Curve25519KeyExchange::NewPrivateKey(QuicRandom* rand) {
bool Curve25519KeyExchange::CalculateSharedKey(
const StringPiece& peer_public_value,
string* out_result) const {
-// TODO(rtenneti): Add support for curve25519.
-#if 0
- if (peer_public_value.size() != crypto_scalarmult_curve25519_BYTES) {
+ if (peer_public_value.size() != crypto::curve25519::kBytes) {
return false;
}
- uint8 result[crypto_scalarmult_curve25519_BYTES];
- crypto_scalarmult_curve25519(
- result, private_key_,
- reinterpret_cast<const uint8*>(peer_public_value.data()));
+ uint8 result[crypto::curve25519::kBytes];
+ crypto::curve25519::ScalarMult(
+ private_key_,
+ reinterpret_cast<const uint8*>(peer_public_value.data()),
+ result);
out_result->assign(reinterpret_cast<char*>(result), sizeof(result));
return true;
-#else
- out_result->assign("01234567", 8);
- return true;
-#endif
}
StringPiece Curve25519KeyExchange::public_value() const {
diff --git a/net/quic/crypto/curve25519_key_exchange.h b/net/quic/crypto/curve25519_key_exchange.h
index f2285b4..77e78e8 100644
--- a/net/quic/crypto/curve25519_key_exchange.h
+++ b/net/quic/crypto/curve25519_key_exchange.h
@@ -39,10 +39,7 @@ class NET_EXPORT_PRIVATE Curve25519KeyExchange : public KeyExchange {
private:
Curve25519KeyExchange();
-// TODO(rtenneti): Add support for curve25519.
-#if 0
uint8 private_key_[32];
-#endif
uint8 public_key_[32];
};
diff --git a/net/quic/crypto/curve25519_key_exchange_test.cc b/net/quic/crypto/curve25519_key_exchange_test.cc
index f731a5da..b1443aa0 100644
--- a/net/quic/crypto/curve25519_key_exchange_test.cc
+++ b/net/quic/crypto/curve25519_key_exchange_test.cc
@@ -4,17 +4,20 @@
#include "net/quic/crypto/curve25519_key_exchange.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/string_piece.h"
#include "net/quic/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) {
-// TODO(rtenneti): Add support for curve25519.
-#if 0
QuicRandom* const rand = QuicRandom::GetInstance();
for (int i = 0; i < 5; i++) {
@@ -34,7 +37,6 @@ TEST(Curve25519KeyExchange, SharedKey) {
ASSERT_TRUE(bob->CalculateSharedKey(alice_public, &bob_shared));
ASSERT_EQ(alice_shared, bob_shared);
}
-#endif
}
} // namespace test