Chromium Code Reviews| 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 |