| 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 #include "crypto/secure_util.h" | |
| 10 | |
| 11 // Curve25519 is specified in terms of byte strings, not numbers, so all | |
| 12 // implementations take and return the same sequence of bits. So the byte | |
| 13 // order is implicitly specified as in, say, SHA1. | |
| 14 // | |
| 15 // Prototype for |curve25519_donna| function in | |
| 16 // third_party/curve25519-donna/curve25519-donna.c | |
| 17 extern "C" int curve25519_donna(uint8_t*, const uint8_t*, const uint8_t*); | |
| 18 | |
| 19 namespace crypto { | |
| 20 | |
| 21 namespace curve25519 { | |
| 22 | |
| 23 bool ScalarMult(const uint8_t* private_key, | |
| 24 const uint8_t* peer_public_key, | |
| 25 uint8_t* shared_key) { | |
| 26 curve25519_donna(shared_key, private_key, peer_public_key); | |
| 27 | |
| 28 // The all-zero output results when the input is a point of small order. | |
| 29 static const uint8_t kZeros[32] = {0}; | |
| 30 return !SecureMemEqual(shared_key, kZeros, 32); | |
| 31 } | |
| 32 | |
| 33 // kBasePoint is the base point (generator) of the elliptic curve group. | |
| 34 // It is little-endian version of '9' followed by 31 zeros. | |
| 35 // See "Computing public keys" section of http://cr.yp.to/ecdh.html. | |
| 36 static const uint8_t kBasePoint[32] = {9}; | |
| 37 | |
| 38 void ScalarBaseMult(const uint8_t* private_key, uint8_t* public_key) { | |
| 39 curve25519_donna(public_key, private_key, kBasePoint); | |
| 40 } | |
| 41 | |
| 42 } // namespace curve25519 | |
| 43 | |
| 44 } // namespace crypto | |
| OLD | NEW |