Botan 3.7.1
Crypto and TLS for C&
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
15namespace Botan {
16
17/**
18* This class represents ECDH Public Keys.
19*/
20class BOTAN_PUBLIC_API(2, 0) ECDH_PublicKey : public virtual EC_PublicKey {
21 public:
22 /**
23 * Create an ECDH public key.
24 * @param alg_id algorithm identifier
25 * @param key_bits DER encoded public key bits
26 */
27 ECDH_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
28 EC_PublicKey(alg_id, key_bits) {}
29
30#if defined(BOTAN_HAS_LEGACY_EC_POINT)
31 /**
32 * Construct a public key from a given public point.
33 * @param group the domain parameters associated with this key
34 * @param public_point the public point defining this key
35 */
36 ECDH_PublicKey(const EC_Group& group, const EC_Point& public_point) : EC_PublicKey(group, public_point) {}
37#endif
38
39 /**
40 * Construct a public key from a given public point.
41 * @param group the domain parameters associated with this key
42 * @param public_key the public point defining this key
43 */
44 ECDH_PublicKey(const EC_Group& group, const EC_AffinePoint& public_key) : EC_PublicKey(group, public_key) {}
45
46 /**
47 * Get this keys algorithm name.
48 * @return this keys algorithm name
49 */
50 std::string algo_name() const override { return "ECDH"; }
51
52 /**
53 * @return public point value
54 */
55 std::vector<uint8_t> public_value() const { return this->public_value(EC_Point_Format::Uncompressed); }
56
57 /**
58 * @return public point value
59 */
60 std::vector<uint8_t> public_value(EC_Point_Format format) const;
61
62 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::KeyAgreement); }
63
64 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
65
66 protected:
67 ECDH_PublicKey() = default;
68};
69
70/**
71* This class represents ECDH Private Keys.
72*/
73
76
78 public EC_PrivateKey,
80 public:
81 /**
82 * Load a private key.
83 * @param alg_id the X.509 algorithm identifier
84 * @param key_bits ECPrivateKey bits
85 */
86 ECDH_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
87 EC_PrivateKey(alg_id, key_bits) {}
88
89 /**
90 * Create a private key from a given secret @p x
91 * @param group curve parameters to bu used for this key
92 * @param x the private key
93 */
94 ECDH_PrivateKey(EC_Group group, EC_Scalar x) : EC_PrivateKey(std::move(group), std::move(x)) {}
95
96 /**
97 * Create a new private key
98 * @param rng a random number generator
99 * @param group parameters to used for this key
100 */
101 ECDH_PrivateKey(RandomNumberGenerator& rng, EC_Group group) : EC_PrivateKey(rng, std::move(group)) {}
102
103 /**
104 * Generate a new private key
105 * @param rng a random number generator
106 * @param group parameters to used for this key
107 * @param x the private key; if zero, a new random key is generated
108 */
109 BOTAN_DEPRECATED("Use one of the other constructors")
110 ECDH_PrivateKey(RandomNumberGenerator& rng, const EC_Group& group, const BigInt& x) :
111 EC_PrivateKey(rng, group, x) {}
112
113 std::unique_ptr<Public_Key> public_key() const override;
114
115 std::vector<uint8_t> public_value() const override {
116 return ECDH_PublicKey::public_value(EC_Point_Format::Uncompressed);
117 }
118
119 std::vector<uint8_t> public_value(EC_Point_Format type) const { return ECDH_PublicKey::public_value(type); }
120
121 std::unique_ptr<PK_Ops::Key_Agreement> create_key_agreement_op(RandomNumberGenerator& rng,
122 std::string_view params,
123 std::string_view provider) const override;
124};
125
127
128} // namespace Botan
129
130#endif
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:108
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:105
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:107
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
#define BOTAN_DEPRECATED(msg)
Definition api.h:59
ECDH_PrivateKey(EC_Group group, EC_Scalar x)
Definition ecdh.h:94
ECDH_PrivateKey(RandomNumberGenerator &rng, EC_Group group)
Definition ecdh.h:101
std::vector< uint8_t > public_value() const override
Definition ecdh.h:115
std::vector< uint8_t > public_value(EC_Point_Format type) const
Definition ecdh.h:119
ECDH_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecdh.h:86
ECDH_PublicKey(const EC_Group &group, const EC_AffinePoint &public_key)
Definition ecdh.h:44
bool supports_operation(PublicKeyOperation op) const override
Definition ecdh.h:62
std::vector< uint8_t > public_value() const
Definition ecdh.h:55
ECDH_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition ecdh.h:27
std::string algo_name() const override
Definition ecdh.h:50
int(* final)(unsigned char *, CTX *)
PublicKeyOperation
Definition pk_keys.h:45