Botan  2.8.0
Crypto and TLS for C++11
dl_algo.h
Go to the documentation of this file.
1 /*
2 * DL Scheme
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_DL_ALGO_H_
9 #define BOTAN_DL_ALGO_H_
10 
11 #include <botan/dl_group.h>
12 #include <botan/pk_keys.h>
13 
14 namespace Botan {
15 
16 /**
17 * This class represents discrete logarithm (DL) public keys.
18 */
19 class BOTAN_PUBLIC_API(2,0) DL_Scheme_PublicKey : public virtual Public_Key
20  {
21  public:
22  bool check_key(RandomNumberGenerator& rng, bool) const override;
23 
24  AlgorithmIdentifier algorithm_identifier() const override;
25 
26  std::vector<uint8_t> public_key_bits() const override;
27 
28  /**
29  * Get the DL domain parameters of this key.
30  * @return DL domain parameters of this key
31  */
32  const DL_Group& get_domain() const { return m_group; }
33 
34  /**
35  * Get the DL domain parameters of this key.
36  * @return DL domain parameters of this key
37  */
38  const DL_Group& get_group() const { return m_group; }
39 
40  /**
41  * Get the public value y with y = g^x mod p where x is the secret key.
42  */
43  const BigInt& get_y() const { return m_y; }
44 
45  /**
46  * Get the prime p of the underlying DL group.
47  * @return prime p
48  */
49  const BigInt& group_p() const { return m_group.get_p(); }
50 
51  /**
52  * Get the prime q of the underlying DL group.
53  * @return prime q
54  */
55  const BigInt& group_q() const { return m_group.get_q(); }
56 
57  /**
58  * Get the generator g of the underlying DL group.
59  * @return generator g
60  */
61  const BigInt& group_g() const { return m_group.get_g(); }
62 
63  /**
64  * Get the underlying groups encoding format.
65  * @return encoding format
66  */
67  virtual DL_Group::Format group_format() const = 0;
68 
69  size_t key_length() const override;
70  size_t estimated_strength() const override;
71 
72  DL_Scheme_PublicKey& operator=(const DL_Scheme_PublicKey& other) = default;
73 
74  protected:
75  DL_Scheme_PublicKey() = default;
76 
77  /**
78  * Create a public key.
79  * @param alg_id the X.509 algorithm identifier
80  * @param key_bits DER encoded public key bits
81  * @param group_format the underlying groups encoding format
82  */
84  const std::vector<uint8_t>& key_bits,
85  DL_Group::Format group_format);
86 
87  DL_Scheme_PublicKey(const DL_Group& group, const BigInt& y);
88 
89  /**
90  * The DL public key
91  */
93 
94  /**
95  * The DL group
96  */
98  };
99 
100 /**
101 * This class represents discrete logarithm (DL) private keys.
102 */
104  public virtual Private_Key
105  {
106  public:
107  bool check_key(RandomNumberGenerator& rng, bool) const override;
108 
109  /**
110  * Get the secret key x.
111  * @return secret key
112  */
113  const BigInt& get_x() const { return m_x; }
114 
115  secure_vector<uint8_t> private_key_bits() const override;
116 
117  DL_Scheme_PrivateKey& operator=(const DL_Scheme_PrivateKey& other) = default;
118 
119  protected:
120  /**
121  * Create a private key.
122  * @param alg_id the X.509 algorithm identifier
123  * @param key_bits DER encoded private key bits
124  * @param group_format the underlying groups encoding format
125  */
127  const secure_vector<uint8_t>& key_bits,
128  DL_Group::Format group_format);
129 
130  DL_Scheme_PrivateKey() = default;
131 
132  /**
133  * The DL private key
134  */
136  };
137 
138 }
139 
140 #endif
const DL_Group & get_domain() const
Definition: dl_algo.h:32
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
const BigInt & get_y() const
Definition: dl_algo.h:43
const DL_Group & get_group() const
Definition: dl_algo.h:38
Definition: alg_id.cpp:13
const BigInt & group_p() const
Definition: dl_algo.h:49
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
const BigInt & get_x() const
Definition: dl_algo.h:113
const BigInt & group_g() const
Definition: dl_algo.h:61
const BigInt & group_q() const
Definition: dl_algo.h:55