Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 /**
24 * Create an ECDH public key.
25 * @param alg_id algorithm identifier
26 * @param key_bits DER encoded public key bits
27 */
28 ECDH_PublicKey(const AlgorithmIdentifier& alg_id,
29 const std::vector<uint8_t>& key_bits) :
30 EC_PublicKey(alg_id, key_bits) {}
31
32 /**
33 * Construct a public key from a given public point.
34 * @param dom_par the domain parameters associated with this key
35 * @param public_point the public point defining this key
36 */
37 ECDH_PublicKey(const EC_Group& dom_par,
38 const PointGFp& public_point) :
39 EC_PublicKey(dom_par, public_point) {}
40
41 /**
42 * Get this keys algorithm name.
43 * @return this keys algorithm name
44 */
45 std::string algo_name() const override { return "ECDH"; }
46
47 /**
48 * @return public point value
49 */
50 std::vector<uint8_t> public_value() const
51 { return unlock(EC2OSP(public_point(), PointGFp::UNCOMPRESSED)); }
52
53 /**
54 * @return public point value
55 */
56 std::vector<uint8_t> public_value(PointGFp::Compression_Type type) const
57 { return unlock(EC2OSP(public_point(), type)); }
58
59 protected:
60 ECDH_PublicKey() = default;
61 };
62
63 /**
64 * This class represents ECDH Private Keys.
65 */
66 class BOTAN_DLL ECDH_PrivateKey : public ECDH_PublicKey,
67 public EC_PrivateKey,
68 public PK_Key_Agreement_Key
69 {
70 public:
71
72 /**
73 * Load a private key.
74 * @param alg_id the X.509 algorithm identifier
75 * @param key_bits ECPrivateKey bits
76 */
77 ECDH_PrivateKey(const AlgorithmIdentifier& alg_id,
78 const secure_vector<uint8_t>& key_bits) :
79 EC_PrivateKey(alg_id, key_bits) {}
80
81 /**
82 * Generate a new private key
83 * @param rng a random number generator
84 * @param domain parameters to used for this key
85 * @param x the private key; if zero, a new random key is generated
86 */
87 ECDH_PrivateKey(RandomNumberGenerator& rng,
88 const EC_Group& domain,
89 const BigInt& x = 0) :
90 EC_PrivateKey(rng, domain, x) {}
91
92 std::vector<uint8_t> public_value() const override
93 { return ECDH_PublicKey::public_value(PointGFp::UNCOMPRESSED); }
94
95 std::vector<uint8_t> public_value(PointGFp::Compression_Type type) const
96 { return ECDH_PublicKey::public_value(type); }
97
98 std::unique_ptr<PK_Ops::Key_Agreement>
99 create_key_agreement_op(RandomNumberGenerator& rng,
100 const std::string& params,
101 const std::string& provider) const override;
102 };
103
104 }
105
106 #endif
Botan::ECDH_PrivateKey::ECDH_PrivateKey
ECDH_PrivateKey(const AlgorithmIdentifier &alg_id, const secure_vector< uint8_t > &key_bits)
Definition: ecdh.h:77
Botan::ECDH_PublicKey::public_value
std::vector< uint8_t > public_value() const
Definition: ecdh.h:50
Botan::PointGFp::UNCOMPRESSED
Definition: point_gfp.h:45
Botan::BigInt
Definition: bigint.h:23
Botan::ECDH_PrivateKey::public_value
std::vector< uint8_t > public_value(PointGFp::Compression_Type type) const
Definition: ecdh.h:95
Botan::ECDH_PublicKey::ECDH_PublicKey
ECDH_PublicKey(const AlgorithmIdentifier &alg_id, const std::vector< uint8_t > &key_bits)
Definition: ecdh.h:28
Botan::PointGFp
Definition: point_gfp.h:41
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::EC2OSP
secure_vector< uint8_t > EC2OSP(const PointGFp &point, uint8_t format)
Definition: point_gfp.cpp:470
Botan::ECDH_PublicKey
Definition: ecdh.h:20
Botan::EC_PublicKey
Definition: ecc_key.h:29
type
MechanismType type
Definition: p11_mechanism.cpp:43
Botan::PointGFp::Compression_Type
Compression_Type
Definition: point_gfp.h:44
Botan::EC_PrivateKey
Definition: ecc_key.h:110
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::ECDH_PrivateKey::public_value
std::vector< uint8_t > public_value() const override
Definition: ecdh.h:92
Botan::ECDH_PublicKey::public_value
std::vector< uint8_t > public_value(PointGFp::Compression_Type type) const
Definition: ecdh.h:56
Botan
Definition: alg_id.cpp:13
Botan::ECDH_PrivateKey::ECDH_PrivateKey
ECDH_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition: ecdh.h:87
Botan::ECDH_PublicKey::ECDH_PublicKey
ECDH_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: ecdh.h:37
Botan::EC_Group
Definition: ec_group.h:31
Botan::ECDH_PublicKey::algo_name
std::string algo_name() const override
Definition: ecdh.h:45
Botan::unlock
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:125
Botan::PK_Key_Agreement_Key
Definition: pk_keys.h:271
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::ECDH_PrivateKey
Definition: ecdh.h:66