Botan  1.11.10
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 
26  const secure_vector<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  std::vector<byte> public_value() const
56  { return unlock(EC2OSP(public_point(), PointGFp::UNCOMPRESSED)); }
57 
58  protected:
60  };
61 
62 /**
63 * This class represents ECDH Private Keys.
64 */
65 class BOTAN_DLL ECDH_PrivateKey : public ECDH_PublicKey,
66  public EC_PrivateKey,
68  {
69  public:
70 
72  const secure_vector<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  */
82  const EC_Group& domain,
83  const BigInt& x = 0) :
84  EC_PrivateKey(rng, domain, x) {}
85 
86  std::vector<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:
97 
98  secure_vector<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
ECDH_PrivateKey(const AlgorithmIdentifier &alg_id, const secure_vector< byte > &key_bits)
Definition: ecdh.h:71
secure_vector< byte > EC2OSP(const PointGFp &point, byte format)
Definition: point_gfp.cpp:485
std::vector< byte > public_value() const
Definition: ecdh.h:55
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:92
std::vector< byte > public_value() const
Definition: ecdh.h:86
ECDH_PublicKey(const AlgorithmIdentifier &alg_id, const secure_vector< byte > &key_bits)
Definition: ecdh.h:25
uint8_t byte
Definition: types.h:30
ECDH_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition: ecdh.h:81
ECDH_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: ecdh.h:34
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:95
std::string algo_name() const
Definition: ecdh.h:42
size_t max_input_bits() const
Definition: ecdh.h:50