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