Botan  1.10.9
ecdh.cpp
Go to the documentation of this file.
1 /*
2 * ECDH implemenation
3 * (C) 2007 Manuel Hartl, FlexSecure GmbH
4 * 2007 Falko Strenzke, FlexSecure GmbH
5 * 2008-2010 Jack Lloyd
6 *
7 * Distributed under the terms of the Botan license
8 */
9 
10 #include <botan/ecdh.h>
11 #include <botan/internal/assert.h>
12 
13 namespace Botan {
14 
16  curve(key.domain().get_curve()),
17  cofactor(key.domain().get_cofactor())
18  {
19  l_times_priv = inverse_mod(cofactor, key.domain().get_order()) *
20  key.private_value();
21  }
22 
24  {
25  PointGFp point = OS2ECP(w, w_len, curve);
26 
27  PointGFp S = (cofactor * point) * l_times_priv;
28 
30  "ECDH agreed value not on the curve");
31 
33  curve.get_p().bytes());
34  }
35 
36 }
SecureVector< byte > agree(const byte w[], size_t w_len)
Definition: ecdh.cpp:23
const EC_Group & domain() const
Definition: ecc_key.h:60
PointGFp OS2ECP(const byte data[], size_t data_len, const CurveGFp &curve)
Definition: point_gfp.cpp:554
#define BOTAN_ASSERT(expr, msg)
Definition: assert.h:19
unsigned char byte
Definition: types.h:22
const BigInt & private_value() const
Definition: ecc_key.cpp:70
BigInt get_affine_x() const
Definition: point_gfp.cpp:392
const BigInt & get_order() const
Definition: ec_group.h:101
ECDH_KA_Operation(const ECDH_PrivateKey &key)
Definition: ecdh.cpp:15
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:202
const BigInt & get_p() const
Definition: curve_gfp.h:64
bool on_the_curve() const
Definition: point_gfp.cpp:419
static SecureVector< byte > encode_1363(const BigInt &n, size_t bytes)
Definition: big_code.cpp:78
size_t bytes() const
Definition: bigint.cpp:245