Botan 1.10.17

ecdh.h
Go to the documentation of this file.
1 /*
2 * ECDH
3 * (C) 2007 Falko Strenzke, FlexSecure GmbH
4 * Manuel Hartl, FlexSecure GmbH
5 * (C) 2008-2010 Jack Lloyd
6 *
7 * Distributed under the terms of the Botan license
8 */
9
10 #ifndef BOTAN_ECDH_KEY_H__
11 #define BOTAN_ECDH_KEY_H__
12
13 #include <botan/ecc_key.h>
14 #include <botan/pk_ops.h>
15
16 namespace Botan {
17
18 /**
19 * This class represents ECDH Public Keys.
20 */
21 class BOTAN_DLL ECDH_PublicKey : public virtual EC_PublicKey
22 {
23 public:
24
25 ECDH_PublicKey(const AlgorithmIdentifier& alg_id,
26 const MemoryRegion<byte>& key_bits) :
27 EC_PublicKey(alg_id, key_bits) {}
28
29 /**
30 * Construct a public key from a given public point.
31 * @param dom_par the domain parameters associated with this key
32 * @param public_point the public point defining this key
33 */
34 ECDH_PublicKey(const EC_Group& dom_par,
35 const PointGFp& public_point) :
36 EC_PublicKey(dom_par, public_point) {}
37
38 /**
39 * Get this keys algorithm name.
40 * @return this keys algorithm name
41 */
42 std::string algo_name() const { return "ECDH"; }
43
44 /**
45 * Get the maximum number of bits allowed to be fed to this key.
46 * This is the bitlength of the order of the base point.
47
48 * @return maximum number of input bits
49 */
50 size_t max_input_bits() const { return domain().get_order().bits(); }
51
52 /**
53 * @return public point value
54 */
55 MemoryVector<byte> public_value() const
56 { return EC2OSP(public_point(), PointGFp::UNCOMPRESSED); }
57
58 protected:
59 ECDH_PublicKey() {}
60 };
61
62 /**
63 * This class represents ECDH Private Keys.
64 */
65 class BOTAN_DLL ECDH_PrivateKey : public ECDH_PublicKey,
66 public EC_PrivateKey,
67 public PK_Key_Agreement_Key
68 {
69 public:
70
71 ECDH_PrivateKey(const AlgorithmIdentifier& alg_id,
72 const MemoryRegion<byte>& key_bits) :
73 EC_PrivateKey(alg_id, key_bits) {}
74
75 /**
76 * Generate a new private key
77 * @param rng a random number generator
78 * @param domain parameters to used for this key
79 * @param x the private key; if zero, a new random key is generated
80 */
81 ECDH_PrivateKey(RandomNumberGenerator& rng,
82 const EC_Group& domain,
83 const BigInt& x = 0) :
84 EC_PrivateKey(rng, domain, x) {}
85
86 MemoryVector<byte> public_value() const
87 { return ECDH_PublicKey::public_value(); }
88 };
89
90 /**
91 * ECDH operation
92 */
93 class BOTAN_DLL ECDH_KA_Operation : public PK_Ops::Key_Agreement
94 {
95 public:
96 ECDH_KA_Operation(const ECDH_PrivateKey& key);
97
98 SecureVector<byte> agree(const byte w[], size_t w_len);
99 private:
100 const CurveGFp& curve;
101 const BigInt& cofactor;
102 BigInt l_times_priv;
103 };
104
105 }
106
107 #endif
Botan::ECDH_PublicKey::ECDH_PublicKey
ECDH_PublicKey()
Definition: ecdh.h:59
Botan::PointGFp::UNCOMPRESSED
Definition: point_gfp.h:45
Botan::BigInt
Definition: bigint.h:22
Botan::ECDH_PublicKey::algo_name
std::string algo_name() const
Definition: ecdh.h:42
Botan::PointGFp
Definition: point_gfp.h:41
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::ECDH_PublicKey
Definition: ecdh.h:21
Botan::ECDH_KA_Operation
Definition: ecdh.h:93
Botan::ECDH_PrivateKey::public_value
MemoryVector< byte > public_value() const
Definition: ecdh.h:86
Botan::EC_PublicKey
Definition: ecc_key.h:30
Botan::ECDH_PublicKey::max_input_bits
size_t max_input_bits() const
Definition: ecdh.h:50
Botan::EC_PrivateKey
Definition: ecc_key.h:92
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::EC2OSP
SecureVector< byte > EC2OSP(const PointGFp &point, byte format)
Definition: point_gfp.cpp:490
Botan::ECDH_PublicKey::ECDH_PublicKey
ECDH_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: ecdh.h:25
Botan::ECDH_PrivateKey::ECDH_PrivateKey
ECDH_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: ecdh.h:71
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::MemoryVector< byte >
Botan::ECDH_PrivateKey::ECDH_PrivateKey
ECDH_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition: ecdh.h:81
Botan::ECDH_PublicKey::ECDH_PublicKey
ECDH_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: ecdh.h:34
Botan::PK_Ops::Key_Agreement
Definition: pk_ops.h:145
Botan::EC_Group
Definition: ec_group.h:31
Botan::PK_Key_Agreement_Key
Definition: pk_keys.h:118
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::SecureVector< byte >
Botan::ECDH_PrivateKey
Definition: ecdh.h:65
Botan::ECDH_PublicKey::public_value
MemoryVector< byte > public_value() const
Definition: ecdh.h:55
Botan::CurveGFp
Definition: curve_gfp.h:20