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

Unified Diff: crypto/curve25519.cc

Issue 12457004: Curve25519-donna changes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 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,43 @@
+// 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 "crypto/third_party/curve25519-donna/curve25519-donna.h"
+
+using std::string;
+
+namespace crypto {
+
+// static
+int Curve25519::ScalarMultiply(uint8* shared_key,
+ const uint8* private_key,
+ const uint8* peer_public_key) {
+ return curve25519_donna(shared_key, private_key, peer_public_key);
+}
+
+// static
+int Curve25519::ScalarMultiplyBase(uint8* public_key,
+ const uint8* private_key) {
+ static const unsigned char basepoint[32] = {9};
wtc 2013/03/06 00:55:58 Nit: basepoint => kBasepoint
ramant (doing other things) 2013/03/06 19:01:05 Made the kBasePoint name similar to p224.cc Done.
+ return curve25519_donna(public_key, private_key, basepoint);
+}
+
+// static
+bool Curve25519::ConvertToPrivateKey(uint8* mysecret,
+ size_t mysecret_size,
+ string* private_key) {
+ if (mysecret_size != crypto_scalarmult_curve25519_SCALARBYTES)
+ return false;
+
+ // This makes |mysecret| a valid scalar, as specified on
+ // http://cr.yp.to/ecdh.html
+ mysecret[0] &= 248;
+ mysecret[31] &= 127;
+ mysecret[31] |= 64;
+ *private_key = string(reinterpret_cast<char*>(mysecret), mysecret_size);
+ return true;
+}
+
+} // namespace crypto

Powered by Google App Engine
This is Rietveld 408576698