/src/Botan-3.4.0/build/include/public/botan/ecdh.h
Line | Count | Source (jump to first uncovered line) |
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_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 | 0 | EC_PublicKey(alg_id, key_bits) {} |
29 | | |
30 | | /** |
31 | | * Construct a public key from a given public point. |
32 | | * @param dom_par the domain parameters associated with this key |
33 | | * @param public_point the public point defining this key |
34 | | */ |
35 | 0 | ECDH_PublicKey(const EC_Group& dom_par, const EC_Point& public_point) : EC_PublicKey(dom_par, public_point) {} |
36 | | |
37 | | /** |
38 | | * Get this keys algorithm name. |
39 | | * @return this keys algorithm name |
40 | | */ |
41 | 0 | std::string algo_name() const override { return "ECDH"; } |
42 | | |
43 | | /** |
44 | | * @return public point value |
45 | | */ |
46 | 0 | std::vector<uint8_t> public_value() const { return public_point().encode(EC_Point_Format::Uncompressed); } |
47 | | |
48 | | /** |
49 | | * @return public point value |
50 | | */ |
51 | 0 | std::vector<uint8_t> public_value(EC_Point_Format format) const { return public_point().encode(format); } |
52 | | |
53 | 0 | bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::KeyAgreement); } |
54 | | |
55 | | std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final; |
56 | | |
57 | | protected: |
58 | 0 | ECDH_PublicKey() = default; |
59 | | }; |
60 | | |
61 | | /** |
62 | | * This class represents ECDH Private Keys. |
63 | | */ |
64 | | |
65 | | BOTAN_DIAGNOSTIC_PUSH |
66 | | BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE |
67 | | |
68 | | class BOTAN_PUBLIC_API(2, 0) ECDH_PrivateKey final : public ECDH_PublicKey, |
69 | | public EC_PrivateKey, |
70 | | public PK_Key_Agreement_Key { |
71 | | public: |
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, std::span<const uint8_t> key_bits) : |
78 | 0 | EC_PrivateKey(alg_id, key_bits) {} |
79 | | |
80 | | /** |
81 | | * Generate a new private key |
82 | | * @param rng a random number generator |
83 | | * @param domain parameters to used for this key |
84 | | * @param x the private key; if zero, a new random key is generated |
85 | | */ |
86 | | ECDH_PrivateKey(RandomNumberGenerator& rng, const EC_Group& domain, const BigInt& x = BigInt::zero()) : |
87 | 0 | EC_PrivateKey(rng, domain, x) {} |
88 | | |
89 | | std::unique_ptr<Public_Key> public_key() const override; |
90 | | |
91 | 0 | std::vector<uint8_t> public_value() const override { |
92 | 0 | return ECDH_PublicKey::public_value(EC_Point_Format::Uncompressed); |
93 | 0 | } |
94 | | |
95 | 0 | std::vector<uint8_t> public_value(EC_Point_Format type) const { return ECDH_PublicKey::public_value(type); } |
96 | | |
97 | | std::unique_ptr<PK_Ops::Key_Agreement> create_key_agreement_op(RandomNumberGenerator& rng, |
98 | | std::string_view params, |
99 | | std::string_view provider) const override; |
100 | | }; |
101 | | |
102 | | BOTAN_DIAGNOSTIC_POP |
103 | | |
104 | | } // namespace Botan |
105 | | |
106 | | #endif |