summaryrefslogtreecommitdiffstats
path: root/crypto/curve25519_unittest.cc
diff options
context:
space:
mode:
authorrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-08 23:40:42 +0000
committerrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-08 23:40:42 +0000
commitb75d8e421243371fa43f83b72ff68aa37342b84a (patch)
treef2fe097d3145b00580a6f06ecd56a86eb43efa1f /crypto/curve25519_unittest.cc
parent45d1f5634d022ef57001186125eb098c555c35a1 (diff)
downloadchromium_src-b75d8e421243371fa43f83b72ff68aa37342b84a.zip
chromium_src-b75d8e421243371fa43f83b72ff68aa37342b84a.tar.gz
chromium_src-b75d8e421243371fa43f83b72ff68aa37342b84a.tar.bz2
Added Curve25519-donna changes.
Added a wrapper class that implements the following API calls which for Curve25519. + ScalarMult to compute the shared key. + ScalarBaseMult to get public key. + ConvertToPrivateKey returns a private key from random bytes. Per agl/wtc, grabbed the rev 234205ff from the git repo (https://github.com/agl/curve25519-donna/tree/234205ff1ecaf6b3c1dc76798a462c4293f31fdb) and checked it in to crypto/ because that version has pure Google copyright. R=wtc@chromium.org,agl@chromium.org,rsleevi@chromium.org TEST=crypto unit tests Review URL: https://chromiumcodereview.appspot.com/12457004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187074 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/curve25519_unittest.cc')
-rw-r--r--crypto/curve25519_unittest.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/crypto/curve25519_unittest.cc b/crypto/curve25519_unittest.cc
new file mode 100644
index 0000000..0ddc422
--- /dev/null
+++ b/crypto/curve25519_unittest.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 "crypto/curve25519.h"
+
+#include <string>
+
+#include "crypto/random.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace crypto {
+
+// Test that the basic shared key exchange identity holds: that both parties end
+// up with the same shared key. This test starts with a fixed private key for
+// two parties: alice and bob. Runs ScalarBaseMult and ScalarMult to compute
+// public key and shared key for alice and bob. It asserts that alice and bob
+// have the same shared key.
+TEST(Curve25519, SharedKeyIdentity) {
+ uint8 alice_private_key[curve25519::kScalarBytes] = {3};
+ uint8 bob_private_key[curve25519::kScalarBytes] = {5};
+
+ // Get public key for alice and bob.
+ uint8 alice_public_key[curve25519::kBytes];
+ curve25519::ScalarBaseMult(alice_private_key, alice_public_key);
+
+ uint8 bob_public_key[curve25519::kBytes];
+ curve25519::ScalarBaseMult(bob_private_key, bob_public_key);
+
+ // Get the shared key for alice, by using alice's private key and bob's
+ // public key.
+ uint8 alice_shared_key[curve25519::kBytes];
+ curve25519::ScalarMult(alice_private_key, bob_public_key, alice_shared_key);
+
+ // Get the shared key for bob, by using bob's private key and alice's public
+ // key.
+ uint8 bob_shared_key[curve25519::kBytes];
+ curve25519::ScalarMult(bob_private_key, alice_public_key, bob_shared_key);
+
+ // Computed shared key of alice and bob should be the same.
+ ASSERT_EQ(0, memcmp(alice_shared_key, bob_shared_key, curve25519::kBytes));
+}
+
+} // namespace crypto