| 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 #ifndef CRYPTO_CURVE25519_H | |
| 6 #define CRYPTO_CURVE25519_H | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include "crypto/crypto_export.h" | |
| 12 | |
| 13 namespace crypto { | |
| 14 | |
| 15 // Curve25519 implements the elliptic curve group known as Curve25519, as | |
| 16 // described in "Curve 25519: new Diffie-Hellman Speed Records", | |
| 17 // by D.J. Bernstein. Additional information is available at | |
| 18 // http://cr.yp.to/ecdh.html. | |
| 19 // | |
| 20 // TODO(davidben): Once iOS is switched to BoringSSL (https://crbug.com/338886), | |
| 21 // remove this file altogether and switch callers to using BoringSSL's | |
| 22 // curve25519.h directly. | |
| 23 namespace curve25519 { | |
| 24 | |
| 25 // kBytes is the number of bytes in the result of the Diffie-Hellman operation, | |
| 26 // which is an element of GF(2^255-19). | |
| 27 static const size_t kBytes = 32; | |
| 28 | |
| 29 // kScalarBytes is the number of bytes in an element of the scalar field: | |
| 30 // GF(2^252 + 27742317777372353535851937790883648493). | |
| 31 static const size_t kScalarBytes = 32; | |
| 32 | |
| 33 // ScalarMult computes the |shared_key| from |private_key| and | |
| 34 // |peer_public_key|. This method is a wrapper for |curve25519_donna()|. It | |
| 35 // calls that function with |private_key| as |secret| and |peer_public_key| as | |
| 36 // basepoint. |private_key| should be of length |kScalarBytes| and | |
| 37 // |peer_public_key| should be of length |kBytes|. It returns true on success | |
| 38 // and false if |peer_public_key| was invalid. | |
| 39 // See the "Computing shared secrets" section of http://cr.yp.to/ecdh.html. | |
| 40 CRYPTO_EXPORT bool ScalarMult(const uint8_t* private_key, | |
| 41 const uint8_t* peer_public_key, | |
| 42 uint8_t* shared_key); | |
| 43 | |
| 44 // ScalarBaseMult computes the |public_key| from |private_key|. This method is a | |
| 45 // wrapper for |curve25519_donna()|. It calls that function with |private_key| | |
| 46 // as |secret| and |kBasePoint| as basepoint. |private_key| should be of length | |
| 47 // |kScalarBytes|. See "Computing public keys" section of | |
| 48 // http://cr.yp.to/ecdh.html. | |
| 49 CRYPTO_EXPORT void ScalarBaseMult(const uint8_t* private_key, | |
| 50 uint8_t* public_key); | |
| 51 | |
| 52 } // namespace curve25519 | |
| 53 | |
| 54 } // namespace crypto | |
| 55 | |
| 56 #endif // CRYPTO_CURVE25519_H | |
| OLD | NEW |