Botan: src/pubkey/ecdh/ecdh.cpp Source File

Botan 1.10.16

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
15 ECDH_KA_Operation::ECDH_KA_Operation(const ECDH_PrivateKey& key) :
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
23 SecureVector<byte> ECDH_KA_Operation::agree(const byte w[], size_t w_len)
24 {
25 PointGFp point = OS2ECP(w, w_len, curve);
26
27 PointGFp S = (cofactor * point) * l_times_priv;
28
29 BOTAN_ASSERT(S.on_the_curve(),
30 "ECDH agreed value not on the curve");
31
32 return BigInt::encode_1363(S.get_affine_x(),
33 curve.get_p().bytes());
34 }
35
36 }
Botan::ECDH_KA_Operation::agree
SecureVector< byte > agree(const byte w[], size_t w_len)
Definition: ecdh.cpp:23
Botan::EC_PrivateKey::private_value
const BigInt & private_value() const
Definition: ecc_key.cpp:70
Botan::PointGFp
Definition: point_gfp.h:41
Botan::OS2ECP
PointGFp OS2ECP(const byte data[], size_t data_len, const CurveGFp &curve)
Definition: point_gfp.cpp:562
Botan::PointGFp::get_affine_x
BigInt get_affine_x() const
Definition: point_gfp.cpp:400
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, msg)
Definition: assert.h:19
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::EC_PublicKey::domain
const EC_Group & domain() const
Definition: ecc_key.h:60
Botan
Definition: algo_base.h:14
Botan::ECDH_KA_Operation::ECDH_KA_Operation
ECDH_KA_Operation(const ECDH_PrivateKey &key)
Definition: ecdh.cpp:15
Botan::BigInt::bytes
size_t bytes() const
Definition: bigint.cpp:245
Botan::EC_Group::get_order
const BigInt & get_order() const
Definition: ec_group.h:101
Botan::PointGFp::on_the_curve
bool on_the_curve() const
Definition: point_gfp.cpp:427
Botan::inverse_mod
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:314
Botan::SecureVector< byte >
Botan::ECDH_PrivateKey
Definition: ecdh.h:65
Botan::CurveGFp::get_p
const BigInt & get_p() const
Definition: curve_gfp.h:64
Botan::BigInt::encode_1363
static SecureVector< byte > encode_1363(const BigInt &n, size_t bytes)
Definition: big_code.cpp:78