Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <stdint.h> | |
| 8 | |
| 9 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.
| |
| 10 | |
| 11 namespace crypto { | |
| 12 | |
| 13 namespace curve25519 { | |
| 14 | |
| 15 #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.
| |
| 16 extern "C" { | |
| 17 #endif | |
| 18 extern int curve25519_donna(uint8_t*, const uint8_t*, const uint8_t*); | |
| 19 #ifdef __cplusplus | |
| 20 } | |
| 21 #endif | |
| 22 | |
| 23 void ScalarMult(const uint8* private_key, | |
| 24 const uint8* peer_public_key, | |
| 25 uint8* shared_key) { | |
| 26 curve25519_donna(shared_key, private_key, peer_public_key); | |
| 27 } | |
| 28 | |
| 29 // kBasePoint is the base point (generator) of the elliptic curve group. | |
| 30 static const unsigned char kBasePoint[32] = {9}; | |
| 31 | |
| 32 void ScalarBaseMult(const uint8* private_key, uint8* public_key) { | |
| 33 curve25519_donna(public_key, private_key, kBasePoint); | |
| 34 } | |
| 35 | |
| 36 bool ConvertToPrivateKey(uint8* secret, size_t secret_size) { | |
| 37 if (secret_size != kCryptoScalarMultCurve25519ScalarBytes) | |
| 38 return false; | |
| 39 | |
| 40 // This makes |secret| a valid scalar, as specified on | |
| 41 // http://cr.yp.to/ecdh.html | |
| 42 secret[0] &= 248; | |
| 43 secret[31] &= 127; | |
| 44 secret[31] |= 64; | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 } // namespace curve25519 | |
| 49 | |
| 50 } // namespace crypto | |
| OLD | NEW |