Botan 3.0.0
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 {
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 */
29 std::span<const 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 EC_Point& 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 public_point().encode(EC_Point_Format::Uncompressed); }
52
53 /**
54 * @return public point value
55 */
56 std::vector<uint8_t> public_value(EC_Point_Format format) const
57 { return public_point().encode(format); }
58
59 bool supports_operation(PublicKeyOperation op) const override
60 {
61 return (op == PublicKeyOperation::KeyAgreement);
62 }
63
64 protected:
65 ECDH_PublicKey() = default;
66 };
67
68/**
69* This class represents ECDH Private Keys.
70*/
71
74
76 public EC_PrivateKey,
78 {
79 public:
80
81 /**
82 * Load a private key.
83 * @param alg_id the X.509 algorithm identifier
84 * @param key_bits ECPrivateKey bits
85 */
87 std::span<const uint8_t> key_bits) :
88 EC_PrivateKey(alg_id, key_bits) {}
89
90 /**
91 * Generate a new private key
92 * @param rng a random number generator
93 * @param domain parameters to used for this key
94 * @param x the private key; if zero, a new random key is generated
95 */
97 const EC_Group& domain,
98 const BigInt& x = BigInt::zero()) :
99 EC_PrivateKey(rng, domain, x) {}
100
101 std::unique_ptr<Public_Key> public_key() const override;
102
103 std::vector<uint8_t> public_value() const override
104 { return ECDH_PublicKey::public_value(EC_Point_Format::Uncompressed); }
105
106 std::vector<uint8_t> public_value(EC_Point_Format type) const
107 { return ECDH_PublicKey::public_value(type); }
108
109 std::unique_ptr<PK_Ops::Key_Agreement>
110 create_key_agreement_op(RandomNumberGenerator& rng,
111 std::string_view params,
112 std::string_view provider) const override;
113 };
114
116
117}
118
119#endif
ECDH_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=BigInt::zero())
Definition: ecdh.h:96
std::vector< uint8_t > public_value() const override
Definition: ecdh.h:103
std::vector< uint8_t > public_value(EC_Point_Format type) const
Definition: ecdh.h:106
ECDH_PrivateKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition: ecdh.h:86
bool supports_operation(PublicKeyOperation op) const override
Definition: ecdh.h:59
std::vector< uint8_t > public_value() const
Definition: ecdh.h:50
ECDH_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Definition: ecdh.h:28
std::string algo_name() const override
Definition: ecdh.h:45
std::vector< uint8_t > public_value(EC_Point_Format format) const
Definition: ecdh.h:56
ECDH_PublicKey(const EC_Group &dom_par, const EC_Point &public_point)
Definition: ecdh.h:37
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition: compiler.h:204
#define BOTAN_DIAGNOSTIC_PUSH
Definition: compiler.h:201
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition: compiler.h:203
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:12
PublicKeyOperation
Definition: pk_keys.h:43
EC_Point_Format
Definition: ec_point.h:19