Botan  1.11.14
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 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9 
10 #ifndef BOTAN_ECDH_KEY_H__
11 #define BOTAN_ECDH_KEY_H__
12 
13 #include <botan/ecc_key.h>
14 
15 namespace Botan {
16 
17 /**
18 * This class represents ECDH Public Keys.
19 */
20 class BOTAN_DLL ECDH_PublicKey : public virtual EC_PublicKey
21  {
22  public:
23 
25  const secure_vector<byte>& key_bits) :
26  EC_PublicKey(alg_id, key_bits) {}
27 
28  /**
29  * Construct a public key from a given public point.
30  * @param dom_par the domain parameters associated with this key
31  * @param public_point the public point defining this key
32  */
33  ECDH_PublicKey(const EC_Group& dom_par,
34  const PointGFp& public_point) :
35  EC_PublicKey(dom_par, public_point) {}
36 
37  /**
38  * Get this keys algorithm name.
39  * @return this keys algorithm name
40  */
41  std::string algo_name() const { return "ECDH"; }
42 
43  /**
44  * Get the maximum number of bits allowed to be fed to this key.
45  * This is the bitlength of the order of the base point.
46 
47  * @return maximum number of input bits
48  */
49  size_t max_input_bits() const { return domain().get_order().bits(); }
50 
51  /**
52  * @return public point value
53  */
54  std::vector<byte> public_value() const
56 
57  protected:
59  };
60 
61 /**
62 * This class represents ECDH Private Keys.
63 */
64 class BOTAN_DLL ECDH_PrivateKey : public ECDH_PublicKey,
65  public EC_PrivateKey,
67  {
68  public:
69 
71  const secure_vector<byte>& key_bits) :
72  EC_PrivateKey(alg_id, key_bits) {}
73 
74  /**
75  * Generate a new private key
76  * @param rng a random number generator
77  * @param domain parameters to used for this key
78  * @param x the private key; if zero, a new random key is generated
79  */
81  const EC_Group& domain,
82  const BigInt& x = 0) :
83  EC_PrivateKey(rng, domain, x) {}
84 
85  std::vector<byte> public_value() const
86  { return ECDH_PublicKey::public_value(); }
87  };
88 
89 }
90 
91 #endif
const BigInt & x
Definition: dsa.cpp:98
ECDH_PrivateKey(const AlgorithmIdentifier &alg_id, const secure_vector< byte > &key_bits)
Definition: ecdh.h:70
secure_vector< byte > EC2OSP(const PointGFp &point, byte format)
Definition: point_gfp.cpp:424
std::vector< byte > public_value() const
Definition: ecdh.h:54
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:93
std::vector< byte > public_value() const
Definition: ecdh.h:85
const PointGFp & public_point
Definition: ecdsa.cpp:112
ECDH_PublicKey(const AlgorithmIdentifier &alg_id, const secure_vector< byte > &key_bits)
Definition: ecdh.h:24
ECDH_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition: ecdh.h:80
ECDH_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: ecdh.h:33
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:97
std::string algo_name() const
Definition: ecdh.h:41
size_t max_input_bits() const
Definition: ecdh.h:49