Coverage Report

Created: 2022-06-23 06:44

/src/botan/build/include/botan/dl_algo.h
Line
Count
Source (jump to first uncovered line)
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
0
      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
110
      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
110
      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
0
      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
110
      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
0
      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
429
      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
      */
83
      DL_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
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
      */
92
      BigInt m_y;
93
94
      /**
95
      * The DL group
96
      */
97
      DL_Group m_group;
98
   };
99
100
/**
101
* This class represents discrete logarithm (DL) private keys.
102
*/
103
class BOTAN_PUBLIC_API(2,0) DL_Scheme_PrivateKey : public virtual DL_Scheme_PublicKey,
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
0
      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
      */
126
      DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
127
                           const secure_vector<uint8_t>& key_bits,
128
                           DL_Group_Format group_format);
129
130
0
      DL_Scheme_PrivateKey() = default;
131
132
      /**
133
      * The DL private key
134
      */
135
      BigInt m_x;
136
   };
137
138
}
139
140
#endif