Botan  2.4.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 public value y with y = g^x mod p where x is the secret key.
36  */
37  const BigInt& get_y() const { return m_y; }
38 
39  /**
40  * Get the prime p of the underlying DL group.
41  * @return prime p
42  */
43  const BigInt& group_p() const { return m_group.get_p(); }
44 
45  /**
46  * Get the prime q of the underlying DL group.
47  * @return prime q
48  */
49  const BigInt& group_q() const { return m_group.get_q(); }
50 
51  /**
52  * Get the generator g of the underlying DL group.
53  * @return generator g
54  */
55  const BigInt& group_g() const { return m_group.get_g(); }
56 
57  /**
58  * Get the underlying groups encoding format.
59  * @return encoding format
60  */
61  virtual DL_Group::Format group_format() const = 0;
62 
63  size_t key_length() const override;
64  size_t estimated_strength() const override;
65 
66  /**
67  * Create a public key.
68  * @param alg_id the X.509 algorithm identifier
69  * @param key_bits DER encoded public key bits
70  * @param group_format the underlying groups encoding format
71  */
73  const std::vector<uint8_t>& key_bits,
74  DL_Group::Format group_format);
75 
76  DL_Scheme_PublicKey& operator=(const DL_Scheme_PublicKey& other) = default;
77 
78  protected:
79  DL_Scheme_PublicKey() = default;
80 
81  /**
82  * The DL public key
83  */
85 
86  /**
87  * The DL group
88  */
90  };
91 
92 /**
93 * This class represents discrete logarithm (DL) private keys.
94 */
96  public virtual Private_Key
97  {
98  public:
99  bool check_key(RandomNumberGenerator& rng, bool) const override;
100 
101  /**
102  * Get the secret key x.
103  * @return secret key
104  */
105  const BigInt& get_x() const { return m_x; }
106 
107  secure_vector<uint8_t> private_key_bits() const override;
108 
109  /**
110  * Create a private key.
111  * @param alg_id the X.509 algorithm identifier
112  * @param key_bits DER encoded private key bits
113  * @param group_format the underlying groups encoding format
114  */
116  const secure_vector<uint8_t>& key_bits,
117  DL_Group::Format group_format);
118 
119  DL_Scheme_PrivateKey& operator=(const DL_Scheme_PrivateKey& other) = default;
120 
121  protected:
122  DL_Scheme_PrivateKey() = default;
123 
124  /**
125  * The DL private key
126  */
128  };
129 
130 }
131 
132 #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:37
Definition: alg_id.cpp:13
const BigInt & group_p() const
Definition: dl_algo.h:43
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
const BigInt & get_x() const
Definition: dl_algo.h:105
const BigInt & group_g() const
Definition: dl_algo.h:55
const BigInt & group_q() const
Definition: dl_algo.h:49