summaryrefslogtreecommitdiffstats
path: root/crypto/curve25519.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.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.cc')
-rw-r--r--crypto/curve25519.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/crypto/curve25519.cc b/crypto/curve25519.cc
new file mode 100644
index 0000000..3346df9
--- /dev/null
+++ b/crypto/curve25519.cc
@@ -0,0 +1,36 @@
+// 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"
+
+// Curve25519 is specified in terms of byte strings, not numbers, so all
+// implementations take and return the same sequence of bits. So the byte
+// order is implicitly specified as in, say, SHA1.
+//
+// Prototype for |curve25519_donna| function in
+// third_party/curve25519-donna/curve25519-donna.c
+extern "C" int curve25519_donna(uint8*, const uint8*, const uint8*);
+
+namespace crypto {
+
+namespace curve25519 {
+
+void ScalarMult(const uint8* private_key,
+ const uint8* peer_public_key,
+ uint8* shared_key) {
+ curve25519_donna(shared_key, private_key, peer_public_key);
+}
+
+// kBasePoint is the base point (generator) of the elliptic curve group.
+// It is little-endian version of '9' followed by 31 zeros.
+// See "Computing public keys" section of http://cr.yp.to/ecdh.html.
+static const unsigned char kBasePoint[32] = {9};
+
+void ScalarBaseMult(const uint8* private_key, uint8* public_key) {
+ curve25519_donna(public_key, private_key, kBasePoint);
+}
+
+} // namespace curve25519
+
+} // namespace crypto