Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

dh.h
Go to the documentation of this file.
1 /*
2 * Diffie-Hellman
3 * (C) 1999-2007 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/dl_algo.h>
12
13 namespace Botan {
14
15 /**
16 * This class represents Diffie-Hellman public keys.
17 */
18 class BOTAN_DLL DH_PublicKey : public virtual DL_Scheme_PublicKey
19 {
20 public:
21 std::string algo_name() const override { return "DH"; }
22
23 std::vector<uint8_t> public_value() const;
24
25 DL_Group::Format group_format() const override { return DL_Group::ANSI_X9_42; }
26
27 /**
28 * Create a public key.
29 * @param alg_id the X.509 algorithm identifier
30 * @param key_bits DER encoded public key bits
31 */
32 DH_PublicKey(const AlgorithmIdentifier& alg_id,
33 const std::vector<uint8_t>& key_bits) :
34 DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_42) {}
35
36 /**
37 * Construct a public key with the specified parameters.
38 * @param grp the DL group to use in the key
39 * @param y the public value y
40 */
41 DH_PublicKey(const DL_Group& grp, const BigInt& y);
42 protected:
43 DH_PublicKey() = default;
44 };
45
46 /**
47 * This class represents Diffie-Hellman private keys.
48 */
49 class BOTAN_DLL DH_PrivateKey : public DH_PublicKey,
50 public PK_Key_Agreement_Key,
51 public virtual DL_Scheme_PrivateKey
52 {
53 public:
54 std::vector<uint8_t> public_value() const override;
55
56 /**
57 * Load a private key.
58 * @param alg_id the X.509 algorithm identifier
59 * @param key_bits PKCS #8 structure
60 */
61 DH_PrivateKey(const AlgorithmIdentifier& alg_id,
62 const secure_vector<uint8_t>& key_bits);
63
64 /**
65 * Create a private key.
66 * @param rng random number generator to use
67 * @param grp the group to be used in the key
68 * @param x the key's secret value (or if zero, generate a new key)
69 */
70 DH_PrivateKey(RandomNumberGenerator& rng, const DL_Group& grp,
71 const BigInt& x = 0);
72
73 std::unique_ptr<PK_Ops::Key_Agreement>
74 create_key_agreement_op(RandomNumberGenerator& rng,
75 const std::string& params,
76 const std::string& provider) const override;
77 };
78
79 }
80
81 #endif
Botan::DL_Scheme_PrivateKey
Definition: dl_algo.h:95
Botan::BigInt
Definition: bigint.h:23
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::DL_Scheme_PublicKey
Definition: dl_algo.h:19
Botan::DL_Group
Definition: dl_group.h:20
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::DL_Group::Format
Format
Definition: dl_group.h:45
Botan::DH_PublicKey::group_format
DL_Group::Format group_format() const override
Definition: dh.h:25
Botan
Definition: alg_id.cpp:13
Botan::DL_Group::ANSI_X9_42
Definition: dl_group.h:46
Botan::DH_PublicKey
Definition: dh.h:18
Botan::PK_Key_Agreement_Key
Definition: pk_keys.h:271
Botan::DH_PublicKey::DH_PublicKey
DH_PublicKey(const AlgorithmIdentifier &alg_id, const std::vector< uint8_t > &key_bits)
Definition: dh.h:32
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::DH_PrivateKey
Definition: dh.h:49
Botan::DH_PublicKey::algo_name
std::string algo_name() const override
Definition: dh.h:21