Index: crypto/curve25519.cc |
=================================================================== |
--- crypto/curve25519.cc (revision 0) |
+++ crypto/curve25519.cc (revision 0) |
@@ -0,0 +1,50 @@ |
+// 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 <stdint.h> |
+ |
+using std::string; |
wtc
2013/03/06 19:21:07
Remove the <stdint.h> header and remove the using
ramant (doing other things)
2013/03/06 20:03:12
Done.
|
+ |
+namespace crypto { |
+ |
+namespace curve25519 { |
+ |
+#ifdef __cplusplus |
wtc
2013/03/06 19:21:07
Remove the #ifdef __cplusplus and #endif. This is
ramant (doing other things)
2013/03/06 20:03:12
Done.
|
+extern "C" { |
+#endif |
+extern int curve25519_donna(uint8_t*, const uint8_t*, const uint8_t*); |
+#ifdef __cplusplus |
+} |
+#endif |
+ |
+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. |
+static const unsigned char kBasePoint[32] = {9}; |
+ |
+void ScalarBaseMult(const uint8* private_key, uint8* public_key) { |
+ curve25519_donna(public_key, private_key, kBasePoint); |
+} |
+ |
+bool ConvertToPrivateKey(uint8* secret, size_t secret_size) { |
+ if (secret_size != kCryptoScalarMultCurve25519ScalarBytes) |
+ return false; |
+ |
+ // This makes |secret| a valid scalar, as specified on |
+ // http://cr.yp.to/ecdh.html |
+ secret[0] &= 248; |
+ secret[31] &= 127; |
+ secret[31] |= 64; |
+ return true; |
+} |
+ |
+} // namespace curve25519 |
+ |
+} // namespace crypto |