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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "crypto/curve25519.h"
6
7 #include "crypto/third_party/curve25519-donna/curve25519-donna.h"
8
9 using std::string;
10
11 namespace crypto {
12
13 // static
14 int Curve25519::ScalarMultiply(uint8* shared_key,
15 const uint8* private_key,
16 const uint8* peer_public_key) {
17 return curve25519_donna(shared_key, private_key, peer_public_key);
18 }
19
20 // static
21 int Curve25519::ScalarMultiplyBase(uint8* public_key,
22 const uint8* private_key) {
23 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.
24 return curve25519_donna(public_key, private_key, basepoint);
25 }
26
27 // static
28 bool Curve25519::ConvertToPrivateKey(uint8* mysecret,
29 size_t mysecret_size,
30 string* private_key) {
31 if (mysecret_size != crypto_scalarmult_curve25519_SCALARBYTES)
32 return false;
33
34 // This makes |mysecret| a valid scalar, as specified on
35 // http://cr.yp.to/ecdh.html
36 mysecret[0] &= 248;
37 mysecret[31] &= 127;
38 mysecret[31] |= 64;
39 *private_key = string(reinterpret_cast<char*>(mysecret), mysecret_size);
40 return true;
41 }
42
43 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698