Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Unified Diff: crypto/curve25519.cc

Issue 12457004: Curve25519-donna changes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: crypto/curve25519.cc
===================================================================
--- crypto/curve25519.cc (revision 0)
+++ crypto/curve25519.cc (revision 0)
@@ -0,0 +1,38 @@
+// 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"
+
+// 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);
wtc 2013/03/06 21:26:44 agl: |shared_key| is the x coordinate of the resul
agl 2013/03/06 21:47:50 Curve25519 is specified in terms of byte strings,
ramant (doing other things) 2013/03/08 00:10:15 Done.
ramant (doing other things) 2013/03/08 00:10:15 Added agl's comments to the file. Hope that is ok.
+}
+
+// kBasePoint is the base point (generator) of the elliptic curve group.
+static const unsigned char kBasePoint[32] = {9};
Ryan Sleevi 2013/03/06 21:18:32 Can you provide more comments explaining the sourc
agl 2013/03/06 21:47:50 It's defined as a magic value by the API. (It happ
ramant (doing other things) 2013/03/08 00:10:15 Done.
+
+void ScalarBaseMult(const uint8* private_key, uint8* public_key) {
+ curve25519_donna(public_key, private_key, kBasePoint);
+}
+
+void ConvertToPrivateKey(uint8* secret) {
+ // This makes |secret| a valid scalar, as specified on
+ // http://cr.yp.to/ecdh.html
+ secret[0] &= 248;
+ secret[31] &= 127;
+ secret[31] |= 64;
Ryan Sleevi 2013/03/06 21:18:32 Does our version not support curve25519_clamp? At
agl 2013/03/06 21:47:50 _clamp has been removed from the API as I recall.
ramant (doing other things) 2013/03/08 00:10:15 Added a reference to the section in the paper. Do
+}
+
+} // namespace curve25519
+
+} // namespace crypto

Powered by Google App Engine
This is Rietveld 408576698