summaryrefslogtreecommitdiff
path: root/chromium/crypto/curve25519.cc
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
committerZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
commit679147eead574d186ebf3069647b4c23e8ccace6 (patch)
treefc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/crypto/curve25519.cc
downloadqtwebengine-chromium-679147eead574d186ebf3069647b4c23e8ccace6.tar.gz
Initial import.
Diffstat (limited to 'chromium/crypto/curve25519.cc')
-rw-r--r--chromium/crypto/curve25519.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/chromium/crypto/curve25519.cc b/chromium/crypto/curve25519.cc
new file mode 100644
index 00000000000..3346df93a1a
--- /dev/null
+++ b/chromium/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