diff options
author | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-08 23:40:42 +0000 |
---|---|---|
committer | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-08 23:40:42 +0000 |
commit | b75d8e421243371fa43f83b72ff68aa37342b84a (patch) | |
tree | f2fe097d3145b00580a6f06ecd56a86eb43efa1f /crypto/curve25519.h | |
parent | 45d1f5634d022ef57001186125eb098c555c35a1 (diff) | |
download | chromium_src-b75d8e421243371fa43f83b72ff68aa37342b84a.zip chromium_src-b75d8e421243371fa43f83b72ff68aa37342b84a.tar.gz chromium_src-b75d8e421243371fa43f83b72ff68aa37342b84a.tar.bz2 |
Added Curve25519-donna changes.
Added a wrapper class that implements the following API calls which for
Curve25519.
+ ScalarMult to compute the shared key.
+ ScalarBaseMult to get public key.
+ ConvertToPrivateKey returns a private key from random bytes.
Per agl/wtc, grabbed the rev 234205ff from the git repo
(https://github.com/agl/curve25519-donna/tree/234205ff1ecaf6b3c1dc76798a462c4293f31fdb)
and checked it in to crypto/ because that version has pure Google copyright.
R=wtc@chromium.org,agl@chromium.org,rsleevi@chromium.org
TEST=crypto unit tests
Review URL: https://chromiumcodereview.appspot.com/12457004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187074 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/curve25519.h')
-rw-r--r-- | crypto/curve25519.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/crypto/curve25519.h b/crypto/curve25519.h new file mode 100644 index 0000000..ba24c92 --- /dev/null +++ b/crypto/curve25519.h @@ -0,0 +1,48 @@ +// 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. + +#ifndef CRYPTO_CURVE25519_H +#define CRYPTO_CURVE25519_H + +#include "base/basictypes.h" +#include "crypto/crypto_export.h" + +namespace crypto { + +// Curve25519 implements the elliptic curve group known as Curve25519, as +// described in "Curve 25519: new Diffie-Hellman Speed Records", +// by D.J. Bernstein. Additional information is available at +// http://cr.yp.to/ecdh.html. +namespace curve25519 { + +// kBytes is the number of bytes in the result of the Diffie-Hellman operation, +// which is an element of GF(2^255-19). +static const size_t kBytes = 32; + +// kScalarBytes is the number of bytes in an element of the scalar field: +// GF(2^252 + 27742317777372353535851937790883648493). +static const size_t kScalarBytes = 32; + +// ScalarMult computes the |shared_key| from |private_key| and +// |peer_public_key|. This method is a wrapper for |curve25519_donna()|. It +// calls that function with |private_key| as |secret| and |peer_public_key| as +// basepoint. |private_key| should be of length |kScalarBytes| and +// |peer_public_key| should be of length |kBytes|. +// See "Computing shared secrets" section of/ http://cr.yp.to/ecdh.html. +CRYPTO_EXPORT void ScalarMult(const uint8* private_key, + const uint8* peer_public_key, + uint8* shared_key); + +// ScalarBaseMult computes the |public_key| from |private_key|. This method is a +// wrapper for |curve25519_donna()|. It calls that function with |private_key| +// as |secret| and |kBasePoint| as basepoint. |private_key| should be of length +// |kScalarBytes|. See "Computing public keys" section of +// http://cr.yp.to/ecdh.html. +CRYPTO_EXPORT void ScalarBaseMult(const uint8* private_key, uint8* public_key); + +} // namespace curve25519 + +} // namespace crypto + +#endif // CRYPTO_CURVE25519_H |