/src/botan/build/include/public/botan/dh.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Diffie-Hellman |
3 | | * (C) 1999-2007,2023 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #ifndef BOTAN_DIFFIE_HELLMAN_H_ |
9 | | #define BOTAN_DIFFIE_HELLMAN_H_ |
10 | | |
11 | | #include <botan/pk_keys.h> |
12 | | #include <memory> |
13 | | |
14 | | namespace Botan { |
15 | | |
16 | | class BigInt; |
17 | | class DL_Group; |
18 | | class DL_PublicKey; |
19 | | class DL_PrivateKey; |
20 | | |
21 | | /** |
22 | | * This class represents Diffie-Hellman public keys. |
23 | | */ |
24 | | class BOTAN_PUBLIC_API(2, 0) DH_PublicKey : public virtual Public_Key { |
25 | | public: |
26 | | /** |
27 | | * Create a public key. |
28 | | * @param alg_id the X.509 algorithm identifier |
29 | | * @param key_bits DER encoded public key bits |
30 | | */ |
31 | | DH_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits); |
32 | | |
33 | | /** |
34 | | * Construct a public key with the specified parameters. |
35 | | * @param group the DL group to use in the key |
36 | | * @param y the public value y |
37 | | */ |
38 | | DH_PublicKey(const DL_Group& group, const BigInt& y); |
39 | | |
40 | | AlgorithmIdentifier algorithm_identifier() const override; |
41 | | |
42 | | std::vector<uint8_t> raw_public_key_bits() const override; |
43 | | |
44 | | std::vector<uint8_t> public_key_bits() const override; |
45 | | |
46 | | bool check_key(RandomNumberGenerator& rng, bool strong) const override; |
47 | | |
48 | | size_t estimated_strength() const override; |
49 | | size_t key_length() const override; |
50 | | |
51 | | std::vector<uint8_t> public_value() const; |
52 | | |
53 | 0 | std::string algo_name() const override { return "DH"; } |
54 | | |
55 | | const BigInt& get_int_field(std::string_view field) const override; |
56 | | |
57 | 0 | bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::KeyAgreement); } |
58 | | |
59 | | std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final; |
60 | | |
61 | | const DL_Group& group() const; |
62 | | |
63 | | private: |
64 | | friend class DH_PrivateKey; |
65 | | |
66 | 0 | DH_PublicKey() = default; |
67 | | |
68 | 0 | DH_PublicKey(std::shared_ptr<const DL_PublicKey> key) : m_public_key(std::move(key)) {} |
69 | | |
70 | | std::shared_ptr<const DL_PublicKey> m_public_key; |
71 | | }; |
72 | | |
73 | | /** |
74 | | * This class represents Diffie-Hellman private keys. |
75 | | */ |
76 | | |
77 | | BOTAN_DIAGNOSTIC_PUSH |
78 | | BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE |
79 | | |
80 | | class BOTAN_PUBLIC_API(2, 0) DH_PrivateKey final : public DH_PublicKey, |
81 | | public PK_Key_Agreement_Key, |
82 | | public virtual Private_Key { |
83 | | public: |
84 | | /** |
85 | | * Load a private key from the ASN.1 encoding |
86 | | * @param alg_id the X.509 algorithm identifier |
87 | | * @param key_bits PKCS #8 structure |
88 | | */ |
89 | | DH_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits); |
90 | | |
91 | | /** |
92 | | * Load a private key from the integer encoding |
93 | | * @param group the underlying DL group |
94 | | * @param private_key the private key |
95 | | */ |
96 | | DH_PrivateKey(const DL_Group& group, const BigInt& private_key); |
97 | | |
98 | | /** |
99 | | * Create a new private key. |
100 | | * @param group the underlying DL group |
101 | | * @param rng the RNG to use |
102 | | */ |
103 | | DH_PrivateKey(RandomNumberGenerator& rng, const DL_Group& group); |
104 | | |
105 | | std::unique_ptr<Public_Key> public_key() const override; |
106 | | |
107 | | std::vector<uint8_t> public_value() const override; |
108 | | |
109 | | secure_vector<uint8_t> private_key_bits() const override; |
110 | | |
111 | | secure_vector<uint8_t> raw_private_key_bits() const override; |
112 | | |
113 | | const BigInt& get_int_field(std::string_view field) const override; |
114 | | |
115 | | std::unique_ptr<PK_Ops::Key_Agreement> create_key_agreement_op(RandomNumberGenerator& rng, |
116 | | std::string_view params, |
117 | | std::string_view provider) const override; |
118 | | |
119 | | private: |
120 | | std::shared_ptr<const DL_PrivateKey> m_private_key; |
121 | | }; |
122 | | |
123 | | BOTAN_DIAGNOSTIC_POP |
124 | | |
125 | | } // namespace Botan |
126 | | |
127 | | #endif |